优化OIDC协议
This commit is contained in:
+2
-1
@@ -1,6 +1,7 @@
|
||||
package com.central.oauth2.common.config;
|
||||
|
||||
import com.central.oauth2.common.properties.SecurityProperties;
|
||||
import com.central.oauth2.common.properties.TokenStoreProperties;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
|
||||
/**
|
||||
@@ -10,6 +11,6 @@ import org.springframework.boot.context.properties.EnableConfigurationProperties
|
||||
* Blog: https://zlt2000.gitee.io
|
||||
* Github: https://github.com/zlt2000
|
||||
*/
|
||||
@EnableConfigurationProperties(SecurityProperties.class)
|
||||
@EnableConfigurationProperties({SecurityProperties.class, TokenStoreProperties.class})
|
||||
public class SecurityPropertiesConfig {
|
||||
}
|
||||
|
||||
+15
@@ -71,4 +71,19 @@ public class IdTokenClaimNames {
|
||||
* {@code c_hash} - the Authorization Code hash value
|
||||
*/
|
||||
public final static String C_HASH = "c_hash";
|
||||
|
||||
/**
|
||||
* {@code name} - 用户姓名
|
||||
*/
|
||||
public final static String NAME = "name";
|
||||
|
||||
/**
|
||||
* {@code login_name} - 登录名
|
||||
*/
|
||||
public final static String L_NAME = "login_name";
|
||||
|
||||
/**
|
||||
* {@code picture} - 头像照片
|
||||
*/
|
||||
public final static String PIC = "picture";
|
||||
}
|
||||
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
package com.central.oauth2.common.properties;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.cloud.context.config.annotation.RefreshScope;
|
||||
|
||||
/**
|
||||
* Token配置
|
||||
*
|
||||
* @author zlt
|
||||
* @version 1.0
|
||||
* @date 2021/5/19
|
||||
* <p>
|
||||
* Blog: https://zlt2000.gitee.io
|
||||
* Github: https://github.com/zlt2000
|
||||
*/
|
||||
@Setter
|
||||
@Getter
|
||||
@ConfigurationProperties(prefix = "zlt.oauth2.token.store")
|
||||
@RefreshScope
|
||||
public class TokenStoreProperties {
|
||||
/**
|
||||
* token存储类型(redis/db/authJwt/resJwt)
|
||||
*/
|
||||
private String type = "redis";
|
||||
}
|
||||
-22
@@ -56,26 +56,4 @@ public class AuthJwtTokenStore {
|
||||
tokenConverter.setUserTokenConverter(new CustomUserAuthenticationConverter());
|
||||
return converter;
|
||||
}
|
||||
|
||||
/**
|
||||
* jwt 生成token 定制化处理
|
||||
* 添加一些额外的用户信息到token里面
|
||||
*
|
||||
* @return TokenEnhancer
|
||||
*/
|
||||
@Bean
|
||||
@Order(1)
|
||||
public TokenEnhancer tokenEnhancer() {
|
||||
return (accessToken, authentication) -> {
|
||||
final Map<String, Object> additionalInfo = new HashMap<>(1);
|
||||
Object principal = authentication.getPrincipal();
|
||||
//增加id参数
|
||||
if (principal instanceof SysUser) {
|
||||
SysUser user = (SysUser)principal;
|
||||
additionalInfo.put("id", user.getId());
|
||||
}
|
||||
((DefaultOAuth2AccessToken) accessToken).setAdditionalInformation(additionalInfo);
|
||||
return accessToken;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user