IdentityServer4-DeviceFlow授权问题

时间:2019-03-07 16:44:18

标签: c# .net asp.net-core identityserver4

我在使用IdentityServer4设置设备流授权时遇到问题。所以我创建了一个具有以下属性的客户端

new Client
{
    ClientId = "XXXXXXXXXXXXXX",
    ClientName = "XXXXXXXXXXXXXX",
    AllowedGrantTypes = GrantTypes.DeviceFlow,
    AccessTokenType = AccessTokenType.Jwt,
    ClientSecrets = new List<Secret> 
    { 
        new Secret("XXXXXXXXXXXXXX".Sha256()) 
    },
    AllowedScopes = new List<string>
    {
        "XXXXXX"
    },
    Enabled = true,
    AllowAccessTokensViaBrowser = true
}

然后,我正在设备上执行以下请求(这些请求来自示例here):

POST /device_authorization HTTP/1.1
Host: server.example.com
Content-Type: application/x-www-form-urlencoded

client_id=459691054427

哪个返回以下内容:

HTTP/1.1 200 OK
Content-Type: application/json
Cache-Control: no-store

{
  "device_code":"GMMhmHCXhWEzkobqIHGG_EnNYYsAkukHspeYUk9E8",
  "user_code":"WDJB-MJHT",
  "verification_uri":"https://www.example.com/device",
   "verification_uri_complete":"https://www.example.com/device?user_code=WDJB-MJHT",
  "expires_in": 1800,
  "interval": 5
}

此后,我继续使用设备轮询授权服务器,该服务器会做出响应:

authorization_pending

然后我从用户发送以下请求以授权设备:

POST
https://XXXXXXXXX/device/userCode

带有包含以下内容的授权标头:

Bearer token_value

来自另一个客户端应用程序的登录用户。

但是,我得到的答复是:

  

设备流程请求中没有用户

这还会在身份服务器中返回错误:

  

IdentityServer4.Services.DefaultDeviceFlowInteractionService:错误:设备授权失败-未找到用户

我授权设备的代码如下(仅需从Postman进行测试就没什么特别了):

var result = new DeviceFlowInteractionResult();

var request = await _interaction.GetAuthorizationContextAsync(userCode);
if (request == null)
{
    return result;
}

ConsentResponse grantedConsent = new ConsentResponse
{
    RememberConsent = true,
    ScopesConsented = new List<string> { "XXXXXXXX" },
};

result = await _interaction.HandleRequestAsync(userCode, grantedConsent);

return result;

有人知道这个错误吗? 这是否需要用户通过授权服务器连接到另一个客户端?

关于这件事,我似乎找不到任何合适的教程。

0 个答案:

没有答案