CURLOPT_HTTPAUTH.3 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. .\" generated by cd2nroff 0.1 from CURLOPT_HTTPAUTH.md
  2. .TH CURLOPT_HTTPAUTH 3 "2025-01-17" libcurl
  3. .SH NAME
  4. CURLOPT_HTTPAUTH \- HTTP server authentication methods to try
  5. .SH SYNOPSIS
  6. .nf
  7. #include <curl/curl.h>
  8. CURLcode curl_easy_setopt(CURL *handle, CURLOPT_HTTPAUTH, long bitmask);
  9. .fi
  10. .SH DESCRIPTION
  11. Pass a long as parameter, which is set to a bitmask, to tell libcurl which
  12. authentication method(s) you want it to use speaking to the remote server.
  13. The available bits are listed below. If more than one bit is set, libcurl
  14. first queries the host to see which authentication methods it supports and
  15. then picks the best one you allow it to use. For some methods, this induces an
  16. extra network round\-trip. Set the actual name and password with the
  17. \fICURLOPT_USERPWD(3)\fP option or with the \fICURLOPT_USERNAME(3)\fP and the
  18. \fICURLOPT_PASSWORD(3)\fP options.
  19. For authentication with a proxy, see \fICURLOPT_PROXYAUTH(3)\fP.
  20. .IP CURLAUTH_BASIC
  21. HTTP Basic authentication. This is the default choice, and the only method
  22. that is in wide\-spread use and supported virtually everywhere. This sends
  23. the username and password over the network in plain text, easily captured by
  24. others.
  25. .IP CURLAUTH_DIGEST
  26. HTTP Digest authentication. Digest authentication is defined in RFC 2617 and
  27. is a more secure way to do authentication over public networks than the
  28. regular old\-fashioned Basic method.
  29. .IP CURLAUTH_DIGEST_IE
  30. HTTP Digest authentication with an IE flavor. Digest authentication is defined
  31. in RFC 2617 and is a more secure way to do authentication over public networks
  32. than the regular old\-fashioned Basic method. The IE flavor is simply that
  33. libcurl uses a special "quirk" that IE is known to have used before version 7
  34. and that some servers require the client to use.
  35. .IP CURLAUTH_BEARER
  36. HTTP Bearer token authentication, used primarily in OAuth 2.0 protocol.
  37. You can set the Bearer token to use with \fICURLOPT_XOAUTH2_BEARER(3)\fP.
  38. .IP CURLAUTH_NEGOTIATE
  39. HTTP Negotiate (SPNEGO) authentication. Negotiate authentication is defined
  40. in RFC 4559 and is the most secure way to perform authentication over HTTP.
  41. You need to build libcurl with a suitable GSS\-API library or SSPI on Windows
  42. for this to work.
  43. .IP CURLAUTH_NTLM
  44. HTTP NTLM authentication. A proprietary protocol invented and used by
  45. Microsoft. It uses a challenge\-response and hash concept similar to Digest, to
  46. prevent the password from being eavesdropped.
  47. You need to build libcurl with either OpenSSL or GnuTLS support for this
  48. option to work, or build libcurl on Windows with SSPI support.
  49. .IP CURLAUTH_NTLM_WB
  50. Support for this is removed since libcurl 8.8.0.
  51. NTLM delegating to winbind helper. Authentication is performed by a separate
  52. binary application that is executed when needed. The name of the application
  53. is specified at compile time but is typically \fB/usr/bin/ntlm_auth\fP.
  54. Note that libcurl forks when necessary to run the winbind application and kill
  55. it when complete, calling \fBwaitpid()\fP to await its exit when done. On POSIX
  56. operating systems, killing the process causes a SIGCHLD signal to be raised
  57. (regardless of whether \fICURLOPT_NOSIGNAL(3)\fP is set), which must be handled
  58. intelligently by the application. In particular, the application must not
  59. unconditionally call wait() in its SIGCHLD signal handler to avoid being
  60. subject to a race condition. This behavior is subject to change in future
  61. versions of libcurl.
  62. .IP CURLAUTH_ANY
  63. This is a convenience macro that sets all bits and thus makes libcurl pick any
  64. it finds suitable. libcurl automatically selects the one it finds most secure.
  65. .IP CURLAUTH_ANYSAFE
  66. This is a convenience macro that sets all bits except Basic and thus makes
  67. libcurl pick any it finds suitable. libcurl automatically selects the one it
  68. finds most secure.
  69. .IP CURLAUTH_ONLY
  70. This is a meta symbol. OR this value together with a single specific auth
  71. value to force libcurl to probe for unrestricted auth and if not, only that
  72. single auth algorithm is acceptable.
  73. .IP CURLAUTH_AWS_SIGV4
  74. provides AWS V4 signature authentication on HTTPS header
  75. see \fICURLOPT_AWS_SIGV4(3)\fP.
  76. .SH DEFAULT
  77. CURLAUTH_BASIC
  78. .SH PROTOCOLS
  79. This functionality affects http only
  80. .SH EXAMPLE
  81. .nf
  82. int main(void)
  83. {
  84. CURL *curl = curl_easy_init();
  85. if(curl) {
  86. CURLcode ret;
  87. curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
  88. /* allow whatever auth the server speaks */
  89. curl_easy_setopt(curl, CURLOPT_HTTPAUTH, (long)CURLAUTH_ANY);
  90. curl_easy_setopt(curl, CURLOPT_USERPWD, "james:bond");
  91. ret = curl_easy_perform(curl);
  92. }
  93. }
  94. .fi
  95. .SH HISTORY
  96. CURLAUTH_DIGEST_IE was added in 7.19.3
  97. CURLAUTH_ONLY was added in 7.21.3
  98. CURLAUTH_NTLM_WB was added in 7.22.0
  99. CURLAUTH_BEARER was added in 7.61.0
  100. CURLAUTH_AWS_SIGV4 was added in 7.74.0
  101. .SH AVAILABILITY
  102. Added in curl 7.10.6
  103. .SH RETURN VALUE
  104. Returns CURLE_OK if the option is supported, CURLE_UNKNOWN_OPTION if not, or
  105. CURLE_NOT_BUILT_IN if the bitmask specified no supported authentication
  106. methods.
  107. .SH SEE ALSO
  108. .BR CURLOPT_PASSWORD (3),
  109. .BR CURLOPT_PROXYAUTH (3),
  110. .BR CURLOPT_USERNAME (3)