Пример #1
0
        public async Task <AuthenticateResult> AuthenticateAsync()
        {
            if (isApiQuery)
            {
                var authToken = context.Request.Headers[AuthenticateHeader];
                var authTk    = authToken.ToString();
                if (string.IsNullOrEmpty(authTk) || !Guid.TryParse(authTk, out _))
                {
                    if (!context.Request.Cookies.TryGetValue(AuthenticateHeader, out authTk))
                    {
                        return(AuthenticateResult.Fail("No authenticate!"));
                    }
                }
                var tk = await userIdentityService.GetTokenInfoAsync(authTk);

                if (tk is null)
                {
                    return(AuthenticateResult.Fail("No authenticate!"));
                }
                context.Features.Set(tk);
                var t = GetAuthTicket(tk.Name);
                return(AuthenticateResult.Success(t));
            }
            var tick = GetAuthTicket(string.Empty);

            return(AuthenticateResult.Success(tick));
        }