private async Task <bool> InvokeReplyPathAsync()
        {
            if (Options.CallbackPath.HasValue && Request.Path == Options.CallbackPath)
            {
                var ticket = await AuthenticateAsync();

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

                var context = new WeiboReturnEndpointContext(Context, ticket)
                {
                    SignInAsAuthenticationType = Options.SignInAsAuthenticationType,
                    RedirectUri = ticket.Properties.RedirectUri
                };

                await Options.Provider.ReturnEndpoint(context);

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

                if (!context.IsRequestCompleted && context.RedirectUri != null)
                {
                    string redirectUri = context.RedirectUri;
                    if (context.Identity == null)
                    {
                        // add a redirect hint that sign-in failed in some way
                        redirectUri = WebUtilities.AddQueryString(redirectUri, "error", "access_denied");
                    }
                    Response.Redirect(redirectUri);
                    context.RequestCompleted();
                }
                return(context.IsRequestCompleted);
            }
            return(false);
        }
        public async Task <bool> InvokeReturnPathAsync()
        {
            AuthenticationTicket model = await this.AuthenticateAsync();

            bool flag;

            if (model == null)
            {
                this.Response.StatusCode = 500;
                flag = true;
            }
            else
            {
                var context = new WeiboReturnEndpointContext(this.Context, model)
                {
                    SignInAsAuthenticationType = this.Options.SignInAsAuthenticationType,
                    RedirectUri = model.Properties.RedirectUri
                };
                model.Properties.RedirectUri = null;
                await this.Options.Provider.ReturnEndpoint(context);

                if (context.SignInAsAuthenticationType != null && context.Identity != null)
                {
                    ClaimsIdentity claimsIdentity = context.Identity;
                    if (!string.Equals(claimsIdentity.AuthenticationType, context.SignInAsAuthenticationType, StringComparison.Ordinal))
                    {
                        claimsIdentity = new ClaimsIdentity(claimsIdentity.Claims, context.SignInAsAuthenticationType, claimsIdentity.NameClaimType, claimsIdentity.RoleClaimType);
                    }
                    this.Context.Authentication.SignIn(context.Properties, new ClaimsIdentity[1] {
                        claimsIdentity
                    });
                }
                if (!context.IsRequestCompleted && context.RedirectUri != null)
                {
                    if (context.Identity == null)
                    {
                        context.RedirectUri = WebUtilities.AddQueryString(context.RedirectUri, "error", "access_denied");
                    }
                    this.Response.Redirect(context.RedirectUri);
                    context.RequestCompleted();
                }
                flag = context.IsRequestCompleted;
            }
            return(flag);
        }