1414import org .springframework .security .oauth2 .server .authorization .settings .TokenSettings ;
1515import org .springframework .stereotype .Component ;
1616
17+ import java .time .Duration ;
1718import java .time .Instant ;
1819import java .util .Arrays ;
1920import java .util .Date ;
21+ import java .util .Map ;
2022import java .util .Set ;
2123import java .util .stream .Collectors ;
2224
25+ import static org .springframework .security .oauth2 .server .authorization .settings .ConfigurationSettingNames .Token .*;
26+
2327@ Component
2428public class RegisteredClientConvert {
2529
@@ -44,6 +48,7 @@ public RegisteredClient convertToRegisteredClient(RegisteredClientPo registeredC
4448 Set <ClientAuthenticationMethod > methods = Arrays .stream (StringUtils .split (registeredClientPo .getClientAuthenticationMethods (), "," ))
4549 .map (ClientAuthenticationMethod ::new )
4650 .collect (Collectors .toSet ());
51+ Map <String , Object > tokenSettings = registeredClientPo .getTokenSettings ();
4752 // 构建 RegisteredClient对象
4853 RegisteredClient .Builder registeredClientBuilder = RegisteredClient .withId (registeredClientPo .getId ())
4954 .clientId (registeredClientPo .getClientId ())
@@ -54,16 +59,18 @@ public RegisteredClient convertToRegisteredClient(RegisteredClientPo registeredC
5459 .clientAuthenticationMethods (methodSet -> methodSet .addAll (methods ))
5560 .scopes (scopeSet -> scopeSet .addAll (scopes ))
5661 .authorizationGrantTypes (grantType -> grantType .addAll (grantTypes ))
62+ // Client相关设置
5763 .clientSettings (ClientSettings .withSettings (registeredClientPo .getClientSettings ()).build ())
64+ // Token相关设置
5865 .tokenSettings (TokenSettings .builder ()
5966 // token有效期5小时
60- // .accessTokenTimeToLive(registeredClientPo.getTokenSettings().getAccessTokenTimeToLive( ))
67+ .accessTokenTimeToLive (Duration . ofSeconds ((( Double ) tokenSettings . get ( ACCESS_TOKEN_TIME_TO_LIVE )). longValue () ))
6168 // 使用默认JWT相关格式
6269 .accessTokenFormat (OAuth2TokenFormat .SELF_CONTAINED )
6370 // 开启刷新token
64- .reuseRefreshTokens (true )
71+ .reuseRefreshTokens (( Boolean ) tokenSettings . get ( REUSE_REFRESH_TOKENS ) )
6572 // refreshToken有效期120分钟
66- // .refreshTokenTimeToLive(registeredClientPo.getTokenSettings().getRefreshTokenTimeToLive( ))
73+ .refreshTokenTimeToLive (Duration . ofSeconds ((( Double ) tokenSettings . get ( REFRESH_TOKEN_TIME_TO_LIVE )). longValue () ))
6774 // idToken签名算法
6875 .idTokenSignatureAlgorithm (SignatureAlgorithm .RS256 ).build ()
6976 );
0 commit comments