Basic Authentication with header format Authorization user:pass format

Not applicable

Hi,

I want to hit a target url with takes header as

Authorization Basic user=name:passwo0rd

I have used basic authentication Encode policy and attached it to request preflow

<BasicAuthentication name="ApplyBasicAuthHeader">
   <DisplayName>ApplyBasicAuthHeader</DisplayName>
   <Operation>Encode</Operation>
   <IgnoreUnresolvedVariables>false</IgnoreUnresolvedVariables>
   <User ref="BasicAuth.credentials.username" />
   <Password ref="BasicAuth.credentials.password" />
   <AssignTo createNew="false">request.header.Authorization</AssignTo>
</BasicAuthentication>

Is there any better way to implement this and how this username password will be populated.
Please give me a better insight.

Solved Solved
0 1 3,862
1 ACCEPTED SOLUTION

HI @abhishek giri - Thats not a valid Authorization header. More details here

Typically you pass the base64 encoded value of username:password within the Authorization header with prefix as "Basic". For example Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==

Your policy code looks good provided you have the variables populated with the correct values. The policy above is using a reference variable which should contain the actual value of the user and password. Hopefully thats the case. If not, please get them populated and see if that did the trick

View solution in original post

1 REPLY 1

HI @abhishek giri - Thats not a valid Authorization header. More details here

Typically you pass the base64 encoded value of username:password within the Authorization header with prefix as "Basic". For example Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==

Your policy code looks good provided you have the variables populated with the correct values. The policy above is using a reference variable which should contain the actual value of the user and password. Hopefully thats the case. If not, please get them populated and see if that did the trick