Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cUrls's option "-u"

From cUrl docs:

-u, --user <user:password;options>  Specify the user name, password and optional login options to use for server authentication. Overrides -n, --netrc and --netrc-optional. 

What it gets translated to, meaning how do I catch it on the server to authenticate the user: are they in GET or in POST parameters?

The language is not important, the idea is important.

like image 680
Alan Coromano Avatar asked Dec 23 '13 04:12

Alan Coromano


People also ask

What is U option in curl request?

To send a Curl request with a Basic Server Authentication, you need to send an HTTP request to the server and provide user credentials using the -u or --- user command-line parameter. Curl has a built-in mechanism for sending basic authorization to the server.

What is U Postman?

The -u option in cURL performs Basic Authentication, where you can effectively "sign in" to an API by using a username and password. You can add Basic Authentication to your Postman request under Authentication > Basic Auth.

What is F in curl request?

-F tells curl to emulate a filled in HTML Form that has just had it's submit button clicked.

What is curl M?

DESCRIPTION. curl is a tool to transfer data from or to a server, using one of the supported protocols (HTTP, HTTPS, FTP, FTPS, GOPHER, DICT, TELNET, LDAP or FILE). The command is designed to work without user interaction.


1 Answers

It all depends on the authentication method but for the most common ones - Basic Auth and Digest Auth, this works with ad hoc HTTP headers. Here's an example with Basic Auth:

curl -u john:pwd http://foo.com/misc 

This performs a GET request with the corresponding header:

GET /misc HTTP/1.1 Authorization: Basic am9objpwd2Q= User-Agent: curl/7.33.0 Host: foo.com Accept: */* 

The Authorization header contains the authentication data the server is supposed to parse, base64 decode[1] and use. The same header would be set with a POST request. You can easily test it out with a service like httpbin(1) (see /basic-auth/:user/:passwd endpoint).

Digest auth is a bit more complex but works with HTTP headers too:

  • the client first send its request, the server replies with a 401 Unauthorized including a WWW-Authenticate header with a challenge to solve,
  • the client solves the challenge and send another request with the response included into a Authorization header which has to be parsed and validated on the server-side.

[1]: base64("john:pwd") -> am9objpwd2Q=

like image 148
deltheil Avatar answered Sep 28 '22 09:09

deltheil