How to determine basic HTTP authentication using cURL?

I am learning Apigility (Apigility Document โ†’ REST Tutorial ) and trying to send a POST request with basic authentication via cURL:

$ curl -X POST -i -H "Content-Type: application/hal+json" -H "Authorization: Basic YXBpdXNlcjphcGlwd2Q=" http://apigilityhw.sandbox.loc/status 

YXBpdXNlcjphcGlwd2Q= is the basic encoded string with my apiuser:apipwd . Credentials are stored in /data/htpasswd ( apiuser:$apr1$3J4cyqEw$WKga3rQMkxvnevMuBaekg/ ).

It looks like this:

 HTTP/1.1 401 Unauthorized Server: nginx/1.4.7 Date: Mon, 22 Sep 2014 07:48:47 GMT Content-Type: application/problem+json Transfer-Encoding: chunked Connection: keep-alive X-Powered-By: PHP/5.5.12-1~dotdeb.1 WWW-Authenticate: Basic realm="api" 

Where is the mistake here? How to make it work?

+83
curl authorization basic-authentication apigility
Sep 22 '14 at 7:58
source share
3 answers
 curl -u username:password http:// curl -u username http:// 

On the documentation page:

-u, --user <user: password>

Specify a username and password for server authentication. Overrides -n, -netrc, and -netrc-optional.

If you just provide a username, curl will ask for a password.

The username and passwords are separated by the first colon, which makes it impossible to use a colon in the username with this option. Password may, still.

When using Kerberos V5 with a Windows-based server, you must include the Windows domain name in the username so that the server can successfully obtain a Kerberos ticket. If you do not, authentication may fail.

When using NTLM, the username can be specified simply as the user name, without a domain, if there is one domain and a forest, for example, your setting.

To specify a domain name, use either the top-level login or UPN (User Principal Name). For example, EXAMPLE \ user and user@example.com, respectively.

If you use a binary key with Windows SSPI support and run Kerberos V5, Negotiation, NTLM or Digest verification, then you can say that select a username and password from your environment by specifying one colon with this option: "-u:".

If this parameter is used several times, the latter will be used.

http://curl.haxx.se/docs/manpage.html#-u

Note that you do not need the --basic flag as it is the default.

+159
Dec 12 '14 at 11:03
source

When using OAuth or other authentication services, you can often also send an access token to the request string instead of the authorization header, so something like:

 GET https://www.example.com/v1/users/1?access_token=abcdefghijklmnopqrstuvwxyz1234567890ABCD 
+7
Oct 27 '14 at 8:45
source

as a title

 AUTH=$(echo -ne "$BASIC_AUTH_USER:$BASIC_AUTH_PASSWORD" | base64 --wrap 0) curl \ --header "Content-Type: application/json" \ --header "Authorization: Basic $AUTH" \ --request POST \ --data '{"key1":"value1", "key2":"value2"}' \ https://example.com/ 
0
Dec 05 '18 at 11:05
source



All Articles