在请求正文中发布用户凭据时未经授权的错误

时间:2018-01-16 01:07:25

标签: java spring-boot spring-security spring-security-oauth2

当我在

的链接中发送带有用户凭据的帖子请求时,我可以登录我的春季启动应用程序

http://localhost:8088/oauth/token?grant_type=password&username=user&password=password

我收到了一个令牌。但是,我收到错误"未经授权的"当我尝试将凭证在x-www-form-urlencoded中发布到http://localhost:8088/oauth/token

这是我的授权服务器配置:

@Configuration
@EnableAuthorizationServer
public class AuthorizationServerConfig extends 
AuthorizationServerConfigurerAdapter {

    @Autowired
    private AuthenticationManager authenticationManager;

    @Override
    public void configure(AuthorizationServerEndpointsConfigurer endpoints)     throws Exception {
        endpoints.authenticationManager(authenticationManager);
        endpoints.tokenStore(getTokenStore());
    }

    @Bean
    public TokenStore getTokenStore(){
        return new InMemoryTokenStore();
    }

    @Override
    public void configure(ClientDetailsServiceConfigurer clients) throws     Exception {
        clients.inMemory().
                withClient("my-trusted-client")
                .authorizedGrantTypes("client_credentials", "password")
                .authorities("ROLE_CLIENT","ROLE_TRUSTED_CLIENT").scopes("read","write","trust")
                .resourceIds("oauth2-resource").accessTokenValiditySeconds(5000).secret("secret");
    }


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

}

我在这里做错了什么?

0 个答案:

没有答案