首页 > 解决方案 > 如何从身份服务器 3 获取多个范围的凭据?

问题描述

我正在尝试使用IdentityModel.TokenClient. 获取一个角色的凭据工作正常,但我需要在一个请求中获取两个范围的凭据。范围是“api”和“myrole”。

据我所知,应该通过简单地用空格分隔多个角色来完成,如下所示:

var client = new TokenClient(
    "https://theidentityserver.com/connect/token",
    "myclient",
    "mysecret");

var result = await client.RequestClientCredentialsAsync("api myrole");

这会生成一个请求:

> POST https://theidentityserver.com/connect/token HTTP/1.1 Connection:
> Keep-Alive Content-Type: application/x-www-form-urlencoded Accept:
> application/json Authorization: Basic [auth token here]
> Content-Length: 46 Host: theidentityserver.com
> 
> grant_type=client_credentials&scope=api+myrole

并产生响应:

{“错误”:“无效范围”}

如您所见,TokenClient生成一个请求,其中范围由加号而不是空格分隔。有什么办法可以解决这个问题还是我做错了什么?

标签: c#.netidentityserver3

解决方案


推荐阅读