首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Spring boot OAuth 2安全性从刷新令牌获取访问令牌(如果已过期)

Spring boot OAuth 2安全性从刷新令牌获取访问令牌(如果已过期)
EN

Stack Overflow用户
提问于 2018-11-20 14:17:05
回答 1查看 622关注 0票数 0

我已经实现了Spring boot Oauth 2安全性,它工作得很好,但是当我试图从刷新令牌中获取访问令牌(如果过期)时,它会给我一个错误

代码语言:javascript
运行
复制
{
    "error": "unauthorized",
    "error_description": "admin"
}

控制台日志

代码语言:javascript
运行
复制
Handling error: UsernameNotFoundException, admin

以下是我的代码

1.WebSecurityConfigure

代码语言:javascript
运行
复制
@Configuration
@EnableWebSecurity
public class EmployeeSecurityConfiguration extends WebSecurityConfigurerAdapter {

    @Override
    public void configure(WebSecurity web) throws Exception {
        web.ignoring().antMatchers("/resources/**");
    }
    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.authorizeRequests().antMatchers("/").permitAll().antMatchers("/user/getEmployeesList")
            .hasAnyRole("USER").anyRequest().authenticated().and().formLogin()
            .permitAll().and().logout().permitAll();
        http.csrf().disable();
    }

    @Override
    public void configure(AuthenticationManagerBuilder authenticationMgr) throws Exception {
        authenticationMgr.inMemoryAuthentication().withUser("admin").password("admin")
            .authorities("ROLE_USER");
    ;
    }
}

2.AuthorizationServerConfigure

代码语言:javascript
运行
复制
@Configuration
@EnableAuthorizationServer
public class AuthorizationServerConfig extends AuthorizationServerConfigurerAdapter {

    @Autowired
    private AuthenticationManager authenticationManager;


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

    @Override
    public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
        clients.inMemory().withClient("MagicUser").authorizedGrantTypes("authorization_code", "refresh_token","password")
                .authorities("CLIENT").scopes("openid", "read", "write", "trust").resourceIds("oauth2-resource")
                .redirectUris("http://10.9.6.31:8090/showEmployees").accessTokenValiditySeconds(5000).secret("secret")
                .refreshTokenValiditySeconds(50000);

    }
    @Override
    public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
        endpoints.authenticationManager(authenticationManager)
                .allowedTokenEndpointRequestMethods(HttpMethod.GET, HttpMethod.POST);
        ;
    }
}

请帮我弄清楚这个问题

访问令牌请求(如果已过期)

代码语言:javascript
运行
复制
    http://10.9.6.31:8091/oauth/token
    Body parameter
   grant_type=refresh_token
  refresh_token=78d2ab82-46a2-4b70-a9e8-e3f9e5ddfec6
EN

回答 1

Stack Overflow用户

发布于 2018-11-20 16:18:35

您可能需要在请求中发送一个authorization标头来验证客户端。检查OAuth 2.0规范中的OAuth client authenticationRefreshing an access token规范。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53387279

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档