【发布时间】:2020-12-26 06:11:08
【问题描述】:
我正在尝试学习使用 net core 的微服务方法应该是怎样的。因此,经过大量教程,这就是我到目前为止所得到的:
-
我创建了两个 apis 项目:Company 和 Package。端口 5002 和 5010
-
我需要一个网关,Ocelot 就是一个。我有这个配置:
{
"Routes": [
// Company Api
{
"DownstreamPathTemplate": "/api/company/{everything}",
"DownstreamScheme": "http",
"DownstreamHostAndPorts": [
{
"Host": "localhost",
"Port": 5002
}
],
"UpstreamPathTemplate": "/api/company/{everything}",
"UpstreamHttpMethod": [
"GET"
],
"AuthenticationOptions": {
"AuthenticationProviderKey": "TestKey",
"AllowedScopes": []
},
"AddHeadersToRequest": {
"CustomerId": "Claims[sub] > value"
}
},
// Anonymous Company Api
{
"DownstreamPathTemplate": "/api/company/getHomeSections",
"DownstreamScheme": "http",
"DownstreamHostAndPorts": [
{
"Host": "localhost",
"Port": 5002
}
],
"UpstreamPathTemplate": "/api/anonymous/company/getHomeSections",
"UpstreamHttpMethod": [
"GET"
]
},
// Package Api
{
"DownstreamPathTemplate": "/api/package/{everything}",
"DownstreamScheme": "http",
"DownstreamHostAndPorts": [
{
"Host": "localhost",
"Port": 5010
}
],
"UpstreamPathTemplate": "/api/package/{everything}",
"UpstreamHttpMethod": [
"GET"
],
"AuthenticationOptions": {
"AuthenticationProviderKey": "TestKey",
"AllowedScopes": []
}
}
],
"GlobalConfiguration": {
"BaseUrl": "http://localhost:5000"
},
"AllowedHosts": "*"
}
- 我有一个配置了身份和 mongoDB 的 identityServer4。像魅力一样工作。
我已经在 Angular 10 中配置了一个客户端。我可以登录,我得到了令牌,一切都按预期工作。
现在我最大的问题是,如何根据 API/角色授予用户访问权限?那么假设角色 A 可以访问公司/读取,而角色 B 可以访问公司/读取和公司/写入?
实际上是如何实现的?
非常感谢。
【问题讨论】:
标签: .net-core microservices identityserver4 ocelot