/// <summary>
 /// Invoked prior to the <see cref="System.Security.Claims.ClaimsIdentity"/> being saved in a local cookie and the browser being redirected to the originally requested URL.
 /// </summary>
 /// <param name="context"></param>
 /// <returns>A <see cref="Task"/> representing the completed operation.</returns>
 public virtual Task ReturnEndpoint(Auth0ReturnEndpointContext context)
 {
     return OnReturnEndpoint(context);
 }
Exemplo n.º 2
0
        private async Task <bool> InvokeReplyPathAsync()
        {
            if (Options.CallbackPath.HasValue && Options.CallbackPath == Request.Path)
            {
                if (Request.Query["error"] != null)
                {
                    _logger.WriteVerbose("Remote server returned an error: " + Request.QueryString);

                    var redirectUrl = RequestPathBase + Options.ErrorRedirectPath + Request.QueryString;
                    Response.Redirect(redirectUrl);
                    return(true);
                }

                AuthenticationTicket ticket = await AuthenticateAsync();

                if (ticket == null)
                {
                    _logger.WriteWarning("Invalid return state, unable to redirect.");
                    Response.StatusCode = 500;
                    return(true);
                }

                var context = new Auth0ReturnEndpointContext(Context, ticket);
                context.SignInAsAuthenticationType = Options.SignInAsAuthenticationType;
                context.RedirectUri = ticket.Properties != null ? ticket.Properties.RedirectUri : null;

                await Options.Provider.ReturnEndpoint(context);

                if (context.SignInAsAuthenticationType != null && context.Identity != null)
                {
                    ClaimsIdentity grantIdentity = context.Identity;
                    if (!string.Equals(grantIdentity.AuthenticationType, context.SignInAsAuthenticationType, StringComparison.Ordinal))
                    {
                        grantIdentity = new ClaimsIdentity(grantIdentity.Claims, context.SignInAsAuthenticationType, grantIdentity.NameClaimType, grantIdentity.RoleClaimType);
                    }
                    Context.Authentication.SignIn(context.Properties, grantIdentity);
                }

                if (!context.IsRequestCompleted)
                {
                    string redirectUri = context.RedirectUri ?? RequestPathBase + Options.RedirectPath.ToString();
                    if (context.Identity == null)
                    {
                        // add a redirect hint that sign-in failed in some way
                        redirectUri = WebUtilities.AddQueryString(redirectUri, "error", "access_denied");
                    }

                    if (context.Request.Query["state"] != null && context.Request.Query["state"].Contains("ru="))
                    {
                        // set returnUrl with state -> ru
                        var state = HttpUtilities.ParseQueryString(context.Request.Query["state"]);
                        redirectUri = WebUtilities.AddQueryString(redirectUri, "returnUrl", state["ru"]);
                    }

                    Response.Redirect(redirectUri);
                    context.RequestCompleted();
                }

                return(context.IsRequestCompleted);
            }
            return(false);
        }
Exemplo n.º 3
0
 /// <summary>
 /// Invoked prior to the <see cref="System.Security.Claims.ClaimsIdentity"/> being saved in a local cookie and the browser being redirected to the originally requested URL.
 /// </summary>
 /// <param name="context"></param>
 /// <returns>A <see cref="Task"/> representing the completed operation.</returns>
 public virtual Task ReturnEndpoint(Auth0ReturnEndpointContext context)
 {
     return(OnReturnEndpoint(context));
 }