src/Foundation/Net/Gimela.Net.Http/Authentication/BasicAuthentication.cs
/// <summary>
/// An authentication response have been received from the web browser.
/// Check if it's correct
/// </summary>
/// <param name="header">Authorization header</param>
/// <param name="realm">Realm that should be authenticated</param>
/// <param name="httpVerb">GET/POST/PUT/DELETE etc.</param>
/// <returns>Authentication object that is stored for the request. A user class or something like that.</returns>
/// <exception cref="ArgumentException">if authenticationHeader is invalid</exception>
/// <exception cref="ArgumentNullException">If any of the paramters is empty or null.</exception>
An authentication response have been received from the web browser.
Check if it's correct
An authentication response have been received from the web browser . Check if it ' s correct
public IAuthenticationUser Authenticate(AuthorizationHeader header, string realm, string httpVerb)
    {
      if (header == null)
        throw new ArgumentNullException("realm");
      if (string.IsNullOrEmpty(realm))
        throw new ArgumentNullException("realm");
      if (string.IsNullOrEmpty(httpVerb))
        throw new ArgumentNullException("httpVerb");
      string decoded = Encoding.UTF8.GetString(Convert.FromBase64String(header.Data));
      int pos = decoded.IndexOf(':');
      if (pos == -1)
        throw new BadRequestException("Invalid basic authentication header, failed to find colon.");
      string password = decoded.Substring(pos + 1, decoded.Length - pos - 1);
      string userName = decoded.Substring(0, pos);
      var user = _userProvider.Lookup(userName, realm);
      if (user == null)
        return null;
      if (user.Password == null)
      {
        var ha1 = DigestAuthentication.GetHA1(realm, userName, password);
        if (ha1 != user.HA1)
          return null;
      }
      else
      {
        if (password != user.Password)
          return null;
      }
      return user;
    }
public IAuthenticationUser Authenticate ( AuthorizationHeader header , string realm , string httpVerb ) { if ( header == null ) throw new ArgumentNullException ( " " ) ; if ( string . IsNullOrEmpty ( realm ) ) throw new ArgumentNullException ( " " ) ; if ( string . IsNullOrEmpty ( httpVerb ) ) throw new ArgumentNullException ( " " ) ; string decoded = Encoding . UTF8 . GetString ( Convert . FromBase64String ( header . Data ) ) ; int pos = decoded . IndexOf ( ' ' ) ; if ( pos == - 1 ) throw new BadRequestException ( " " ) ; string password = decoded . Substring ( pos + 1 , decoded . Length - pos - 1 ) ; string userName = decoded . Substring ( 0 , pos ) ; var user = _userProvider . Lookup ( userName , realm ) ; if ( user == null ) return null ; if ( user . Password == null ) { var ha1 = DigestAuthentication . GetHA1 ( realm , userName , password ) ; if ( ha1 != user . HA1 ) return null ; } else { if ( password != user . Password ) return null ; } return user ; }
An authentication response have been received from the web browser.
An authentication response have been received from the web browser .
/*
       * To receive authorization, the client sends the userid and password,
          separated by a single colon (":") character, within a base64 [7]
          encoded string in the credentials.*/
Authentication object that is stored for the request. A user class or something like that.
Authentication object that is stored for the request . A user class or something like that .
if authenticationHeader is invalid
if authenticationHeader is invalid
If any of the paramters is empty or null.
If any of the paramters is empty or null .
header
AuthorizationHeader
None
realm
string
Realm that should be authenticated
Realm that should be authenticated
httpVerb
string
None