Generating the Authorization Header for RWX_BASIC

By default AuctionWorx Web API blocks anonymous clients from accessing protected resources. Instead of a traditional Login page, the mobile web client page displays username and password fields as shown in the image . The typed values are assembled with Javascript and jQuery code to produce an HTTP Authorization header.

There are two schemes for presenting login credentials: RWX_BASIC and RWX_SECURE. This client uses the simpler version which is easy to generate in client-side script.

An Authorization Request header for the RWX_BASIC schema looks like the following:

Authorization RWX_BASIC kencox:abc!123!

The header value is composed of the scheme, RWX_BASIC + a space + the username + a colon + the user's password.

The client example generates the header in the setHeaders() function, shown in the following snippet.

The jQuery xhr variable is an XMLHttpRequest object. The setRequestHeader(name, value) method takes two parameters: the name of the header to set (Authorization) and the formatted credentials.

The formatted credentials include the values in the username and password textboxes (lines 4-6) separated by a colon.

function setHeaders(xhr) {
    xhr.setRequestHeader('Authorization',
                          'RWX_BASIC '
                          + $("#txtUsername").val()
                          + ":"
                          + $("#txtPassword").val());
    return xhr;
}

Note: When using RWX_BASIC, the Authorization header is sent as part of every request and evaluated on the server each time.

Copyright © 2002-2022. RainWorx Software. All rights reserved.