【发布时间】:2018-01-05 13:54:07
【问题描述】:
我创建了一个配置为我的授权服务器 oauth2 的 Spring Boot 应用程序,还有其他配置为客户端 oauth2 的 Spring Boot 应用程序。
在我的服务器中,我实现了 CustomUserDetailsService,我希望在 loadUserByUsername 方法中检索正在验证的项目的 client_id。
我不知道这是否可能,但我想恢复它以验证 client_id,因为我有几个使用相同授权方的应用程序,并且通过 client_id 我将检查用户是否有权访问该应用程序。
有人知道怎么做吗?
application.yml 客户端
security:
basic:
enabled: false
oauth2:
sso:
loginPath: /login
client:
clientId: web_app
clientSecret: secret
accessTokenUri: https://localhost/uaa/oauth/token
userAuthorizationUri: https://localhost/uaa/oauth/authorize
CustomUserDetailsService
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
try {
//I would like to recover the client_id in this location
User domainUser = userRepository.findByUsername(username);
必须验证任何服务器,因为我对所有应用程序都有一个登录:
Auth 服务器身份验证由用户和密码以及应用程序完成。
假设您正在登录“https://accounts.google.com/”,谷歌会检查用户名和密码,并显示您的帐户以及“产品”的快捷方式。
现在,如果您访问“https://mail.google.com”,谷歌会检查用户名和密码并显示 gmail 界面。就我而言,它可以来自 URL https://application.domain.com、https://application2.domain.com、https://application3.domain.com 或“https://accounts.domain.com”。
它使用用户名和密码的所有 URL,但它可以访问 application1 或全部或无。
我想做服务器端,因为它只为具有权限(信用)的应用程序返回访问令牌。如果用户和密码正确,并不意味着用户可以访问所有应用程序。
【问题讨论】:
标签: spring-boot oauth-2.0 spring-security-oauth2