Browse Source

兼容客户端模式

tags/v2.4.1
chenjiandong 1 year ago
parent
commit
b552130540
1 changed files with 13 additions and 10 deletions
  1. +13
    -10
      tuoheng_oidc_server/src/main/java/com/tuoheng/config/IdTokenCustomizerConfig.java

+ 13
- 10
tuoheng_oidc_server/src/main/java/com/tuoheng/config/IdTokenCustomizerConfig.java View File

@@ -15,6 +15,7 @@ import org.springframework.security.oauth2.server.authorization.token.OAuth2Toke
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

/**
@@ -39,16 +40,18 @@ public class IdTokenCustomizerConfig {
}
if ("access_token".equals(context.getTokenType().getValue())) {
UserBaseInfoDto userBaseInfoDto = userMapper.getUserBaseInfo(context.getPrincipal().getName());
context.getClaims().claims(claims ->
claims.put("scope", context.getPrincipal().getAuthorities()
.stream().map(GrantedAuthority::getAuthority)
.collect(Collectors.toSet())))
.claims(claims ->
claims.put("username", context.getPrincipal().getName()))
.claims(claims ->
claims.put("oUserId", userBaseInfoDto.getUserId()))
.claims(claims ->
claims.put("clientRoleList", JSONObject.toJSONString(userBaseInfoDto.getClientRoleDtoList())));
if(Objects.nonNull(userBaseInfoDto)){
context.getClaims().claims(claims ->
claims.put("scope", context.getPrincipal().getAuthorities()
.stream().map(GrantedAuthority::getAuthority)
.collect(Collectors.toSet())))
.claims(claims ->
claims.put("username", context.getPrincipal().getName()))
.claims(claims ->
claims.put("oUserId", userBaseInfoDto.getUserId()))
.claims(claims ->
claims.put("clientRoleList", JSONObject.toJSONString(userBaseInfoDto.getClientRoleDtoList())));
}
}
};
}

Loading…
Cancel
Save