第9章 设备授权端点(Device Authorization Endpoint)

OAuth 2.0设备流设备授权的客户端库是作为HttpClient扩展方法提供的。

以下代码发送设备授权请求:

var client = new HttpClient();

var response = await client.RequestDeviceAuthorizationAsync(new DeviceAuthorizationRequest
{
    Address = "https://demo.identityserver.io/connect/device_authorize",
    ClientId = "device"
});

响应属于DeviceAuthorizationResponse类型并具有标准响应参数的属性。您还可以访问原始响应以及解析的JSON文档(通过RawJson属性)。

在使用响应之前,您应该始终检查IsError属性以确保请求成功:

if (response.IsError) throw new Exception(response.Error);

var userCode = response.UserCode;
var deviceCode = response.DeviceCode;
var verificationUrl = response.VerificationUri;
var verificationUrlComplete = response.VerificationUriComplete;

github地址

原文地址:https://www.cnblogs.com/thinksjay/p/10787661.html