Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
613 views
in Technique[技术] by (71.8m points)

单点登录客户端通过代码注册如何实现

项目开发中,要使用Springboot Security做单点登录,然后找到这篇教程-Spring Boot+OAuth2,一个注解搞定单点登录!,但是实现过程中发现客户端重定向等相关信息是代码写定的,该如何将信保存数据呢,然后授权服务器有个接口可提供管理员注册客户端跳转信息。

项目端口描述
auth-server1110授权服务器+资源服务器
client11111单点登录客户端1
client21112单点登录客户端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

通过配置文件配置客户端信息,客户端信息配置倒无所谓,主要的是客户端信息怎么代码添加?(客户端信息不是指系统使用者的用户名和密码,而是客户端和授权服务器通信的账号信息)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

找到了,参考文章
token存 redis,客户端信息存数据库:
AuthorizationServerConfigurerAdapter的子类的configure(ClientDetailsServiceConfigurer clients)方法,使用数据库的用户资源。
头痛,spring security的OAUTH2第三方授权和单点登录看混了


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

56.7k users

...