第9章 设备受权端点(Device Authorization Endpoint) - IdentityModel 中文文档(v1.0.0)

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

如下代码发送设备受权请求:git

var client = new HttpClient();

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

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

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

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地址ide

相关文章
相关标签/搜索