Can you pass username/pass for Authentication in URL?

Hi there,

I have a backend server(SAP Netwear) which expects the username:password in the below format.

https://username:password@domain.com/

I tried with couple of options like:

1. Sending the credentials using the Basic Authentication policy -base 64 encoding

2. Using Service Callout

3. Using JavaScript Dynamic Target URL

All the scenario's getting 401Unauthorized, looks like the credentials are not reaching to target properly. Will Apigee supports such kind of URL patterns? Can you please share any examples available? However, CURL is working to the direct URL from the Apigee servers.

Thanks.

0 1 7,150
1 REPLY 1

when you insert credentials in the URL after the scheme ... the http client (curl, the browser, etc) extracts those creds and creates an Authorization header with Basic Authentication. More details here. Not all clients follow this convention. The Chrome browser, for example, recently removed support for doing this. I think the http client used by the Apigee Service Callout policy does not provide this "syntactic sugar" assistance. You have to set the header yourself, explicitly.

You will be able to use the BasicAuthentication policy to do what's necessary. You said you tried "sending the credentials using the Basic Authentication policy". To be precise, the BasicAuthentication policy doesn't send credentials. The only thing it does is encode or decode a Basic Auth header. You need a complementary policy like ServiceCallout or a JS to "send" the header that was thus encoded.

I suspect that when you used the BasicAuthentication policy, you had some other problem or glitch in either how you're using the policy or how the variable you set with that policy is being propagated into the request being sent by ServiceCallout or JS, to the NetWeaver endpoint.

Double check everything and give it another shot. If you can't figure it out, maybe try an echo endpoint. Use the same policies to send (FAKE!) credentials to an echo endpoint (like this one) to verify that your policies are sending what you think they should be sending. That echo service will just send back to you in a response, some data indicating what the endpoint received.

This is a handy tool for diagnosing many questions like "Why is my backend responding the way it responds?"