150

I believe this is not possible, but someone I know insisted that it works. I don't even know what parameters to try, and I haven't found this documented anywhere.

I tried http://myserver.com/~user=username&password=mypassword but it doesn't work.

Can you confirm that it's not in fact possible to pass the user/pass via HTTP parameters (GET or POST)?

197

It is indeed not possible to pass the username and password via query parameters in standard HTTP auth. Instead, you use a special URL format, like this: http://username:password@example.com/ -- this sends the credentials in the standard HTTP "Authorization" header.

It's possible that whoever you were speaking to was thinking of a custom module or code that looked at the query parameters and verified the credentials. This isn't standard HTTP auth, though, it's an application-specific thing.

  • 1
    Thanks, this is just what I was looking for ... it's not critical that it's GET parameters, just that I can craft it into the URL. – ripper234 Mar 21 '12 at 12:48
  • 41
    FYI, the http://username:password@example.com format is no longer supported by either IE or Chrome, wouldn't be surprised if others followed suit if they haven't already. – T.J. Crowder Jun 20 '14 at 10:31
  • 11
    Actually works fine in Chrome. Only IE is being a spoiled brat. – Damien Overeem ツ Aug 18 '14 at 13:12
  • 1
    @DamienOvereem what version of chrome you on? i'm on mac os x 37 and it does not seem to work for me – Chris DaMour Aug 27 '14 at 16:23
  • 11
    I have since learned that Chrome had it disabled for a time, but re-enabled this feature later. I've also learned that Safari will throw phishing errors when running into these types of links.. Basically the time of url-based http authentication is over.. – Damien Overeem ツ Aug 28 '14 at 9:20
18

Passing Basic authentication parameters in URL not recommended

There is an Authorization header field for this purpose check it here: http header list

How to use it is written here: Basic access authentication

There you can also read that although it is still supported by some browsers the suggested solution of adding the Basic authorization credentials in the url is not recommended.

Read also chapter 4.1 in RFC 2617 - HTTP Authentication for more details on why NOT to use Basic Authentication.


Passing authentication parameters in query string

When using OAuth or other authentication services you can often also send your access token in a query string instead of in an authorization header, so something like:

GET https://www.example.com/api/v1/users/1?access_token=1234567890abcdefghijklmnopqrstuvwxyzABCD
  • And how does one go about encoding an Authorization header into a URL? – womble Jan 10 '14 at 10:09
  • 2
    Isn't that the form you stated was now deprecated? – womble Jan 14 '14 at 4:37
  • 2
    The question you answered with "There is an Authorization header field for this purpose" was asking how to put authentication parameters into the URL. If you can't encode HTTP header fields into a URL (which you can't), your answer is a non sequitur. – womble Jan 15 '14 at 22:17
  • Can you cite where in the URI standard says that passing basic authentication parameters in URI is deprecated? RFC 2396 only says that it is "NOT RECOMMENDED" because authentication details in plain text is, in many circumstances, not a good idea (of which I agree), while RFC 7235 mentions nothing. Nowhere in the specs I can search says that it's deprecated. – Lie Ryan Jul 1 '15 at 13:21
  • 1
    @Wilt: I have to apologise, you are indeed correct. Your hint that the spec was "altered" instigated me to investigate further (an RFC is never modified once it's published/numbered). I just found that RFC 2396 has actually been superseded by RFC 3986, which I wasn't able to find earlier. RFC 3986 does mention the deprecation of username:password syntax: Use of the format "user:password" in the userinfo field is deprecated. – Lie Ryan Jul 1 '15 at 14:19
17

http://username:password@example.com will works for FireFox, Chrome, Safari BUT not for IE.

Microsoft Knowledge Base

  • 1
    This capability was removed from Chrome 19+. See code.google.com/p/chromium/issues/detail?id=123150 – Moshe Katz Oct 31 '13 at 21:07
  • 4
    By my reading of that bug report, it got added back into Chrome 20. Certainly, I'd expect to see a lot of continued complaining about it if it hadn't been. – womble Jan 10 '14 at 10:08
  • I now requested it for Internet Explorer: connect.microsoft.com/IE/feedback/details/873575/…. Slightly different use-case, but addresses the same issue ;) – SimonSimCity May 16 '14 at 13:03
  • @Diago if password contains '@' then it doesn't work. it gives fatal error, can anyone tell me how we can give username & password at once – Ashish Jain Mar 4 '15 at 7:50
  • @AshishJain -- I would try escaping the @ in the password as %40. (I don't know if that works, though, and it might depend on the server or browser/server combination.) – David Moles Apr 14 '15 at 0:00
0

It is (obviously) possible to send any string in the GET parameters, although not recommended to send login and password as can make it highly visible, especially if it's not in an AJAX request.

You will however, need to then code the server page to extract the login and password and then validate and use them in whatever way is required.

protected by Community Mar 28 at 7:15

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.