Exemplo n.º 1
0
        /// <summary>
        /// Handles the authentication by checking the "Authorization" header.
        /// </summary>
        protected override async Task <AuthenticateResult> HandleAuthenticateAsync()
        {
            try
            {
                var header = Request.Headers["Authorization"];

                if (IsBasicAuthentication(header))
                {
                    var credentials = DecodeCredentials(header);
                    var context     = new BasicSignInContext(Context, Scheme, Options, credentials);
                    await Options.Events.SignInAsync(context);

                    if (context.Principal != null)
                    {
                        var ticket = new AuthenticationTicket(context.Principal, context.Properties, Scheme.Name);
                        return(AuthenticateResult.Success(ticket));
                    }

                    return(AuthenticateResult.Fail("No principal."));
                }

                return(AuthenticateResult.NoResult());
            }
            catch (Exception ex)
            {
                return(AuthenticateResult.Fail(ex));
            }
        }
 /// <summary>
 /// Implements the interface method by invoking the related delegate method.
 /// </summary>
 /// <param name="context">Contains information about the event.</param>
 public virtual Task SignInAsync(BasicSignInContext context)
     => OnSignIn(context);