Authentication token for the HTTP protocol. More...
Public Member Functions | |
BHttpAuthentication () | |
Default constructor. More... | |
BHttpAuthentication (const BString &username, const BString &password) | |
Create an authentication session with the given name and password. More... | |
BString | Authorization (const BUrl &url, const BString &method) const |
Generate an authentication reply for the given URL and method. More... | |
status_t | Initialize (const BString &wwwAuthenticate) |
Initialize the object from the given authentication data. More... | |
BHttpAuthenticationMethod | Method () const |
const BString & | Password () const |
void | SetMethod (BHttpAuthenticationMethod type) |
Set the authentication method. More... | |
void | SetPassword (const BString &password) |
Set the password. More... | |
void | SetUserName (const BString &username) |
Set the user name. More... | |
const BString & | UserName () const |
Authentication token for the HTTP protocol.
This class allows managing of an authenticated http session. It stores the authentication credentials and realm and provides tools for generating the required nonces and hashes.
An instance of this class should be used for the whole length of an HTTP authenticated session. Initialize it by calling Initialize() and setting the username and password (from the constructor or the setter methods). Then, for each page that requires authentication, generate a token using the Authorization() method.
BHttpAuthentication::BHttpAuthentication | ( | ) |
Default constructor.
This will create an unconfigured authentication object with the authentication method set to B_HTTP_AUTHENTICATION_NONE.
You have to set the username and password, and initialize the object using the Initialize method with proper authentication data.
Create an authentication session with the given name and password.
The authentication method is set to B_HTTP_AUTHENTICATION_NONE. This object can then be used with the Initialize method to bind it to an HTTP authenticated session.
Generate an authentication reply for the given URL and method.
For basic authentication, the reply is constant and is a Base64 encoding of the string made of 'username:password'. In digest mode, each request will have a different reply, so you must call this method for each page you want to authenticate with.
Initialize the object from the given authentication data.
This method will parse the given authentication challenge and initialize the authentication type to either B_HTTP_AUTHENTICATION_BASIC or B_HTTP_AUTHENTICATION_DIGEST. The authentication parameters (realm, nonce, algorithm) and state (opaque, stale) are also parsed and stored.
wwwAuthenticate | the value of the WWW-Authenticate HTTP header field. |
BHttpAuthenticationMethod BHttpAuthentication::Method | ( | ) | const |
const BString & BHttpAuthentication::Password | ( | ) | const |
void BHttpAuthentication::SetMethod | ( | BHttpAuthenticationMethod | method | ) |
Set the authentication method.
method | the new authentication method. |
void BHttpAuthentication::SetPassword | ( | const BString & | password | ) |
Set the password.
password | the new password. |
void BHttpAuthentication::SetUserName | ( | const BString & | username | ) |
Set the user name.
username | the new user name. |
const BString & BHttpAuthentication::UserName | ( | ) | const |