如何生成JWT令牌以通过API度假访问微服务
我正在尝试使用.NET Core中的微服务架构来构建项目。 假设我创建了以下服务
-Service 1
-Service 2,
然后我使用了API -GATEWAY并添加了Service1和Servic2的路线。最后,启用JWT授权层。
现在,我对如何基于用户名和密码为用户生成代币以及对用户的自定义索赔感到困惑,以便在API-Gateway验证该代币并相应地提供服务?
我应该创建另一个服务(例如IdentityService),用户可以根据用户名和密码生成令牌?
- 如果是的,则将该服务放置在API网关或API网关外部?
最好的方法是什么?
谢谢你, Saurabh Khandelwal。
I am trying to build Project with microservices architecture in .net core.
Say I have created the below services
-Service 1
-Service 2
Then I used the API-Gateway and added the routes for Service1 and Servic2. And at last, enable the JWT Authorization layer.
Now I'm confused about how to generate tokens along with the custom claims for the users based on username and password so that this token will be validated at API-Gateway and served services accordingly?
Should I create another Service (say IdentityService) where the user can generate the token based on username and password?
-If yes then, Where to place that service in the API Gateway or Outside the API Gateway?
What is the best way?
Thank you,
Saurabh Khandelwal.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
嗯,有很多可用的方法,但是每种情况都有优点和缺点。
举个例子,我总是将 Abp Framework 的方法用于任何我认为将持续很长一段时间且未来会发生大量变化的项目。
通过使用这种方法,您可以将 IdentityServer 集中在域层内,如下所示:
然后使用方法生成令牌的任何设置。例如:
我相信这种方法非常适合 DDD 模式。你可以在这里查看 使用 ABP 进行领域驱动设计
Well, there are so many approaches available, However, each scenario has pros and cons.
As an example, I always use Abp Framework's approach for any project that I believe is going to live for a long period of time with a lot of changes down the road.
By using this approach you can concentrate your IdentityServer inside the Domain layer as per below:
Then use a method to generate any settings for tokens. For example:
This approach is super great for DDD patterns I believe. you can check it out here Domain Driven Design using ABP