【问题标题】:Spring security OAuth - check validity of access token?Spring security OAuth - 检查访问令牌的有效性?
【发布时间】:2015-10-14 11:54:39
【问题描述】:

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

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

curl -X POST http://localhost:9999/uaa/oauth/check_token -d "token=e3f44c4f-f8f2-45c4-9f9e-c7dd1f583a1f"

我收到以下错误:

{"error":"unauthorized","error_description":"Full authentication is required to access this resource"}

我尝试传递客户端 ID 和密码。

curl -X POST acme:acmesecret@localhost:9999/uaa/oauth/check_token -d "token=e3f44c4f-f8f2-45c4-9f9e-c7dd1f583a1f"

我得到 403 状态。

{"timestamp":1437683976536,"status":403,"error":"Forbidden","message":"Access is denied","path":"/uaa/oauth/check_token”}

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

【问题讨论】:

  • 您能否具体说明../uaa/oauth/check_token 的定义是什么?我问是因为没有这样的标准端点..
  • 验证访问令牌的是/oauth/check_token/uaa/ 只是 contextPath。
  • 它到底是做什么的?如果你已经有一个令牌,为什么你必须验证它?如果 check_token 端点已经使用 oauth 进行保护,那么您必须在请求中提供 Authentication 标头而不是参数...此标头应该是:Authentication: Bearer YOUR_TOKEN
  • check_token 不受 oauth 保护。请查看上面帖子中的链接以获取有关其使用的更多信息

标签: spring spring-security spring-security-oauth2


【解决方案1】:

尝试通过/check_token授权权限玩:

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

【讨论】:

  • 而不是使用 oauthServer.checkTokenAccess("permitAll()");我会建议使用 oauthServer.checkTokenAccess("isAuthenticated()");这比打开它更安全。任何想要检查令牌的客户都必须提供他们的客户凭据
  • @SeunMatt 单页应用程序和隐式或授权代码流是什么?我的意思是,SPA 客户端无法验证自己,因为将客户端凭据存储在 SPA 应用程序中是不安全的
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-04-06
  • 2019-11-12
  • 2015-03-30
  • 2013-07-28
  • 2011-03-12
  • 2020-08-19
  • 1970-01-01
相关资源
最近更新 更多