package com.kidgrow.jwt.server.utils;
|
|
import com.kidgrow.common.exception.BizException;
|
import com.kidgrow.jwt.server.properties.AuthServerProperties;
|
import com.kidgrow.jwt.utils.JwtHelper;
|
import com.kidgrow.jwt.utils.JwtUserInfo;
|
import com.kidgrow.jwt.utils.Token;
|
import lombok.AllArgsConstructor;
|
|
/**
|
* 石家庄喜高科技有限责任公司 版权所有 © Copyright 2020<br>
|
*
|
* @Description: jwt token工具<br>
|
* @Project: <br>
|
* @CreateDate: Created in 2020/2/11 13:55 <br>
|
* @Author: <a href="4345453@kidgrow.com">liuke</a>
|
*/
|
@AllArgsConstructor
|
public class JwtTokenServerUtils {
|
/**
|
* 认证服务端使用,如 authority-server
|
* 生成和 解析token
|
*/
|
private AuthServerProperties authServerProperties;
|
|
/**
|
* 生成token
|
*
|
* @param jwtInfo
|
* @param expire
|
* @return
|
* @throws BizException
|
*/
|
public Token generateUserToken(JwtUserInfo jwtInfo, Integer expire) throws BizException {
|
AuthServerProperties.TokenInfo userTokenInfo = authServerProperties.getUser();
|
if (expire == null || expire <= 0) {
|
expire = userTokenInfo.getExpire();
|
}
|
return JwtHelper.generateUserToken(jwtInfo, userTokenInfo.getPriKey(), expire);
|
}
|
|
/**
|
* 解析token
|
*
|
* @param token
|
* @return
|
* @throws BizException
|
*/
|
public JwtUserInfo getUserInfo(String token) throws BizException {
|
AuthServerProperties.TokenInfo userTokenInfo = authServerProperties.getUser();
|
return JwtHelper.getJwtFromToken(token, userTokenInfo.getPubKey());
|
}
|
}
|