示例#1
0
        Task IAuthenticationFilter.AuthenticateAsync(HttpAuthenticationContext context, CancellationToken cancellationToken)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            return(Task.Factory.StartNew(() =>
            {
                AuthenticationType authenticationType;
                if (Enum.TryParse(context.Request?.Headers?.Authorization?.Scheme, out authenticationType))
                {
                    context.Principal = UserPrincipal.Create(authenticationType, context.Request?.Headers?.Authorization?.Parameter);
                }
            }, cancellationToken));
        }