gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:12:35 27 4
gpt4 key购买 nike

我已经阅读并实现了我自己的 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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com