protected virtual async Task <bool> HandleRemoteCallbackAsync()
        {
            var authResult = await HandleRemoteAuthenticateAsync();

            if (authResult != null && authResult.Skipped)
            {
                return(false);
            }
            if (authResult == null || !authResult.Succeeded)
            {
                var errorContext = new FailureContext(Context, authResult?.Failure ?? new Exception("Invalid return state, unable to redirect."));
                Logger.RemoteAuthenticationError(errorContext.Failure.Message);
                await Options.Events.RemoteFailure(errorContext);

                if (errorContext.HandledResponse)
                {
                    return(true);
                }
                if (errorContext.Skipped)
                {
                    return(false);
                }

                throw new AggregateException("Unhandled remote failure.", errorContext.Failure);
            }

            // We have a ticket if we get here
            var ticket  = authResult.Ticket;
            var context = new TicketReceivedContext(Context, Options, ticket)
            {
                ReturnUri = ticket.Properties.RedirectUri,
            };

            // REVIEW: is this safe or good?
            ticket.Properties.RedirectUri = null;

            await Options.Events.TicketReceived(context);

            if (context.HandledResponse)
            {
                Logger.SigninHandled();
                return(true);
            }
            else if (context.Skipped)
            {
                Logger.SigninSkipped();
                return(false);
            }

            await Context.Authentication.SignInAsync(Options.SignInScheme, context.Principal, context.Properties);

            // Default redirect path is the base path
            if (string.IsNullOrEmpty(context.ReturnUri))
            {
                context.ReturnUri = "/";
            }

            Response.Redirect(context.ReturnUri);
            return(true);
        }
 /// <summary>
 /// Invoked when there is a remote failure
 /// </summary>
 public virtual Task RemoteFailure(FailureContext context) => OnRemoteFailure(context);
 // Handle sign-in errors differently than generic errors.
 private Task OnAuthenticationFailed(FailureContext context)
 {
     context.HandleResponse();
     context.Response.Redirect("/Home/Error?message=" + context.Failure.Message);
     return Task.FromResult(0);
 }
Пример #4
0
 /// <summary>
 /// Invoked when there is a remote failure
 /// </summary>
 public virtual Task RemoteFailure(FailureContext context) => OnRemoteFailure(context);