Public Member Functions | List of all members
BPrivate::Network::BHttpAuthentication Class Reference

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 BStringPassword () 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 BStringUserName () const

Detailed Description

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.

Constructor & Destructor Documentation

◆ BHttpAuthentication() [1/2]

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.

◆ BHttpAuthentication() [2/2]

BHttpAuthentication::BHttpAuthentication ( const BString username,
const BString password 

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.

Member Function Documentation

◆ Authorization()

BString BHttpAuthentication::Authorization ( const BUrl url,
const BString method 
) const

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.

the generated reply

◆ Initialize()

status_t BHttpAuthentication::Initialize ( const BString wwwAuthenticate)

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.

wwwAuthenticatethe value of the WWW-Authenticate HTTP header field.
B_OK if the request was parsed, B_ERROR if there is a parsing error, B_BAD_VALUE if the authentication string is empty.

◆ Method()

BHttpAuthenticationMethod BHttpAuthentication::Method ( ) const
the authentication method

◆ Password()

const BString & BHttpAuthentication::Password ( ) const
the password.

◆ SetMethod()

void BHttpAuthentication::SetMethod ( BHttpAuthenticationMethod  method)

Set the authentication method.

methodthe new authentication method.

◆ SetPassword()

void BHttpAuthentication::SetPassword ( const BString password)

Set the password.

passwordthe new password.

◆ SetUserName()

void BHttpAuthentication::SetUserName ( const BString username)

Set the user name.

usernamethe new user name.

◆ UserName()

const BString & BHttpAuthentication::UserName ( ) const
the user name.