Issue
How to add Basic Authentication header to SendWebRequest function in Script RESTful Web Services
Product Line
EcoStruxure Building Operation
Environment
- Building Operation Enterprise Server
- Building Operation Enterprise Central
- Building Operation Automation Server
- Building Operation Automation Server Premium
- Building Operation Automation Server Bundled
Cause
A 3rd party web service requires basic authentication for HTTP requests to ensure that data is requested securely, otherwise, the request will be rejected with an "Authorization Error".
Resolution
Basic Authentication is a type of Authorization Request Headers, which transmits credentials as user-id/
password pairs, encoded using Base64, as defined in RFC 7617 - The 'Basic' HTTP Authentication Scheme (ietf.org).
Follow the below steps to create a Basic Authentication header in Script RESTful Web Services:
- Combine the User ID and the Password with a colon ex. "aladdin:opensesame".
- Encode the resulting string in base64 using script function to base64 encode a string posted in the Community or using the online encoder as Base64 Encode and Decode - Online, ex. "aladdin:opensesame" will be "YWxhZGRpbjpvcGVuc2VzYW1l" after Base64 encoding.
- Construct SendWebRequest header in the following format:
Authorization: Basic <credentials>, as below example:
Headers= "Authorization: Basic YWxhZGRpbjpvcGVuc2VzYW1l"'User ID=alaadin Password=opensesame
Resultstring= SendWebRequest(BaseUrl,Method,ContentType,Headers,Message)
Note: Basic Authentication is not a secure method of user authentication unless used in conjunction with HTTPS/TLS, as the user ID and password are transmitted as clear text. User ID and Password are Base64 encoded but Base64 can be easily decoded.
For more information refer to Script RESTful Web Services WebHelp and Authorization - HTTP | MDN (mozilla.org)