0

I have a site where user must login to access. I have some web services calls for getting datas stored in another server.

But to access to the server user must login again via a login popup. To avoid this I want to pass the user/password but not in the URL.

Is it possible to do this in Javascript adding user/password in header or something similar ?

1
  • You should write a proxy in a server-side language to which you communicate using JavaScript. Otherwise the used password will be visible in your source code. Commented Mar 7, 2014 at 10:13

2 Answers 2

1

Authorization of this type is typically done via request headers. For regular users interacting with a web page, the login credentials may be remembered using the cookies in the request. For API access, however, the standard way to do this is with bearer tokens included in the POST body of the request. See also: OAuth2.

For authenticating API access (but not the user), such authentication is typically done via API keys.

Important footnote: whenever doing any authentication, you should ensure that your requests are encrypted (and, when setting cookies, that cookies used for authentication are properly marked "secure").

Sign up to request clarification or add additional context in comments.

Comments

1

Take a look at the W3C specifications for the XMLHttpRequest Object. The five-parameter version of the 'open' method allow you to specify the username and password.

EDITED

Keep in mind: this will make your password publicly accessible.

3 Comments

Most JS libraries also provide convenient ways to specify login information, in case the OP is already using one
But keep in mind that this makes the password publicly accessible.
I use HTTPS requests.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.