示例#1
0
        /// <summary>
        /// Authenticates the user via an "Authentication: Bearer {token}" header.
        /// Returns a user principal containing claims from the token and a token that can be used to perform actions on behalf of the user.
        /// Throws an exception if the token fails to authenticate or if the Authentication header is malformed.
        /// This method has an asynchronous signature, but usually completes synchronously.
        /// </summary>
        /// <param name="this">The authenticator instance.</param>
        /// <param name="header">The authentication header.</param>
        /// <param name="cancellationToken">An optional cancellation token.</param>
        public static async Task <CsResult <ClaimsPrincipal> > AuthenticateAsync(this TokenAuthenticator @this, AuthenticationHeaderValue header,
                                                                                 CancellationToken cancellationToken = new CancellationToken())
        {
            if (header == null || !string.Equals(header.Scheme, "Bearer", StringComparison.InvariantCultureIgnoreCase))
            {
                return(CsResult <ClaimsPrincipal> .createError("Authentication header does not use Bearer token."));
            }

            return(await @this.AuthenticateAsync(header.Parameter, cancellationToken));
        }
示例#2
0
 public FunctionAppAuth0Authenticator(TokenAuthenticator tokenAuthenticator)
 {
     TokenAuthenticator = tokenAuthenticator;
 }
示例#3
0
 /// <summary>
 /// Authenticates the user via an "Authentication: Bearer {token}" header in an HTTP request message.
 /// Returns a user principal containing claims from the token and a token that can be used to perform actions on behalf of the user.
 /// Throws an exception if the token fails to authenticate or if the Authentication header is missing or malformed.
 /// This method has an asynchronous signature, but usually completes synchronously.
 /// </summary>
 /// <param name="this">The authenticator instance.</param>
 /// <param name="request">The HTTP request.</param>
 /// <param name="cancellationToken">An optional cancellation token.</param>
 public static Task <CsResult <ClaimsPrincipal> > AuthenticateAsync(this TokenAuthenticator @this, HttpRequestMessage request,
                                                                    CancellationToken cancellationToken = new CancellationToken()) =>
 @this.AuthenticateAsync(request.Headers.Authorization, cancellationToken);