protected override async Task <AuthenticateResult> HandleAuthenticateAsync()
        {
            if (PriorHandler != null)
            {
                var authenticateContext = new AuthenticateContext(Options.SignInScheme);
                await PriorHandler.AuthenticateAsync(authenticateContext);

                if (authenticateContext.Accepted)
                {
                    if (authenticateContext.Error != null)
                    {
                        return(AuthenticateResult.Fail(authenticateContext.Error));
                    }

                    if (authenticateContext.Principal != null)
                    {
                        return(AuthenticateResult.Success(new AuthenticationTicket(authenticateContext.Principal,
                                                                                   new AuthenticationProperties(authenticateContext.Properties), Options.AuthenticationScheme)));
                    }

                    return(AuthenticateResult.Fail("Not authenticated"));
                }
            }

            return(AuthenticateResult.Fail("Remote authentication does not support authenticate"));
        }
예제 #2
0
        public async Task AuthenticateAsync(AuthenticateContext context)
        {
            var handled = false;

            if (ShouldHandleScheme(context.AuthenticationScheme, Options.AutomaticAuthenticate))
            {
                // Calling Authenticate more than once should always return the original value.
                var result = await HandleAuthenticateOnceAsync();

                if (result?.Failure != null)
                {
                    context.Failed(result.Failure);
                }
                else
                {
                    var ticket = result?.Ticket;
                    if (ticket?.Principal != null)
                    {
                        context.Authenticated(ticket.Principal, ticket.Properties.Items, Options.Description.Items);
                        Logger.AuthenticationSchemeAuthenticated(Options.AuthenticationScheme);
                        handled = true;
                    }
                    else
                    {
                        context.NotAuthenticated();
                        Logger.AuthenticationSchemeNotAuthenticated(Options.AuthenticationScheme);
                    }
                }
            }

            if (PriorHandler != null && !handled)
            {
                await PriorHandler.AuthenticateAsync(context);
            }
        }
예제 #3
0
        public virtual async Task AuthenticateAsync(IAuthenticateContext context)
        {
            if (context.AuthenticationTypes.Contains(BaseOptions.AuthenticationType, StringComparer.Ordinal))
            {
                AuthenticationTicket ticket = await AuthenticateAsync();

                if (ticket != null && ticket.Identity != null)
                {
                    context.Authenticated(ticket.Identity, ticket.Properties.Dictionary, BaseOptions.Description.Dictionary);
                }
                else
                {
                    context.NotAuthenticated(BaseOptions.AuthenticationType, properties: null, description: BaseOptions.Description.Dictionary);
                }
            }

            if (PriorHandler != null)
            {
                await PriorHandler.AuthenticateAsync(context);
            }
        }
예제 #4
0
        public async Task AuthenticateAsync(AuthenticateContext context)
        {
            if (ShouldHandleScheme(context.AuthenticationScheme))
            {
                // Calling Authenticate more than once should always return the original value.
                var ticket = await HandleAuthenticateOnceAsync();

                if (ticket?.Principal != null)
                {
                    context.Authenticated(ticket.Principal, ticket.Properties.Items, BaseOptions.Description.Items);
                }
                else
                {
                    context.NotAuthenticated();
                }
            }

            if (PriorHandler != null)
            {
                await PriorHandler.AuthenticateAsync(context);
            }
        }
예제 #5
0
        public virtual async Task AuthenticateAsync(IAuthenticateContext context)
        {
            if (ShouldHandleScheme(context.AuthenticationScheme))
            {
                var ticket = await AuthenticateAsync();

                if (ticket?.Principal != null)
                {
                    AuthenticateCalled = true;
                    context.Authenticated(ticket.Principal, ticket.Properties.Dictionary, BaseOptions.Description.Dictionary);
                }
                else
                {
                    context.NotAuthenticated();
                }
            }

            if (PriorHandler != null)
            {
                await PriorHandler.AuthenticateAsync(context);
            }
        }