项目开发中,要使用Springboot Security做单点登录,然后找到这篇教程-Spring Boot+OAuth2,一个注解搞定单点登录!,但是实现过程中发现客户端重定向等相关信息是代码写定的,该如何将信保存数据呢,然后授权服务器有个接口可提供管理员注册客户端跳转信息。
项目 | 端口 | 描述 |
---|---|---|
auth-server | 1110 | 授权服务器+资源服务器 |
client1 | 1111 | 单点登录客户端1 |
client2 | 1112 | 单点登录客户端2 |
授权服务器授权代码如下:
@Override
public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
clients.inMemory()
.withClient("客户端编号")
.secret(passwordEncoder.encode("客户端密码"))
.autoApprove(true)
.redirectUris("http://localhost:1111/login", "http://localhost:1112/login")
.scopes("user")
.accessTokenValiditySeconds(7200)
.authorizedGrantTypes("authorization_code");
}
客户端注册代码:
security.oauth2.client.client-secret=密码
security.oauth2.client.client-id=客户端编号
security.oauth2.client.user-authorization-uri=http://localhost:1110/oauth/authorize
security.oauth2.client.access-token-uri=http://localhost:1110/oauth/token
security.oauth2.resource.user-info-uri=http://localhost:1110/user
server.port=1111
server.servlet.session.cookie.name=s1
通过配置文件配置客户端信息,客户端信息配置倒无所谓,主要的是客户端信息怎么代码添加?(客户端信息不是指系统使用者的用户名和密码,而是客户端和授权服务器通信的账号信息)
找到了,参考文章
token存 redis,客户端信息存数据库:
AuthorizationServerConfigurerAdapter的子类的configure(ClientDetailsServiceConfigurer clients)方法,使用数据库的用户资源。
头痛,spring security的OAUTH2第三方授权和单点登录看混了