How to use pass caller credentials (Basic Auth) from one API to another?

reagz
Kilo Contributor

I have a custom Scripted REST API that uses Basic Authentication (user ID and password).  This scripted API is calling an out of the box API that also uses Basic Authentication.

Is there a way I can set the Basic Authentication values when calling the out of the box API, using the credentials that were used to call the scripted API?

3 REPLIES 3

Maik Skoddow
Tera Patron
Tera Patron

Hi @reagz 

in your REST API Script check whether you can get the original request header "Authorization"

request.getHeader('Authorization');

Then use that value to set a corresponding header for the next REST call.

Kind regards
Maik

Hi @reagz 

In case you think I was able to answer your question, I would be happy if you mark the appropriate response as "correct" so that the question will appear as resolved for other users who may have a similar question in the future.

If not, please tell me what you are still missing!

Many thanks & kind regards
Maik

Anna Markose
Kilo Guru

Hi @reagz ,

Did you got the solution for passing the basic auth from one API to another?

In my implementation, I am calling the OOB record producer API from a custom API. The basic auth details received in the custom API is forwarded as it is received to the OOB record producer API. But I can see some sort of encoding is happening to the password other than the base 64 encoding when it is received at the serviceNow end. The OOB record producer API expects the Basic username:password in base 64 encoded format, but as the password is again encoded ,the OOB API, doesn't identifies the user and it is showing the record's created by as guest.

Please help me know, if you got any solution.