Spring OAUTH2 - Access token expiry time

前端 未结 2 1013
后悔当初
后悔当初 2021-01-13 09:53

Is it possible to update/reset the expiry time of an access token programatically? If yes, which class/filter would be the best place to do it so that expiry time can be upd

2条回答
  •  旧时难觅i
    2021-01-13 10:17

    To update the expiry time of an access token globally you should have to create instance of the DefaultTokenServices & inject into the AuthorizationServerEndpointsConfigurer like this :

    public AuthorizationServerTokenServices customTokenServices(){
      TokenServices tokenServices = new DefaultTokenServices();
      tokenServices.setReuseAccessToken(reuseAccessToken);
      tokenServices.setTokenStore(tokenStore());
      tokenServices.setSupportRefreshToken(true);
      tokenServices.setAccessTokenValiditySeconds();
      tokenServices.setClientDetailsService(clientDetailsService);
      return tokenServices;
    }
    

    & put this tokenServices in AuthorizationServerEndpointsConfigurer like this.

    @Override
    public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
      endpoints.tokenServices(customTokenServices()).
    }
    

提交回复
热议问题