Exemplo n.º 1
0
        protected override Task ApplyResponseChallengeAsync()
        {
            if (base.Response.StatusCode != 401)
            {
                return(Task.FromResult <object>(null));
            }
            AuthenticationResponseChallenge authenticationResponseChallenge = base.Helper.LookupChallenge(base.Options.AuthenticationType, base.Options.AuthenticationMode);

            if (authenticationResponseChallenge != null)
            {
                string arg = string.Concat(new object[]
                {
                    base.Request.Scheme,
                    Uri.SchemeDelimiter,
                    base.Request.Host,
                    base.Request.PathBase
                });
                string redirectUri = arg + base.Request.Path + base.Request.QueryString;
                string value       = arg + base.Options.CallbackPath;
                AuthenticationProperties properties = authenticationResponseChallenge.Properties;
                if (string.IsNullOrEmpty(properties.RedirectUri))
                {
                    properties.RedirectUri = redirectUri;
                }
                base.GenerateCorrelationId(properties);
                Dictionary <string, string> dictionary = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase);
                dictionary.Add("response_type", "code");
                dictionary.Add("client_id", base.Options.ClientId);
                dictionary.Add("redirect_uri", value);
                string text = string.Join(" ", base.Options.Scope);
                if (string.IsNullOrEmpty(text))
                {
                    text = "get_user_info,get_info,add_t,del_t,add_pic_t,get_repost_list";
                }
                QQOAuth2AuthenticationHandler.AddQueryString(dictionary, properties, "scope", text);
                string value2 = base.Options.StateDataFormat.Protect(properties);
                dictionary.Add("state", value2);
                string redirectUri2 = AddQueryString(AuthorizeEndpoint, dictionary);
                QQOAuth2ApplyRedirectContext context = new QQOAuth2ApplyRedirectContext(base.Context, base.Options, properties, redirectUri2);
                base.Options.Provider.ApplyRedirect(context);
            }
            return(Task.FromResult <object>(null));
        }
 /// <summary>
 /// Called when a Challenge causes a redirect to authorize endpoint in the QQ OAuth 2.0 middleware
 /// </summary>
 /// <param name="context">Contains redirect URI and <see cref="T:Microsoft.Owin.Security.AuthenticationProperties" /> of the challenge </param>
 public virtual void ApplyRedirect(QQOAuth2ApplyRedirectContext context)
 {
     this.OnApplyRedirect(context);
 }