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文檔(經過Raw
和Json
屬性)。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