简体   繁体   English

Spring Boot Security如何检查/验证访问令牌

[英]Spring Boot Security how to check/verify access token

I am spring newbie 我是春季新手

I've implemented OAuth2 implicit flow using spring security. 我已经使用Spring Security实现了OAuth2隐式流。 The question is how to check token validity? 问题是如何检查令牌的有效性? I've found oauth/check_token endpoint but first I wasn't able to reach it. 我找到了oauth/check_token端点,但是首先我无法到达它。 Then I've made the following change: 然后,我进行了以下更改:

@Override
public void configure(AuthorizationServerSecurityConfigurer oauthServer) throws Exception
{
    oauthServer.checkTokenAccess("permitAll()");
}

After the configuration I can use check_token endpoint but I wonder if it is correct to use permitAll on the endpoint. 配置完成后,我可以使用check_token端点,但是我想知道在端点上使用permitAll是否正确。 I've tried to change it to isAuthenticated but in that case I am not able to reach the endpoint because I don't store client_secret on my frontend app. 我尝试将其更改为isAuthenticated但是在那种情况下,由于我没有在我的前端应用程序中存储client_secret,因此无法到达端点。

Should I continue use permitAll or there is better way? 我应该继续使用permitAll还是有更好的方法?

You should check access while using oAuth. 使用oAuth时,您应该检查访问权限。

Try below code if works, 如果可行,请尝试以下代码,

 @Override
    public void configure(
      AuthorizationServerSecurityConfigurer oauthServer) 
      throws Exception {
        oauthServer
          .tokenKeyAccess("permitAll()")
          .checkTokenAccess("isAuthenticated()");
    }

If doesn't, please share your security related snippets. 如果不是,请分享您与安全相关的摘要。 Happy coding :) 快乐的编码:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用Spring Boot Security从Facebook获取访问令牌 - How to get access token from facebook using spring boot security 仅当资源在 spring 安全性中得到保护时,如何检查访问令牌? - How to check access token only if resource is secured in spring security? 如何验证oAuth2 access_token是否被Spring安全性发布给它的同一客户端使用? - How to verify that oAuth2 access_token is used by same client to whom it was issued in Spring security? 如何使用 Spring Security 5 在 Spring Boot 应用程序(不是 Web 应用程序)中获取 oauth2 访问令牌 - How to get oauth2 access token in a spring boot application (not a web application) using spring security 5 Spring Boot:如何验证 Azure B2C JWT 令牌 - Spring Boot: How to verify Azure B2C JWT token spring boot 安全认证来验证正文内容 - spring boot security authentication to verify body contents FirebaseAuth JAVA(春季启动)验证令牌 - FirebaseAuth JAVA (Spring boot) verify token 在 Spring Security 中获取访问令牌 - Get Access token in Spring Security 获取控制器中Spring启动/安全性的会话令牌 - Get session token for Spring boot/security in controller 使用 JWT 令牌安全性进行 Spring Boot 单元测试 - Spring Boot Unit Tests with JWT Token Security
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM