예제 #1
0
        protected override async Task ApplyResponseChallengeAsync()
        {
            if (Response.StatusCode != 401)
            {
                return;
            }

            // Active middleware should redirect on 401 even if there wasn't an explicit challenge.
            if (ChallengeContext == null && Options.AuthenticationMode == AuthenticationMode.Passive)
            {
                return;
            }

            string requestPrefix = Request.Scheme + "://" + Request.Host;
            string callBackUrl   = requestPrefix + RequestPathBase + Options.CallbackPath;

            AuthenticationProperties properties;

            if (ChallengeContext == null)
            {
                properties = new AuthenticationProperties();
            }
            else
            {
                properties = new AuthenticationProperties(ChallengeContext.Properties);
            }
            if (string.IsNullOrEmpty(properties.RedirectUri))
            {
                properties.RedirectUri = requestPrefix + Request.PathBase + Request.Path + Request.QueryString;
            }

            RequestToken requestToken = await ObtainRequestTokenAsync(Options.ConsumerKey, Options.ConsumerSecret, callBackUrl, properties);

            if (requestToken.CallbackConfirmed)
            {
                string twitterAuthenticationEndpoint = AuthenticationEndpoint + requestToken.Token;

                var cookieOptions = new CookieOptions
                {
                    HttpOnly = true,
                    Secure   = Request.IsSecure
                };

                Response.Cookies.Append(StateCookie, Options.StateDataFormat.Protect(requestToken), cookieOptions);

                var redirectContext = new TwitterApplyRedirectContext(
                    Context, Options,
                    properties, twitterAuthenticationEndpoint);
                Options.Notifications.ApplyRedirect(redirectContext);
            }
            else
            {
                _logger.WriteError("requestToken CallbackConfirmed!=true");
            }
        }
예제 #2
0
 /// <summary>
 /// Called when a Challenge causes a redirect to authorize endpoint in the Twitter middleware
 /// </summary>
 /// <param name="context">Contains redirect URI and <see cref="AuthenticationProperties"/> of the challenge </param>
 public virtual void ApplyRedirect(TwitterApplyRedirectContext context)
 {
     OnApplyRedirect(context);
 }