protected override async Task <bool> HandleUnauthorizedAsync(ChallengeContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            var properties = new AuthenticationProperties(context.Properties);

            if (string.IsNullOrEmpty(properties.RedirectUri))
            {
                properties.RedirectUri = CurrentUri;
            }

            // If CallbackConfirmed is false, this will throw
            var requestToken = await ObtainRequestTokenAsync(Options.ConsumerKey, Options.ConsumerSecret, BuildRedirectUri(Options.CallbackPath), properties);

            var twitterAuthenticationEndpoint = AuthenticationEndpoint + requestToken.Token;

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

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

            var redirectContext = new Twitter2RedirectToAuthorizationEndpointContext(
                Context, Options,
                properties, twitterAuthenticationEndpoint);
            await Options.Events.RedirectToAuthorizationEndpoint(redirectContext);

            return(true);
        }
Exemple #2
0
 /// <summary>
 /// Called when a Challenge causes a redirect to authorize endpoint in the Twitter2 middleware
 /// </summary>
 /// <param name="context">Contains redirect URI and <see cref="AuthenticationProperties"/> of the challenge </param>
 public virtual Task RedirectToAuthorizationEndpoint(Twitter2RedirectToAuthorizationEndpointContext context) => OnRedirectToAuthorizationEndpoint(context);
 /// <summary>
 /// Called when a Challenge causes a redirect to authorize endpoint in the Twitter2 middleware
 /// </summary>
 /// <param name="context">Contains redirect URI and <see cref="AuthenticationProperties"/> of the challenge </param>
 public virtual Task RedirectToAuthorizationEndpoint(Twitter2RedirectToAuthorizationEndpointContext context) => OnRedirectToAuthorizationEndpoint(context);