xref: /aosp_15_r20/external/curl/docs/libcurl/opts/CURLOPT_HTTPAUTH.md (revision 6236dae45794135f37c4eb022389c904c8b0090d)
1*6236dae4SAndroid Build Coastguard Worker---
2*6236dae4SAndroid Build Coastguard Workerc: Copyright (C) Daniel Stenberg, <[email protected]>, et al.
3*6236dae4SAndroid Build Coastguard WorkerSPDX-License-Identifier: curl
4*6236dae4SAndroid Build Coastguard WorkerTitle: CURLOPT_HTTPAUTH
5*6236dae4SAndroid Build Coastguard WorkerSection: 3
6*6236dae4SAndroid Build Coastguard WorkerSource: libcurl
7*6236dae4SAndroid Build Coastguard WorkerProtocol:
8*6236dae4SAndroid Build Coastguard Worker  - HTTP
9*6236dae4SAndroid Build Coastguard WorkerSee-also:
10*6236dae4SAndroid Build Coastguard Worker  - CURLOPT_PASSWORD (3)
11*6236dae4SAndroid Build Coastguard Worker  - CURLOPT_PROXYAUTH (3)
12*6236dae4SAndroid Build Coastguard Worker  - CURLOPT_USERNAME (3)
13*6236dae4SAndroid Build Coastguard WorkerAdded-in: 7.10.6
14*6236dae4SAndroid Build Coastguard Worker---
15*6236dae4SAndroid Build Coastguard Worker
16*6236dae4SAndroid Build Coastguard Worker# NAME
17*6236dae4SAndroid Build Coastguard Worker
18*6236dae4SAndroid Build Coastguard WorkerCURLOPT_HTTPAUTH - HTTP server authentication methods to try
19*6236dae4SAndroid Build Coastguard Worker
20*6236dae4SAndroid Build Coastguard Worker# SYNOPSIS
21*6236dae4SAndroid Build Coastguard Worker
22*6236dae4SAndroid Build Coastguard Worker~~~c
23*6236dae4SAndroid Build Coastguard Worker#include <curl/curl.h>
24*6236dae4SAndroid Build Coastguard Worker
25*6236dae4SAndroid Build Coastguard WorkerCURLcode curl_easy_setopt(CURL *handle, CURLOPT_HTTPAUTH, long bitmask);
26*6236dae4SAndroid Build Coastguard Worker~~~
27*6236dae4SAndroid Build Coastguard Worker
28*6236dae4SAndroid Build Coastguard Worker# DESCRIPTION
29*6236dae4SAndroid Build Coastguard Worker
30*6236dae4SAndroid Build Coastguard WorkerPass a long as parameter, which is set to a bitmask, to tell libcurl which
31*6236dae4SAndroid Build Coastguard Workerauthentication method(s) you want it to use speaking to the remote server.
32*6236dae4SAndroid Build Coastguard Worker
33*6236dae4SAndroid Build Coastguard WorkerThe available bits are listed below. If more than one bit is set, libcurl
34*6236dae4SAndroid Build Coastguard Workerfirst queries the host to see which authentication methods it supports and
35*6236dae4SAndroid Build Coastguard Workerthen picks the best one you allow it to use. For some methods, this induces an
36*6236dae4SAndroid Build Coastguard Workerextra network round-trip. Set the actual name and password with the
37*6236dae4SAndroid Build Coastguard WorkerCURLOPT_USERPWD(3) option or with the CURLOPT_USERNAME(3) and the
38*6236dae4SAndroid Build Coastguard WorkerCURLOPT_PASSWORD(3) options.
39*6236dae4SAndroid Build Coastguard Worker
40*6236dae4SAndroid Build Coastguard WorkerFor authentication with a proxy, see CURLOPT_PROXYAUTH(3).
41*6236dae4SAndroid Build Coastguard Worker
42*6236dae4SAndroid Build Coastguard Worker## CURLAUTH_BASIC
43*6236dae4SAndroid Build Coastguard Worker
44*6236dae4SAndroid Build Coastguard WorkerHTTP Basic authentication. This is the default choice, and the only method
45*6236dae4SAndroid Build Coastguard Workerthat is in wide-spread use and supported virtually everywhere. This sends
46*6236dae4SAndroid Build Coastguard Workerthe username and password over the network in plain text, easily captured by
47*6236dae4SAndroid Build Coastguard Workerothers.
48*6236dae4SAndroid Build Coastguard Worker
49*6236dae4SAndroid Build Coastguard Worker## CURLAUTH_DIGEST
50*6236dae4SAndroid Build Coastguard Worker
51*6236dae4SAndroid Build Coastguard WorkerHTTP Digest authentication. Digest authentication is defined in RFC 2617 and
52*6236dae4SAndroid Build Coastguard Workeris a more secure way to do authentication over public networks than the
53*6236dae4SAndroid Build Coastguard Workerregular old-fashioned Basic method.
54*6236dae4SAndroid Build Coastguard Worker
55*6236dae4SAndroid Build Coastguard Worker## CURLAUTH_DIGEST_IE
56*6236dae4SAndroid Build Coastguard Worker
57*6236dae4SAndroid Build Coastguard WorkerHTTP Digest authentication with an IE flavor. Digest authentication is defined
58*6236dae4SAndroid Build Coastguard Workerin RFC 2617 and is a more secure way to do authentication over public networks
59*6236dae4SAndroid Build Coastguard Workerthan the regular old-fashioned Basic method. The IE flavor is simply that
60*6236dae4SAndroid Build Coastguard Workerlibcurl uses a special "quirk" that IE is known to have used before version 7
61*6236dae4SAndroid Build Coastguard Workerand that some servers require the client to use.
62*6236dae4SAndroid Build Coastguard Worker
63*6236dae4SAndroid Build Coastguard Worker## CURLAUTH_BEARER
64*6236dae4SAndroid Build Coastguard Worker
65*6236dae4SAndroid Build Coastguard WorkerHTTP Bearer token authentication, used primarily in OAuth 2.0 protocol.
66*6236dae4SAndroid Build Coastguard Worker
67*6236dae4SAndroid Build Coastguard WorkerYou can set the Bearer token to use with CURLOPT_XOAUTH2_BEARER(3).
68*6236dae4SAndroid Build Coastguard Worker
69*6236dae4SAndroid Build Coastguard Worker## CURLAUTH_NEGOTIATE
70*6236dae4SAndroid Build Coastguard Worker
71*6236dae4SAndroid Build Coastguard WorkerHTTP Negotiate (SPNEGO) authentication. Negotiate authentication is defined
72*6236dae4SAndroid Build Coastguard Workerin RFC 4559 and is the most secure way to perform authentication over HTTP.
73*6236dae4SAndroid Build Coastguard Worker
74*6236dae4SAndroid Build Coastguard WorkerYou need to build libcurl with a suitable GSS-API library or SSPI on Windows
75*6236dae4SAndroid Build Coastguard Workerfor this to work.
76*6236dae4SAndroid Build Coastguard Worker
77*6236dae4SAndroid Build Coastguard Worker## CURLAUTH_NTLM
78*6236dae4SAndroid Build Coastguard Worker
79*6236dae4SAndroid Build Coastguard WorkerHTTP NTLM authentication. A proprietary protocol invented and used by
80*6236dae4SAndroid Build Coastguard WorkerMicrosoft. It uses a challenge-response and hash concept similar to Digest, to
81*6236dae4SAndroid Build Coastguard Workerprevent the password from being eavesdropped.
82*6236dae4SAndroid Build Coastguard Worker
83*6236dae4SAndroid Build Coastguard WorkerYou need to build libcurl with either OpenSSL or GnuTLS support for this
84*6236dae4SAndroid Build Coastguard Workeroption to work, or build libcurl on Windows with SSPI support.
85*6236dae4SAndroid Build Coastguard Worker
86*6236dae4SAndroid Build Coastguard Worker## CURLAUTH_NTLM_WB
87*6236dae4SAndroid Build Coastguard Worker
88*6236dae4SAndroid Build Coastguard WorkerSupport for this is removed since libcurl 8.8.0.
89*6236dae4SAndroid Build Coastguard Worker
90*6236dae4SAndroid Build Coastguard WorkerNTLM delegating to winbind helper. Authentication is performed by a separate
91*6236dae4SAndroid Build Coastguard Workerbinary application that is executed when needed. The name of the application
92*6236dae4SAndroid Build Coastguard Workeris specified at compile time but is typically **/usr/bin/ntlm_auth**.
93*6236dae4SAndroid Build Coastguard Worker
94*6236dae4SAndroid Build Coastguard WorkerNote that libcurl forks when necessary to run the winbind application and kill
95*6236dae4SAndroid Build Coastguard Workerit when complete, calling **waitpid()** to await its exit when done. On POSIX
96*6236dae4SAndroid Build Coastguard Workeroperating systems, killing the process causes a SIGCHLD signal to be raised
97*6236dae4SAndroid Build Coastguard Worker(regardless of whether CURLOPT_NOSIGNAL(3) is set), which must be handled
98*6236dae4SAndroid Build Coastguard Workerintelligently by the application. In particular, the application must not
99*6236dae4SAndroid Build Coastguard Workerunconditionally call wait() in its SIGCHLD signal handler to avoid being
100*6236dae4SAndroid Build Coastguard Workersubject to a race condition. This behavior is subject to change in future
101*6236dae4SAndroid Build Coastguard Workerversions of libcurl.
102*6236dae4SAndroid Build Coastguard Worker
103*6236dae4SAndroid Build Coastguard Worker## CURLAUTH_ANY
104*6236dae4SAndroid Build Coastguard Worker
105*6236dae4SAndroid Build Coastguard WorkerThis is a convenience macro that sets all bits and thus makes libcurl pick any
106*6236dae4SAndroid Build Coastguard Workerit finds suitable. libcurl automatically selects the one it finds most secure.
107*6236dae4SAndroid Build Coastguard Worker
108*6236dae4SAndroid Build Coastguard Worker## CURLAUTH_ANYSAFE
109*6236dae4SAndroid Build Coastguard Worker
110*6236dae4SAndroid Build Coastguard WorkerThis is a convenience macro that sets all bits except Basic and thus makes
111*6236dae4SAndroid Build Coastguard Workerlibcurl pick any it finds suitable. libcurl automatically selects the one it
112*6236dae4SAndroid Build Coastguard Workerfinds most secure.
113*6236dae4SAndroid Build Coastguard Worker
114*6236dae4SAndroid Build Coastguard Worker## CURLAUTH_ONLY
115*6236dae4SAndroid Build Coastguard Worker
116*6236dae4SAndroid Build Coastguard WorkerThis is a meta symbol. OR this value together with a single specific auth
117*6236dae4SAndroid Build Coastguard Workervalue to force libcurl to probe for unrestricted auth and if not, only that
118*6236dae4SAndroid Build Coastguard Workersingle auth algorithm is acceptable.
119*6236dae4SAndroid Build Coastguard Worker
120*6236dae4SAndroid Build Coastguard Worker## CURLAUTH_AWS_SIGV4
121*6236dae4SAndroid Build Coastguard Worker
122*6236dae4SAndroid Build Coastguard Workerprovides AWS V4 signature authentication on HTTPS header
123*6236dae4SAndroid Build Coastguard Workersee CURLOPT_AWS_SIGV4(3).
124*6236dae4SAndroid Build Coastguard Worker
125*6236dae4SAndroid Build Coastguard Worker# DEFAULT
126*6236dae4SAndroid Build Coastguard Worker
127*6236dae4SAndroid Build Coastguard WorkerCURLAUTH_BASIC
128*6236dae4SAndroid Build Coastguard Worker
129*6236dae4SAndroid Build Coastguard Worker# %PROTOCOLS%
130*6236dae4SAndroid Build Coastguard Worker
131*6236dae4SAndroid Build Coastguard Worker# EXAMPLE
132*6236dae4SAndroid Build Coastguard Worker
133*6236dae4SAndroid Build Coastguard Worker~~~c
134*6236dae4SAndroid Build Coastguard Workerint main(void)
135*6236dae4SAndroid Build Coastguard Worker{
136*6236dae4SAndroid Build Coastguard Worker  CURL *curl = curl_easy_init();
137*6236dae4SAndroid Build Coastguard Worker  if(curl) {
138*6236dae4SAndroid Build Coastguard Worker    CURLcode ret;
139*6236dae4SAndroid Build Coastguard Worker    curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
140*6236dae4SAndroid Build Coastguard Worker    /* allow whatever auth the server speaks */
141*6236dae4SAndroid Build Coastguard Worker    curl_easy_setopt(curl, CURLOPT_HTTPAUTH, (long)CURLAUTH_ANY);
142*6236dae4SAndroid Build Coastguard Worker    curl_easy_setopt(curl, CURLOPT_USERPWD, "james:bond");
143*6236dae4SAndroid Build Coastguard Worker    ret = curl_easy_perform(curl);
144*6236dae4SAndroid Build Coastguard Worker  }
145*6236dae4SAndroid Build Coastguard Worker}
146*6236dae4SAndroid Build Coastguard Worker~~~
147*6236dae4SAndroid Build Coastguard Worker
148*6236dae4SAndroid Build Coastguard Worker# HISTORY
149*6236dae4SAndroid Build Coastguard Worker
150*6236dae4SAndroid Build Coastguard WorkerCURLAUTH_DIGEST_IE was added in 7.19.3
151*6236dae4SAndroid Build Coastguard Worker
152*6236dae4SAndroid Build Coastguard WorkerCURLAUTH_ONLY was added in 7.21.3
153*6236dae4SAndroid Build Coastguard Worker
154*6236dae4SAndroid Build Coastguard WorkerCURLAUTH_NTLM_WB was added in 7.22.0
155*6236dae4SAndroid Build Coastguard Worker
156*6236dae4SAndroid Build Coastguard WorkerCURLAUTH_BEARER was added in 7.61.0
157*6236dae4SAndroid Build Coastguard Worker
158*6236dae4SAndroid Build Coastguard WorkerCURLAUTH_AWS_SIGV4 was added in 7.74.0
159*6236dae4SAndroid Build Coastguard Worker
160*6236dae4SAndroid Build Coastguard Worker# %AVAILABILITY%
161*6236dae4SAndroid Build Coastguard Worker
162*6236dae4SAndroid Build Coastguard Worker# RETURN VALUE
163*6236dae4SAndroid Build Coastguard Worker
164*6236dae4SAndroid Build Coastguard WorkerReturns CURLE_OK if the option is supported, CURLE_UNKNOWN_OPTION if not, or
165*6236dae4SAndroid Build Coastguard WorkerCURLE_NOT_BUILT_IN if the bitmask specified no supported authentication
166*6236dae4SAndroid Build Coastguard Workermethods.
167