Exemple #1
0
        protected override async Task <bool> HandleUnauthorizedAsync(ChallengeContext context)
        {
            var properties = new AuthenticationProperties(context.Properties);

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

            var tenantOptions = new MultiTenantTwitterOptionsResolver(Options, siteResolver, siteRepo, multiTenantOptions);

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

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

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

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

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

                var redirectContext = new TwitterApplyRedirectContext(
                    Context, Options,
                    properties, twitterAuthenticationEndpoint);

                Options.Notifications.ApplyRedirect(redirectContext);
                return(true);
            }
            else
            {
                Logger.LogError("requestToken CallbackConfirmed!=true");
            }
            return(false); // REVIEW: Make sure this should not stop other handlers
        }
 internal static void OnApplyRedirect(TwitterApplyRedirectContext context)
 {
     context.Response.Redirect(context.RedirectUri + "&custom_redirect_uri=custom");
 }
 /// <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);
 }
Exemple #4
0
 public void ApplyRedirect(TwitterApplyRedirectContext context)
 {
     context.Response.Redirect(context.RedirectUri);
 }