Spring 弹簧OAuth+;JWT--/oauth/token

Spring 弹簧OAuth+;JWT--/oauth/token,spring,spring-security,jwt,spring-security-oauth2,Spring,Spring Security,Jwt,Spring Security Oauth2,我正在尝试将我的spring应用程序配置为使用JWT。我已经公开了一个由JwtTokenStore支持的ConsumerTokenServicesbean,但是点击/oauth/token并没有给我一个JWT $curl localhost:8643/contextpath/oauth/token?授予\类型=客户端\凭据-用户:密码` {“访问令牌”:“a78a6225-78d5-4cb8-9393-6c0b567a6f24”,“令牌类型”:“承载”、“到期时间”:5684,“范围”:“读写”

我正在尝试将我的spring应用程序配置为使用JWT。我已经公开了一个由
JwtTokenStore
支持的
ConsumerTokenServices
bean,但是点击
/oauth/token
并没有给我一个JWT

$curl localhost:8643/contextpath/oauth/token?授予\类型=客户端\凭据-用户:密码`
{“访问令牌”:“a78a6225-78d5-4cb8-9393-6c0b567a6f24”,“令牌类型”:“承载”、“到期时间”:5684,“范围”:“读写”}%

我知道正在使用
TokenStore
,因为点击
check\u-token
会产生一个错误,而以前没有

$curlhttps://localhost:8643/context/oauth/check_token?token=a78a6225-78d5-4cb8-9393-6c0b567a6f24
{“error”:“无效的\u令牌”,“error\u描述”:“无法将访问令牌转换为JSON”}%


如何使我的
TokenEndpoint
吐回一个JWT?

也许您应该使用spring提供的JwtAccessTokenConverter,然后正确配置。 以下是一个例子:

public class YourTokenEnhancer extends JwtAccessTokenConverter {

//you can autowire sth for you logic

@Override
public OAuth2AccessToken enhance(OAuth2AccessToken accessToken,
                                 OAuth2Authentication authentication) {
    DefaultOAuth2AccessToken customAccessToken = new DefaultOAuth2AccessToken(accessToken);

    OAuth2AccessToken enhancedToken = super.enhance(customAccessToken, authentication);
    return enhancedToken;
}
配置为:

 @Configuration
 @EnableAuthorizationServer
 public class OAuth2Config extends AuthorizationServerConfigurerAdapter {
 //other config...
 @Bean
 public JwtAccessTokenConverter accessTokenConverter() {
    JwtAccessTokenConverter converter = new YourTokenEnhancer();
    converter.setSigningKey("secret");
    return converter;
 }

 @Override
 public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception {

    endpoints.authenticationManager(authenticationManager)
            .tokenStore(redisTokenStore())
            .tokenServices(authorizationServerTokenServices())
            .accessTokenConverter(accessTokenConverter())//configure it here
            ;
 }
}

你试过用Spring Boot 1.3制作一个示例应用程序吗?它提供了对OAuth2的自动支持,请参阅。我会尝试构建一个示例应用程序,然后查看和。另一个好的博客系列是看你能解决这个问题吗?我最终没有使用Spring。