Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

basic authorization command for curl

How do I set up the basic authorization using 64 encoded credentials ? I tried below the two commands but of no use , please suggest.

curl -i -H 'Accept:application/json' Authorization:Basic <username:password> http://example.com curl -i -H 'Accept:application/json' Authorization:Basic.base64_encode(username:password) http://example.com   
like image 959
Amit Sharad Avatar asked Dec 27 '13 15:12

Amit Sharad


People also ask

How do you give Authorization in cURL command?

To send basic auth credentials with Curl, use the "-u login: password" command-line option. Curl automatically converts the login: password pair into a Base64-encoded string and adds the "Authorization: Basic [token]" header to the request.

How do you get auth tokens in cURL?

To generate an access token: Replace {AUTH CODE QUERY PARAMETER} with the auth code you copied from the previous step in the above cURL request. Replace {CLIENT ID} in the above request with the Client ID from your Oauth client. Replace {CLIENT SECRET} in the above request with the Client Secret from your Oauth client.

How do I pass basic auth credentials in URL?

We can do HTTP basic authentication URL with @ in password. We have to pass the credentials appended with the URL. The username and password must be added with the format − https://username:password@URL.


2 Answers

How do I set up the basic authorization?

All you need to do is use -u, --user USER[:PASSWORD]. Behind the scenes curl builds the Authorization header with base64 encoded credentials for you.

Example:

curl -u username:password -i -H 'Accept:application/json' http://example.com 
like image 140
deltheil Avatar answered Sep 17 '22 08:09

deltheil


Use the -H header again before the Authorization:Basic things. So it will be

curl -i \     -H 'Accept:application/json' \     -H 'Authorization:Basic BASE64_string' \     http://example.com 

Here, BASE64_string = Base64 of username:password

like image 38
Sabuj Hassan Avatar answered Sep 17 '22 08:09

Sabuj Hassan