小编jyo*_*ore的帖子

Spring Security OAuth2资源服务器始终返回无效令牌

我正在尝试使用Spring库运行基本的内存OAuth2服务器.我一直在关注sparklr的例子.

我目前已配置服务器,几乎一切正常,但我无法从资源服务器访问我的受限资源.

我的测试工作流程

  1. 访问oauth授权的URI以启动OAuth2流:http:// localhost:8080/server/oauth/authorize?response_type = code&client_id = client

  2. 重定向到登录页面:http:// localhost:8080/server/login

  3. 处理批准并重定向到我配置的重定向页面w/a code参数:http:// localhost:8080/client?code = HMJO4K

  4. 使用基本身份验证使用客户端ID和密码以及授权类型和代码构造GET请求:http:// localhost:8080/server/oauth/token?grant_type = authorization_code&code = HMJO4K

  5. 接收一个access_token和刷新令牌对象作为回报

    {access_token:"f853bcc5-7801-42d3-9cb8-303fc67b0453"token_type:"bearer"refresh_token:"57100377-dea9-4df0-adab-62e33f2a1b49"expires_in:299范围:"read write"}

  6. 尝试使用access_token访问受限资源:http:// localhost:8080/server/me?access_token = f853bcc5-7801-42d3-9cb8-303fc67b0453

  7. 收到无效的令牌回复

    {error:"invalid_token"error_description:"无效的访问令牌:f853bcc5-7801-42d3-9cb8-303fc67b0453"}

  8. 再次POST到令牌uri以刷新令牌:http:// localhost:8080/server/oauth/token?grant_type = refresh_token&refresh_token = 57100377-dea9-4df0-adab-62e33f2a1b49

  9. 收到一个新令牌

    {access_token:"ed104994-899c-4cd9-8860-43d5689a9420"token_type:"bearer"refresh_token:"57100377-dea9-4df0-adab-62e33f2a1b49"expires_in:300范围:"read write"}

我真的不确定我做错了什么,但似乎除了访问受限制的uri之外的一切都正常.这是我的配置:

@Configuration
public class Oauth2ServerConfiguration {

    private static final String SERVER_RESOURCE_ID = "oauth2-server";

    @Configuration
    @EnableResourceServer
    protected static class ResourceServerConfiguration extends ResourceServerConfigurerAdapter {

        @Override
        public void configure(ResourceServerSecurityConfigurer resources) {
            resources.resourceId(SERVER_RESOURCE_ID);
        }

        @Override
        public …
Run Code Online (Sandbox Code Playgroud)

spring oauth spring-security

20
推荐指数
2
解决办法
3万
查看次数

标签 统计

oauth ×1

spring ×1

spring-security ×1