//----------------------------------------------------------------------- // // Copyright (c) Andrew Arnott. All rights reserved. // //----------------------------------------------------------------------- namespace DotNetOpenAuth.OAuth2.ChannelElements { using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Web; using DotNetOpenAuth.Messaging; using DotNetOpenAuth.OAuth2.Messages; /// /// Reads client authentication information from the HTTP Authorization header via Basic authentication. /// public class ClientCredentialHttpBasicReader : ClientAuthenticationModuleBase { /// /// The authorization server host. /// private readonly IAuthorizationServerHost authorizationServerHost; /// /// Initializes a new instance of the class. /// /// The authorization server host. public ClientCredentialHttpBasicReader(IAuthorizationServerHost authorizationServerHost) { Requires.NotNull(authorizationServerHost, "authorizationServerHost"); this.authorizationServerHost = authorizationServerHost; } /// /// Attempts to extract client identification/authentication information from a message. /// /// The incoming message. /// Receives the client identifier, if one was found. /// The level of the extracted client information. public override ClientAuthenticationResult TryAuthenticateClient(AuthenticatedClientRequestBase requestMessage, out string clientIdentifier) { Requires.NotNull(requestMessage, "requestMessage"); var credential = OAuthUtilities.ParseHttpBasicAuth(requestMessage.Headers); if (credential != null) { clientIdentifier = credential.UserName; return TryAuthenticateClient(this.authorizationServerHost, credential.UserName, credential.Password); } clientIdentifier = null; return ClientAuthenticationResult.NoAuthenticationRecognized; } } }