15 Star 104 Fork 52

monkeyk7 / MyOIDC

 / 详情

TOKEN 自定义信息怎么修改

Backlog
Opened this issue  
2021-04-07 16:32
{
  "alg": "RS256",
  "typ": "JWT",
  "kid": "myoidc-keyid"
}.{
  "sub": "admin",
  "user_name": "admin",
  "scope": [
    "server"
  ],
  "iss": "http://localhost:3000/",
  "exp": 1617805722,
  "iat": 1617762522,
  "authorities": [

这是生成的默认的 claim,我百度有个 enhance方法可以修改,但是不起作用、

/**
	 * 自定义token扩展链
	 *
	 * @return tokenEnhancerChain
	 */
	@Bean
	public TokenEnhancerChain tokenEnhancerChain() throws Exception {
		TokenEnhancerChain tokenEnhancerChain = new TokenEnhancerChain();
		tokenEnhancerChain.setTokenEnhancers(Arrays.asList(new CustomTokenEnhancer(), accessTokenConverter()));
		return tokenEnhancerChain;
	}


	@Override
	public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
		endpoints
				.allowedTokenEndpointRequestMethods(HttpMethod.GET, HttpMethod.POST)
				.tokenStore(tokenStore())
				.accessTokenConverter(accessTokenConverter())
				.tokenEnhancer(tokenEnhancerChain())  //这里执行上面的enhance方法

你的 MyOIDCJwtAccessTokenConverter 中的 这个方法是不是也可以啊

@Override
    public OAuth2AccessToken enhance(OAuth2AccessToken accessToken, OAuth2Authentication authentication) {
        OAuth2AccessToken enhanceToken = super.enhance(accessToken, authentication);

        //if have openid, add id_token
        if (authentication.getOAuth2Request().getScope().contains(OIDCUtils.SCOPE_OPENID)) {
            ImmutableMap<String, String> extHeader = ImmutableMap.of(
                    KEY_ID, publicJsonWebKey.getKeyId());
            String idToken = encodeWithHeader(accessToken, authentication, extHeader);
            enhanceToken.getAdditionalInformation().put(ID_TOKEN, idToken);
            if (LOG.isDebugEnabled()) {
                LOG.debug("{}|Added id_token: {} to accessToken: {}", WebUtils.getIp(), idToken, enhanceToken);
            }
        }

        return enhanceToken;
    }

Comments (1)

yang872546 created任务
yang872546 set related repository to monkeyk7/MyOIDC
Expand operation logs

可以扩展,提供的实现中是参考,可以根据自己需要修改claims里的内容 。

Sign in to comment

Status
Assignees
Milestones
Pull Requests
Successfully merging a pull request will close this issue.
Branches
Planed to start   -   Planed to end
-
Top level
Priority
参与者(2)
7238 mkk 1578914473
Java
1
https://gitee.com/mkk/MyOIDC.git
git@gitee.com:mkk/MyOIDC.git
mkk
MyOIDC
MyOIDC

Search