protected override Task ApplyResponseChallengeAsync() { if (Response.StatusCode != 401) { return(Task.FromResult <object>(null)); } AuthenticationResponseChallenge challenge = Helper.LookupChallenge(Options.AuthenticationType, Options.AuthenticationMode); if (challenge != null) { string baseUri = Request.Scheme + Uri.SchemeDelimiter + Request.Host + Request.PathBase; string currentUri = baseUri + Request.Path + Request.QueryString; string redirectUri = baseUri + Options.CallbackPath; AuthenticationProperties properties = challenge.Properties; if (string.IsNullOrEmpty(properties.RedirectUri)) { properties.RedirectUri = currentUri; } // OAuth2 10.12 CSRF GenerateCorrelationId(properties); // comma separated string scope = string.Join(",", Options.Scope); string state = Options.StateDataFormat.Protect(properties); string authorizationEndpoint = Options.AuthorizationEndpoint + "?response_type=code" + "&client_id=" + Uri.EscapeDataString(Options.AppId) + "&redirect_uri=" + Uri.EscapeDataString(redirectUri) + "&scope=" + Uri.EscapeDataString(scope) + "&state=" + Uri.EscapeDataString(state); var redirectContext = new QQApplyRedirectContext( Context, Options, properties, authorizationEndpoint); Options.Provider.ApplyRedirect(redirectContext); } return(Task.FromResult <object>(null)); }
/// <summary> /// 执行401跳转 /// </summary> /// <returns></returns> protected override Task ApplyResponseChallengeAsync() { // return base.ApplyResponseChallengeAsync(); if (Response.StatusCode != 401) { return(Task.FromResult <object>(null)); } AuthenticationResponseChallenge challenge = Helper.LookupChallenge(Options.AuthenticationType, Options.AuthenticationMode); if (challenge != null) { string baseUri = Request.Scheme + Uri.SchemeDelimiter + Request.Host + Request.PathBase; string currentUri = baseUri + Request.Path + Request.QueryString; string redirectUri = baseUri + Options.CallbackPath; AuthenticationProperties extra = challenge.Properties; if (string.IsNullOrEmpty(extra.RedirectUri)) { extra.RedirectUri = currentUri; } // OAuth2 10.12 CSRF GenerateCorrelationId(extra); string scope = string.Join(",", Options.Scope); if (string.IsNullOrEmpty(scope)) { scope = "get_user_info"; } string state = Options.StateDataFormat.Protect(extra); string authorizationEndpoint = string.Format(AuthorizationEndpoint + "?client_id={0}&redirect_uri={1}&response_type=code&scope={2}&state={3}", Uri.EscapeDataString(Options.AppId), Uri.EscapeDataString(redirectUri), Uri.EscapeDataString(scope), Uri.EscapeDataString(state)); // 跳转到 授权服务器 页面 // Context.Response.Redirect(authorizationEndpoint); var redirectContext = new QQApplyRedirectContext(Context, Options, extra, authorizationEndpoint); Options.Provider.ApplyRedirect(redirectContext); } return(Task.FromResult <object>(null)); }
/// <summary> /// Called when a Challenge causes a redirect to authorize endpoint /// </summary> public void ApplyRedirect(QQApplyRedirectContext context) { OnApplyRedirect(context); }