How to set expire_in in OAUTH 2.0?

后端 未结 8 2051
醉梦人生
醉梦人生 2020-12-28 15:58

I am using OAuth 2.0 with spring for token generation and I want to set expire_in manually so token can expire as per my criteria. Any one help me?

8条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-28 16:28

    • Create a custom class of AuthorizationCodeAccessTokenProvider and override the parent

      public method obtainAccessToken(OAuth2ProtectedResourceDetails details, AccessTokenRequest request)
      
    • In the overridden method of your custom class, call upon the program logic of its parent class:

      DefaultOAuth2AccessToken token = super.obtainAccessToken(details, request);
      
    • This will return an AccessToken. Now, you just have to manipulate the expired value of that token directly, by providing a timestamp from the past token.setExpiresIn(int timestamp)

提交回复
热议问题