Exemplo n.º 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;
            }
            var callBackUri  = BuildRedirectUri(Options.CallbackPath);
            var requestToken = await ObtainRequestTokenAsync(callBackUri, properties);

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

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

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

            var redirectContext = new DeveloperAuthRedirectToAuthorizationEndpointContext(
                Context, Options,
                properties, authenticationEndpoint);
            await Options.Events.RedirectToAuthorizationEndpoint(redirectContext);

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