计划设置一个IdentityServer并将其配置为多个资源,如:
internal static IEnumerable<ApiResource> GetApiResources()
{
return new List<ApiResource>
{
new ApiResource()
{
Name = "API 1",
DisplayName = "API 1",
Description = "API 1 Access",
Scopes = new List<Scope>()
{
new Scope("public"), new Scope("write")
}
},
new ApiResource
{
Name = "API 2",
DisplayName = "API 2",
Description = "API 2 Access",
Scopes = new List<Scope>
{
new Scope("public"), new Scope("write")
}
}
};
}然后,客户机1将只访问API 1,客户机2将只访问API 2。两个客户都有公共范围。
上面这样的内容会起作用吗?还是我应该更改作用域的名称,并使其对于每个API资源都是唯一的?
在多个API中使用1标识/授权服务器是个坏主意吗?
发布于 2017-01-24 07:30:01
此设计的主要问题是客户端1和客户端2在其承载令牌中具有相同的范围。两个客户端都可以访问任何一个API资源。您可以通过API来“命名空间”范围,如下所示:
internal static IEnumerable<ApiResource> GetApiResources()
{
return new List<ApiResource>
{
new ApiResource()
{
Name = "API 1",
DisplayName = "API 1",
Description = "API 1 Access",
Scopes = new List<Scope>()
{
new Scope("api1.public"), new Scope("api1.write")
}
},
new ApiResource
{
Name = "API 2",
DisplayName = "API 2",
Description = "API 2 Access",
Scopes = new List<Scope>
{
new Scope("api2.public"), new Scope("api2.write")
}
}
};
}尽管如此,在大量的API/参考资料中使用1授权服务器并没有什么错。为多个API使用1个授权服务器是将授权问题与身份服务器分离开来的优势之一。
https://stackoverflow.com/questions/41821447
复制相似问题