Hello Team,
I have to call from my backend URL using service callout policy for that URL, I have to send username and password using basic authentication. How to build basic authentication in servicecallout.
Thank you,
Solved! Go to Solution.
In service callout you can set the header Authorization, in which you will send basic Authorization value.
Also you can use basic Authentication policy before service callout, and encode the username and password to another variable and then set the variable to Authorization header in the service callout.
<BasicAuthentication name="ApplyBasicAuthHeader"> <DisplayName>ApplyBasicAuthHeader</DisplayName> <Operation>Encode</Operation> <IgnoreUnresolvedVariables>false</IgnoreUnresolvedVariables> <User ref="BasicAuth.credentials.username" /> <Password ref="BasicAuth.credentials.password" /> <AssignTo>xyz</AssignTo> </BasicAuthentication>
Then
<ServiceCallout name="ServiceCallout-GeocodingRequest1"> <DisplayName>Inline request message</DisplayName> <Request variable="authenticationRequest"> <Set> <Headers> <Header name="Authorization">{xyz}</Header> </Headers> </Set> </Request> <Response>GeocodingResponse</Response> <Timeout>30000</Timeout> <HTTPTargetConnection> <URL>http://maps.googleapis.com/maps/api/geocode/json</URL> </HTTPTargetConnection> </ServiceCallout>
You can try message template in service callout.
<Set> <Headers> <Header name="request.header.Authorization">Basic {encodeBase64(request.header.username':'request.header.password)}</Header> </Headers> </Set>
In service callout you can set the header Authorization, in which you will send basic Authorization value.
Also you can use basic Authentication policy before service callout, and encode the username and password to another variable and then set the variable to Authorization header in the service callout.
<BasicAuthentication name="ApplyBasicAuthHeader"> <DisplayName>ApplyBasicAuthHeader</DisplayName> <Operation>Encode</Operation> <IgnoreUnresolvedVariables>false</IgnoreUnresolvedVariables> <User ref="BasicAuth.credentials.username" /> <Password ref="BasicAuth.credentials.password" /> <AssignTo>xyz</AssignTo> </BasicAuthentication>
Then
<ServiceCallout name="ServiceCallout-GeocodingRequest1"> <DisplayName>Inline request message</DisplayName> <Request variable="authenticationRequest"> <Set> <Headers> <Header name="Authorization">{xyz}</Header> </Headers> </Set> </Request> <Response>GeocodingResponse</Response> <Timeout>30000</Timeout> <HTTPTargetConnection> <URL>http://maps.googleapis.com/maps/api/geocode/json</URL> </HTTPTargetConnection> </ServiceCallout>
You can try message template in service callout.
<Set> <Headers> <Header name="request.header.Authorization">Basic {encodeBase64(request.header.username':'request.header.password)}</Header> </Headers> </Set>