Spring安全OAuth - 检查访问令牌的有效性?

bra*_*orm 8 spring spring-security spring-security-oauth2

我正在关注Spring Security OAuth中的示例代码.

当我尝试检查令牌时获得访问令牌后

curl -X POST http://localhost:9999/uaa/oauth/check_token -d "token=e3f44c4f-f8f2-45c4-9f9e-c7dd1f583a1f"
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

{"error":"unauthorized","error_description":"Full authentication is required to access this resource"}
Run Code Online (Sandbox Code Playgroud)

我尝试传递客户端ID和秘密.

curl -X POST acme:acmesecret@localhost:9999/uaa/oauth/check_token -d "token=e3f44c4f-f8f2-45c4-9f9e-c7dd1f583a1f"
Run Code Online (Sandbox Code Playgroud)

我获得403状态.

{"timestamp":1437683976536,"status":403,"error":"Forbidden","message":"Access is denied","path":"/uaa/oauth/check_token”}
Run Code Online (Sandbox Code Playgroud)

我无法弄清楚出了什么问题.这里的任何帮助非常感谢.

nKo*_*ito 14

尝试/check_token通过以下方式使用授权权限:

public class OAuthSecurityConfig extends AuthorizationServerConfigurerAdapter {
   @Override 
   public void configure(AuthorizationServerSecurityConfigurer oauthServer) throws Exception { 
       oauthServer.checkTokenAccess("permitAll()"); 
   }
}
Run Code Online (Sandbox Code Playgroud)

  • 而不是使用 oauthServer.checkTokenAccess("permitAll()"); 我会建议使用 oauthServer.checkTokenAccess("isAuthenticated()"); 这比打开它更安全。任何想要检查令牌的客户端都必须提供他们的客户端凭据 (6认同)