Ejemplo n.º 1
0
        private async Task <bool> InvokeReplyPathAsync()
        {
            bool result;

            if (base.Options.CallbackPath.HasValue && base.Options.CallbackPath == base.Request.Path)
            {
                AuthenticationTicket authenticationTicket = await base.AuthenticateAsync();

                if (authenticationTicket == null)
                {
                    LoggerExtensions.WriteWarning(this._logger, "Invalid return state, unable to redirect.", new string[0]);
                    base.Response.StatusCode = 500;
                    result = true;
                }
                else
                {
                    QQOAuth2ReturnEndpointContext qqOAuth2ReturnEndpointContext = new QQOAuth2ReturnEndpointContext(base.Context, authenticationTicket);
                    qqOAuth2ReturnEndpointContext.SignInAsAuthenticationType = base.Options.SignInAsAuthenticationType;
                    qqOAuth2ReturnEndpointContext.RedirectUri = authenticationTicket.Properties.RedirectUri;
                    await base.Options.Provider.ReturnEndpoint(qqOAuth2ReturnEndpointContext);

                    if (qqOAuth2ReturnEndpointContext.SignInAsAuthenticationType != null && qqOAuth2ReturnEndpointContext.Identity != null)
                    {
                        ClaimsIdentity claimsIdentity = qqOAuth2ReturnEndpointContext.Identity;
                        if (!string.Equals(claimsIdentity.AuthenticationType, qqOAuth2ReturnEndpointContext.SignInAsAuthenticationType, StringComparison.Ordinal))
                        {
                            claimsIdentity = new ClaimsIdentity(claimsIdentity.Claims, qqOAuth2ReturnEndpointContext.SignInAsAuthenticationType, claimsIdentity.NameClaimType, claimsIdentity.RoleClaimType);
                        }
                        base.Context.Authentication.SignIn(qqOAuth2ReturnEndpointContext.Properties, new ClaimsIdentity[]
                        {
                            claimsIdentity
                        });
                    }
                    if (!qqOAuth2ReturnEndpointContext.IsRequestCompleted && qqOAuth2ReturnEndpointContext.RedirectUri != null)
                    {
                        string text = qqOAuth2ReturnEndpointContext.RedirectUri;
                        if (qqOAuth2ReturnEndpointContext.Identity == null)
                        {
                            text = AddQueryString(text, "error", "access_denied");
                        }
                        base.Response.Redirect(text);
                        qqOAuth2ReturnEndpointContext.RequestCompleted();
                    }
                    result = qqOAuth2ReturnEndpointContext.IsRequestCompleted;
                }
            }
            else
            {
                result = false;
            }
            return(result);
        }
 /// <summary>
 /// Invoked prior to the <see cref="T:System.Security.Claims.ClaimsIdentity" /> being saved in a local cookie and the browser being redirected to the originally requested URL.
 /// </summary>
 /// <param name="context">Contains context information and authentication ticket of the return endpoint.</param>
 /// <returns>A <see cref="T:System.Threading.Tasks.Task" /> representing the completed operation.</returns>
 public virtual Task ReturnEndpoint(QQOAuth2ReturnEndpointContext context)
 {
     return(this.OnReturnEndpoint(context));
 }