java - Spring Boot Auth 服务器中的多个 SSO 提供程序

标签 java spring-boot oauth-2.0 spring-security-oauth2

我已经阅读并实现了我自己的 Auth 服务器,遵循 this tutorial来自 Spring 。有多个 SSO 提供程序——Facebook、Github 和自定义身份验证服务器。在本教程中,auth 服务器包含对其他 SSO 提供程序的处理。

我有一个单独的资源服务器,它使用以下属性链接到我的身份验证服务器:

security.oauth2.resource.userInfoUri=http://localhost:9000/user

我可以使用 cUrl 命令从我的身份验证服务器获取 token :

curl acme:acmesecret@localhost:9000/oauth/token -d grant_type=password -d username=user -d password=...
{"access_token":"aa49e025-c4fe-4892-86af-15af2e6b72a2","token_type":"bearer","refresh_token":"97a9f978-7aad-4af7-9329-78ff2ce9962d","expires_in":43199,"scope":"read write"}

但我不明白的是,我如何使用其他 SSO 提供程序从身份验证服务器获取此类 token ?资源服务器不应该关心我是如何获得 token 的,以及我是使用 Facebook 还是我的自定义身份验证服务器进行身份验证的。它应该简单地询问 auth 服务器什么是 Principal(登录用户),然后决定向他显示哪些资源,对吗?

我没有任何 UI,这将支持移动应用程序,因此我需要了解如何使用 REST 请求处理身份验证。

最佳答案

如果我正确理解你的问题,

how can I use the other SSO providers to get such token as well from the auth server?

此自定义 Auth 服务器正在抽象出您与 FB 或 Github 的交互,并向您颁发它自己的 token 。您的自定义 Auth 服务器吐出的 token 不是 FB 或 Github token ,它是由您的自定义 Auth 服务器生成的 token (在使用 FB/Github token 进行身份验证后)。

Then why do we need FB/github?

您的自定义 Auth 服务器还可以如何识别一个人,它当然可以使用用户 ID 和密码;将“使用 FB 登录”视为它为用户提供的另一个不错的选择。

How to add other SSO providers like digitalocean in addition to FB and github?

就像我们为 FB 和 Github 做的一样(在 digital ocean 注册一个客户端 id,然后在 auth 服务器应用程序中,在 properties/yaml 文件中添加客户端 id 和密码等)

The resource server should not care how did I get the token and whether I am authenticated using Facebook or my custom auth server. It should simply ask the auth server what is the Principal (logged user) and then decide which resources to show him, right?

是的,你的理解是正确的。

编辑(回答评论中提出的问题)

But lets say I log in with Facebook through my Auth server. Where do I find the token that I can use with the Resource server? Let's say I have a RestClient and want to make a request to obtain some resource belonging to a user which went through the Facebook auth process via my auth server. Where do I find the token to use?

如果这是一个要求,我想你可以使用这个 example反而;您可能不需要这样的自定义身份验证服务器。拥有自定义身份验证服务器的全部意义在于抽象出与 FB 或 github 的交互。

或者

如果您仍想使用自定义身份验证服务器方向,则从身份验证服务器公开一个端点(这将使您从 FB 获得所需的资源),然后从您的资源服务器中使用它。

关于java - Spring Boot Auth 服务器中的多个 SSO 提供程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41738864/

相关文章:

java - 处理 Java 和 C# REST API 之间的 JSON 互操作

java - 处理错误: UnsupportedGrantTypeException,不支持的授权类型:密码

c# - Azure 上的 Google Analytics API

java - 将文件扫描到字节数组时出现 ArrayIndexOutOfBoundsException

java - 使用 Scanner 类解析文本文件并通过多个循环计数模式出现次数

java - 多线程代码和条件变量的使用

java - 带有额外字段的 JPA 自引用 OneToMany 映射

java - Spring Boot Tomcat 无法在特定端口上启动

java - AclClassIdUtils : Unable to obtain the class id type

java - 是否可以使用移动设备和 QRCodes 通过两因素身份验证来实现 OAuth?