JWT:为什么清除本地存储后为什么要获得新令牌?

时间:2018-12-03 21:08:23

标签: spring-security oauth oauth-2.0 jwt angular7

我有一个带有Spring API的Angular 7应用。我使用Spring Security,JWT令牌和https://github.com/manfredsteyer/angular-oauth2-oidc处理登录。

我可以登录,但是当我再次注销并再次登录时,无需连接就可以立即获得一个新令牌。 我是Spring Security和JWT令牌的新手,但据我所知,我无法从背面正确注销,经典方法是从正面删除令牌。库就是这样做的,并且确保我尝试手动清空localStorage(存储令牌的位置),但是即使清除了localStorage,当我尝试登录时,我也会立即获得一个新令牌。

关于发生什么情况以及如何注销的任何想法?

授权服务器配置:

@Configuration
@EnableAuthorizationServer
public class OAuth2AuthorizationServerConfigJwt extends AuthorizationServerConfigurerAdapter {

    @Override
    public void configure(final ClientDetailsServiceConfigurer clients) throws Exception {
        clients.inMemory().withClient("sampleClientId")
        .authorizedGrantTypes("implicit")
        .scopes("read", "write", "foo", "bar")
        .autoApprove(true)/*.accessTokenValiditySeconds(3600)*/
        .redirectUris("http://localhost:4200");
    }

    @Override
    public void configure(final AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
        final TokenEnhancerChain tokenEnhancerChain = new TokenEnhancerChain();
        tokenEnhancerChain.setTokenEnhancers(Arrays.asList(tokenEnhancer(), accessTokenConverter()));
        endpoints.tokenStore(tokenStore()).tokenEnhancer(tokenEnhancerChain);
    }

    @Bean
    public TokenStore tokenStore() {
        return new JwtTokenStore(accessTokenConverter());
    }


    @Bean
    public JwtAccessTokenConverter accessTokenConverter() {
        final JwtAccessTokenConverter converter = new JwtAccessTokenConverter();
        converter.setSigningKey("123");
        return converter;
    }

    @Bean
    public TokenEnhancer tokenEnhancer() {
        return new CustomTokenEnhancer();
    }
}

编辑:

这似乎是由于缺少

.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS)

但是,既然我已经添加了它,我就停留在登录表单上,似乎仍然缺少一些东西。这是我的配置:

@Override
    protected void configure(final HttpSecurity http) throws Exception {
        http.csrf().disable()
        .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS)
        .and()
        .authorizeRequests()
        .antMatchers("/login").permitAll()
        .antMatchers("/user").permitAll()
        .antMatchers("/registrationConfirm").permitAll()
        .antMatchers("/user/confirm/**").permitAll()
        .antMatchers("/user/registration/**").permitAll()
        .antMatchers("/oauth/token/revokeById/**").permitAll()
        .antMatchers("/tokens/**").permitAll()
        .anyRequest().authenticated()
        .and().formLogin().permitAll();
    }

0 个答案:

没有答案