Problem
I would like to pass credentials in an url to access my Apache server.
My .htaccess is set up for basic auth.
AuthType Basic
And displays an Auth window where I can enter the credentials. All fine BUT …
The problem is that the url is within a script and is used to access an API.
<script>
....
ocpu.seturl("//xx.xx.xx.xx/ocpu/library/base/R")
....
</script>
What I tried
I tried to pass credentials using:
ocpu.seturl("//user:[email protected]/ocpu/library/base/R")
Or something like
ocpu.seturl("////xx.xx.xx.xx?username=user&pass=password/ocpu/library/base/R")
But it does not work. In addition (and as expected), if I enter the credentials in a web browser, e.g.
http://xx.xx.xx.xx?username=user&pass=password
it does not work (meaning the Auth window appears).
Is it not possible ? Or do I have to encode the credentials ?
Thanks
2
Answers
Maybe you’re going about this the wrong way. You should host the webpage on the same server as the ocpu page, and then the credentials that the user enters when loading the webpage, will automatically be used when calling the API.
Did you try including your web front-end inside the app, as in the example apps?
Have you tried to pass the Basic Auth credentials in the authentication header? In plain JavaScript this can be done for example as following: