OpenID Connect UserInfo端點的客戶端庫是做爲擴展HttpClient
方法提供的。git
如下代碼將訪問令牌發送到UserInfo端點:github
var client = new HttpClient(); var response = await client.GetUserInfoAsync(new UserInfoRequest { Address = disco.UserInfoEndpoint, Token = token });
響應屬於UserInfoResponse
類型並具備標準響應參數的屬性。您還能夠訪問原始響應以及解析的JSON文檔(經過Raw
和Json
屬性)。c#
在使用響應以前,您應該始終檢查IsError屬性以確保請求成功:code
if (response.IsError) throw new Exception(response.Error); var claims = response.Claims;
github地址token