Example #1
0
        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 TwitterRedirectToAuthorizationEndpointContext(
                Context, Options,
                properties, twitterAuthenticationEndpoint);
            await Options.Events.RedirectToAuthorizationEndpoint(redirectContext);

            return(true);
        }
Example #2
0
        protected override async Task <bool> HandleUnauthorizedAsync([NotNull] ChallengeContext context)
        {
            var properties = new AuthenticationProperties(context.Properties);

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

            var requestToken = await ObtainRequestTokenAsync(Options.ConsumerKey, Options.ConsumerSecret, BuildRedirectUri(Options.CallbackPath), properties);

            if (requestToken.CallbackConfirmed)
            {
                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 TwitterRedirectToAuthorizationEndpointContext(
                    Context, Options,
                    properties, twitterAuthenticationEndpoint);
                await Options.Events.RedirectToAuthorizationEndpoint(redirectContext);

                return(true);
            }
            else
            {
                Logger.LogError("requestToken CallbackConfirmed!=true");
            }
            return(false); // REVIEW: Make sure this should not stop other handlers
        }
Example #3
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 Task RedirectToAuthorizationEndpoint(TwitterRedirectToAuthorizationEndpointContext context) => OnRedirectToAuthorizationEndpoint(context);
 internal static Task RedirectToAuthorizationEndpoint(TwitterRedirectToAuthorizationEndpointContext context)
 {
     context.Response.Redirect(context.RedirectUri + "&custom_redirect_uri=custom");
     return Task.FromResult(0);
 }
Example #5
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 Task RedirectToAuthorizationEndpoint(TwitterRedirectToAuthorizationEndpointContext context) => OnRedirectToAuthorizationEndpoint(context);