如何在ASP.NET Core中为多个网站和移动应用程序创建单个JWT身份验证和授权服务器

发布于 2025-02-11 01:12:29 字数 791 浏览 1 评论 0原文

我发现为每个网站设置验证服务都很麻烦。

这是我的场景:我当前有三个网站,例如example.comexample.org example.space.space.space

我发现分别为每个人配置auth是很累。我想要的是创建具有不同数据库在其他端口上运行的集中化身份验证服务。例如,在示例中。net:7000

每当用户请求通过将其电子邮件password发送到example> example.com/authexample.org/auth 或可能只是示例.net/auth他们将收到一个JWT令牌,可用于访问各个站点或其移动应用程序上的受保护资源。而且,如果移动应用程序,它应该没有从浏览器打开任何网站。

我的意思是,用户不应该意识到此过程是单个服务器正在处理他们的凭据。就像Google一样,用户可以在gmail.com上登录,并且还登录到google> google.com

我已经看了看OpenIddict,但发现它涉及一些重定向(为了验证用户,用户被重定向到auth服务器,然后发送回上一个URL)。我希望它像机器一样用于机器通信,而没有涉及的用户交互,而不是在简单的HTTP POST API请求中发送包含其凭据的JSON。

我该如何实现?是否有任何示例存储库。

注意:我正在为移动应用程序使用Flutter。

I find setting up the auth services for every website is cumbersome.

This is my scenario: I have currently three websites for example example.com, example.org and example.space and their mobile apps respectively.

I found it's tiring to configure auth for each of them separately. What I want is to create a centralise auth service running on a different port with a different database. For example on example.net:7000.

Whenever users request to be authenticated by sending their email and password to example.com/auth, example.org/auth or maybe just example.net/auth they will receive a JWT token which can be used to access the protected resources on the respective sites or their mobile apps. And it should be without opening any website from the browser in case of the mobile apps.

I mean users shouldn't be aware of this process that their credentials is being handling by a single server. It's kind of like Google where user can login on to gmail.com and also gets logged in to google.com.

I have taken a look to Openiddict but found out that it has some redirections involved (to auth a user, the user is being redirected to the auth server and then send back to the previous url). I want it to be like machine to machine communication with no user interactions involved rather than sending an JSON containing their credential in a simple HTTP POST API request.

How can I achieve this? Is there any example repository.

Note: I am using Flutter for the mobile apps.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文