第2章 授權端點(Authorize Endpoint) - IdentityModel 中文文檔(v1.0.0)
阿新 • • 發佈:2019-04-29
token turn set tool summary htm ati redirect auth
對於大多數情況,OAuth 2.0和OpenID Connect授權端點的GET請求需要具有許多查詢字符串參數。
雖然您可以使用任何方法創建帶參數的URL來創建正確的字符串,但RequestUrl類是完成此任務的簡單幫助程序。
特別是,您可以使用CreateAuthorizeUrl
擴展方法為授權端點創建URL - 它支持最常用的參數:
/// <summary> /// Creates an authorize URL. /// </summary> /// <param name="request">The request.</param> /// <param name="clientId">The client identifier.</param> /// <param name="responseType">The response type.</param> /// <param name="scope">The scope.</param> /// <param name="redirectUri">The redirect URI.</param> /// <param name="state">The state.</param> /// <param name="nonce">The nonce.</param> /// <param name="loginHint">The login hint.</param> /// <param name="acrValues">The acr values.</param> /// <param name="prompt">The prompt.</param> /// <param name="responseMode">The response mode.</param> /// <param name="codeChallenge">The code challenge.</param> /// <param name="codeChallengeMethod">The code challenge method.</param> /// <param name="display">The display option.</param> /// <param name="maxAge">The max age.</param> /// <param name="uiLocales">The ui locales.</param> /// <param name="idTokenHint">The id_token hint.</param> /// <param name="extra">Extra parameters.</param> /// <returns></returns> public static string CreateAuthorizeUrl(this RequestUrl request, string clientId, string responseType, string scope = null, string redirectUri = null, string state = null, string nonce = null, string loginHint = null, string acrValues = null, string prompt = null, string responseMode = null, string codeChallenge = null, string codeChallengeMethod = null, string display = null, int? maxAge = null, string uiLocales = null, string idTokenHint = null, object extra = null) { ... }
例:
var ru = new RequestUrl("https://demo.identityserver.io/connect/authorize"); var url = ru.CreateAuthorizeUrl( clientId: "client", responseType: "implicit", redirectUri: "https://app.com/callback", nonce: "xyz", scope: "openid");
註意
該extra
參數可以是一個串字典或任意其它具有屬性的類型。在這兩種情況下,值都將序列化為鍵/值。
github地址
第2章 授權端點(Authorize Endpoint) - IdentityModel 中文文檔(v1.0.0)