src/Foundation/Net/Gimela.Net.Http/Authentication/DigestAuthentication.cs
/// <summary>
/// An authentication response have been received from the web browser.
/// Check if it's correct
/// </summary>
/// <param name="header">Contents from the 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 parameters 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("header");
      lock (_nonces)
      {
        if (_timer == null)
          _timer = new Timer(ManageNonces, null, 15000, 15000);
      }
      if (!header.Scheme.Equals("digest", StringComparison.OrdinalIgnoreCase))
        return null;
      var parameters = HeaderParameterCollection.Parse(new StringReader(header.Data), ',');
      if (!IsValidNonce(parameters["nonce"]) && !DisableNonceCheck)
        return null;
      string username = parameters["username"];
      var user = _userProvider.Lookup(username, realm);
      if (user == null)
        return null;
      string HA1 = string.IsNullOrEmpty(user.HA1) ? GetHA1(realm, username, user.Password) : user.HA1;
      string A2 = String.Format("{0}:{1}", httpVerb, parameters["uri"]);
      string HA2 = GetMD5HashBinHex2(A2);
      string hashedDigest = Encrypt(HA1, HA2, parameters["qop"],
                                    parameters["nonce"], parameters["nc"], parameters["cnonce"]);
      if (parameters["response"] == hashedDigest)
        return user;
      return null;
    }
public IAuthenticationUser Authenticate ( AuthorizationHeader header , string realm , string httpVerb ) { if ( header == null ) throw new ArgumentNullException ( " " ) ; lock ( _nonces ) { if ( _timer == null ) _timer = new Timer ( ManageNonces , null , 15000 , 15000 ) ; } if ( ! header . Scheme . Equals ( " " , StringComparison . OrdinalIgnoreCase ) ) return null ; var parameters = HeaderParameterCollection . Parse ( new StringReader ( header . Data ) , ' ' ) ; if ( ! IsValidNonce ( parameters [ " " ] ) && ! DisableNonceCheck ) return null ; string username = parameters [ " " ] ; var user = _userProvider . Lookup ( username , realm ) ; if ( user == null ) return null ; string HA1 = string . IsNullOrEmpty ( user . HA1 ) ? GetHA1 ( realm , username , user . Password ) : user . HA1 ; string A2 = String . Format ( " " , httpVerb , parameters [ " " ] ) ; string HA2 = GetMD5HashBinHex2 ( A2 ) ; string hashedDigest = Encrypt ( HA1 , HA2 , parameters [ " " ] , parameters [ " " ] , parameters [ " " ] , parameters [ " " ] ) ; if ( parameters [ " " ] == hashedDigest ) return user ; return null ; }
An authentication response have been received from the web browser.
An authentication response have been received from the web browser .
// request authentication information // Encode authentication info // encode challenge info //validate
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 parameters is empty or null.
If any of the parameters is empty or null .
header
AuthorizationHeader
Contents from the Authorization header
Contents from the Authorization header
realm
string
Realm that should be authenticated
Realm that should be authenticated
httpVerb
string
None