package org.lingniu.sdk.utils;

import org.lingniu.sdk.model.user.UserInfo;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.oauth2.client.authentication.OAuth2AuthenticationToken;

public class UserUtil {

    public static UserInfo getUserInfo(){
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        if(authentication instanceof OAuth2AuthenticationToken oAuth2AuthenticationToken){
            return (UserInfo) oAuth2AuthenticationToken.getPrincipal();
        }
        return null;
    }
}
