mahaidery
mahaidery

Reputation: 611

Curl to prompt a User Name and Password

I have a password protect web folder on my site, I am fetching that folder on another domain using Curl, what I want is: when I try to open the URL it should ask me the user name and password, instead of asking it display the "Authorization Required".

Example:

If I try to access the "a" url it ask me for the user name password. Fine. but it doesn't ask me for the user name and password on "b" (using curl here).

Any Idea?

In Short: I want to make Curl ask for the User/Password prompt.

Regards

I am not sure, if it is possible or not? but if it's possible so please let me know how, otherwise I will close this as "Invalid"

Upvotes: 31

Views: 59243

Answers (5)

cottton
cottton

Reputation: 1607

Examples:

--user

curl -v --user myName:mySecret http://example.com/foo/bar

-u

curl -v -u myName:mySecret http://example.com/foo/bar

(example for Minh Nguyen see https://stackoverflow.com/a/26826658/3411766)

curl -v -su 'myName' http://example.com/foo/bar

asks for the pw of user 'myName'.

Upvotes: 7

user2906744
user2906744

Reputation: 19

-H 'Authorization: Basic user:pass' user:pass must be encoded in base64

Upvotes: 1

Minh Nguyen
Minh Nguyen

Reputation: 749

Try the following like :

curl -su 'user' <url>

It should prompt password for the user

Upvotes: 74

pizza
pizza

Reputation: 7620

for .htaccess style password protection, You can code the userid password as in:

curl -u userid:password http://.......

Upvotes: 1

Taha Paksu
Taha Paksu

Reputation: 15616

you can use cookies there I think. The steps would be:

  1. If you try to curl "http://www.2nddomain.com/admin" with no cookies, it can return you a html login form.
  2. Your form's action would point to 2nd server and if the credentials were right, set the cookie there and return (redirect) to server 1.
  3. And if you curl again, you'd check the cookie on the other side and in this case, it could read that cookie and return you the admin page output instead.

Upvotes: -1

Related Questions