Today's content is mainly to solve a problem raised by a fan : How to use jwt Add additional information about the user in the resource server and get the data in the resource server .

There are three knowledge points involved :

*
How to use the jwt Add custom data to

*
How to use jwt Add additional data for users in , For example, users id, phone number

*
How to get these custom data in the resource server

Now let's see how to achieve it .

How to use the jwt Add custom data to

The question is relatively simple , Just follow these two steps :

*
Write custom token Enhancer
package com.javadaily.auth.security;
import org.springframework.security.oauth2.common.DefaultOAuth2AccessToken;
import org.springframework.security.oauth2.common.OAuth2AccessToken;
import org.springframework.security.oauth2.provider.OAuth2Authentication;
import org.springframework.security.oauth2.provider.token.store.JwtAccessTokenConverter;
import java.util.HashMap; import java.util.Map; /**  * <p>
 * <code>JwtTokenEnhancer</code>  * </p>  * Description:  *  custom Token enhance
 * @author javadaily  * @date 2020/7/4 15:56  */ public

Technology