以下全文 Spring Authorization Server 简称为: SAS
本文以PIG 微服务开发平台为演示,适用于 Spring Security OAuth 2.3 <-> 2.5 的认证中心迁移
目前最新的 SAS 0.3 基于 Java 11 构建,低版本 Java 无法使用
经过和 Spring Security 官方团队的沟通 0.3.1 将继续兼容 Java 1.8
我们联合 springboot 中文社区编译了适配 java 1.8 的版本坐标如下
<dependency>
<groupId>io.springboot.security</groupId>
<artifactId>spring-security-oauth2-authorization-server</artifactId>
<version>0.3.0</version>
</dependency>
ku4R4n7YD1f584KXj4k_3GP9o-HbdY-PDIIh-twPVJTmvHa5mLIoifaNhbBvFNBbse6_wAMcRoOWuVs9qeBWpxQ5zIFrF1A4g1Q7LhVAfH1vo9Uc7WL3SP3u82j0XU5x
统一前缀::令牌类型::客户端ID::用户名::uuid
@Bean
public OAuth2TokenGenerator oAuth2TokenGenerator() {
CustomeOAuth2AccessTokenGenerator accessTokenGenerator = new CustomeOAuth2AccessTokenGenerator();
// 注入Token 增加关联用户信息
accessTokenGenerator.setAccessTokenCustomizer(new CustomeOAuth2TokenCustomizer());
return new DelegatingOAuth2TokenGenerator(accessTokenGenerator, new OAuth2RefreshTokenGenerator());
}
{
"access_token": "xx",
"refresh_token": "xx",
"scope": "server",
"token_type": "Bearer",
"expires_in": 43199
}
{
"sub": "admin",
"clientId": "test",
"access_token": "xx",
"refresh_token": "xx",
"license": "https://pig4cloud.com",
"user_info": {
"username": "admin",
"accountNonExpired": true,
"accountNonLocked": true,
"credentialsNonExpired": true,
"enabled": true,
"id": 1,
"deptId": 1,
"phone": "17034642999",
"name": "admin",
"attributes": {}
}
}
- 优势: 1. 用户状态实时更新 2. 减少网络调用提升性能
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。