为什么获取JWT时候,还是原来的oauth令牌?

来源:6-9 使用JWT替换默认令牌

eddie_k2

2018-09-11

{
“access_token”: “ff080671-b6aa-43d7-bee9-b4aa1cxxxxx”,
“token_type”: “bearer”,
“refresh_token”: “74c60a9f-1eb6-4147-bd9d-656xxxxxxxx”,
“expires_in”: 3599,
“scope”: “all”
}

跟视频的不一样, 获取的不一样?

写回答

1回答

无敌威威

2018-09-12

项目在本地运行生成token没问题,部署到Linux服务器上为什么jwt就不生效了呢,生成的和上面一样了

@Configuration
public class TokenStoreConfig {

    @Bean
    public OAuth2WebSecurityExpressionHandler oAuth2WebSecurityExpressionHandler(ApplicationContext applicationContext) {
        OAuth2WebSecurityExpressionHandler expressionHandler = new OAuth2WebSecurityExpressionHandler();
        expressionHandler.setApplicationContext(applicationContext);
        return expressionHandler;
    }

    /**
     *  使用redis存储token的配置,只有在imooc.security.oauth2.tokenStore配置为redis时生效
     */
    @Configuration
    @ConditionalOnProperty(prefix = "weiwei.security.oauth2", name = "storeType", havingValue = "redis")
    public static class RedisConfig {

        @Autowired
        private RedisConnectionFactory redisConnectionFactory;

        /**
         * @return
         */
        @Bean
        public TokenStore redisTokenStore() {
            return new RedisTokenStore(redisConnectionFactory);
        }
    }

    /**
     * 使用jwt时的配置,默认生效
     */
    @Configuration
    @ConditionalOnProperty(prefix = "weiwei.security.oauth2", name = "storeType", havingValue = "jwt", matchIfMissing = true)
    public static class JwtTokenConfig {

        @Autowired
        private SecurityProperties securityProperties;

        @Bean
        public TokenStore jwtTokenStore() {
            return new JwtTokenStore(jwtAccessTokenConverter());
        }

        @Bean
        public JwtAccessTokenConverter jwtAccessTokenConverter() {
            JwtAccessTokenConverter accessTokenConverter = new JwtAccessTokenConverter();
            accessTokenConverter.setSigningKey(securityProperties.getOauth2().getJwtSigningKey());
            return accessTokenConverter;
        }

        @Bean
        @ConditionalOnBean(TokenEnhancer.class)
        public TokenEnhancer jwtTokenEnhancer(){
            return new WeiTokenJwtEnhancer();
        }
    }
}


0
0

Spring Security技术栈开发企业级认证与授权

Spring Security技术栈,REST风格开发常见接口,独立开发认证授权模块保证REST服务安全

2662 学习 · 1561 问题

查看课程