     [Answers](https://scrapfly.io/blog)   /  [curl](https://scrapfly.io/blog/tag/curl)   /  [How to Set cURL Authentication - Full Examples Guide](https://scrapfly.io/blog/answers/how-to-set-authorization-with-curl-full-examples-guide)   # How to Set cURL Authentication - Full Examples Guide

 by [Mazen Ramadan](https://scrapfly.io/blog/author/mazen) Apr 18, 2026 3 min read [\#curl](https://scrapfly.io/blog/tag/curl) 

 [  ](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fscrapfly.io%2Fblog%2Fanswers%2Fhow-to-set-authorization-with-curl-full-examples-guide "Share on LinkedIn")    

 

 

cURl is a viable tool for requesting and transferring data from web pages. However, an obstacle is often encountered: authentication. In this guide, we'll explain how to set cURL authorization for different types:

- Basic authentication.
- Bearer token based authentication.
- Cookies authentication.

Let's get started!



## Basic Authentication With cURL

The basic auth credentials method is one of the oldest methods for managing HTTP authentication. It requires entering basic credentials data, username and password:



Basic auth exampleAuthentication in the above image can be found at `https://httpbin.dev/basic-auth/user/passwd` . It requires entering the auth credentials before the request can proceed to the data.

To set basic authentication with cURL, we can use the `--user` or `-u` cURL options followed by the `--basic` option to mark it as basic auth:

shell```shell
curl --user user:passwd --basic https://httpbin.dev/basic-auth/user/passwd
```



The above cURL command will enter the credentials data (`user` and `passwd`) to authorize the HTTP request. Here is the response of the above cURL command:

json```json
{
  "authorized": true,
  "user": "user"
}
```





## Bearer Tokens With cURL

Bearer tokens are popular authentication methods for modern applications. They are tokens generated after the credentials are entered for the first time and used to pass authorization [How Headers Are Used to Block Web Scrapers and How to Fix It](https://scrapfly.io/blog/posts/how-to-avoid-web-scraping-blocking-headers) for the requests to authenticate them.

If we go over the previous authentication endpoint on the browser and refresh the page, we'll find the authorization header used with the HTTP request headers:



Authorization token on browser developer toolsTo set cURL Bearer authentication with cURL, we'll add the above `Authorization` header to the cURL command using the `-H` option:

To set Bearer authentication with cURL, we'll add the above `Authorization` header to cURL commands using the `-H` option:

shell```shell
curl -H "Authorization: Basic dXNlcjpwYXNzd2Q=" https://httpbin.dev/basic-auth/user/passwd
```



From the response, we can see that the cURL request was successfully authenticated:

json```json
{
  "authorized": true,
  "user": "user"
}
```





Scrapfly

#### Scale your web scraping effortlessly

Scrapfly handles proxies, browsers, and anti-bot bypass — so you can focus on data.

[Try Free →](https://scrapfly.io/register)## Authentication Cookies With cURL

Another popular authentication method is using [How to Handle Cookies in Web Scraping](https://scrapfly.io/blog/posts/how-to-handle-cookies-in-web-scraping), which function similarly to bearer tokens. After the credentials are validated successfully, a cookie value is created and saved to authorize future requests.

For this example, we'll use the login page on [web-scraping.dev](https://web-scraping.dev/login):



Login page on web-scraping.devThe above page uses a login form for authentication. If we take a look at the cookies for this domain, we'll find a cookie value for authentication:



To handle cookie authentication with cURL, we'll pass this cookie value to the cURL command in either two ways:

- Adding it **as a cookie** value using the `-b` cURL option.
- Adding the cookie value **as a header** using the `-H` cURL option.

shell```shell
curl -b "auth=user123-secret-token" https://web-scraping.dev/login
# or
curl -H "cookie: auth=user123-secret-token" https://web-scraping.dev/login
```



From the response, we can see that the cURL command was authenticated successfully:

html```html
  <div class="container text-center">
    <div class="form-text mb-2">Logged in as User123</div>
    <div class="form-text mb-2">The secret message is:<div id="secret-message" class="fw-bold">🤫</div>
    </div>
    <a href="/api/logout"><button type="submit" class="btn btn-primary"> Logout </button> </a>
  </div>
```





For further details on cURL, including configuring its commands and using it for web scraping, refer to our dedicated guide.

[How to Use cURL For Web ScrapingIn this article, we'll go over a step-by-step guide on sending and configuring HTTP requests with cURL. We'll also explore advanced usages of cURL for web scraping, such as scraping dynamic pages and avoiding getting blocked.](https://scrapfly.io/blog/posts/how-to-use-curl-for-web-scraping)



 

    Table of Contents- [Basic Authentication With cURL](#basic-authentication-with-curl)
- [Bearer Tokens With cURL](#bearer-tokens-with-curl)
- [Authentication Cookies With cURL](#authentication-cookies-with-curl)
 
    Join the Newsletter  Get monthly web scraping insights 

 

  



Scale Your Web Scraping

Anti-bot bypass, browser rendering, and rotating proxies, all in one API. Start with 1,000 free credits.

  No credit card required  1,000 free API credits  Anti-bot bypass included 

 [Start Free](https://scrapfly.io/register) [View Docs](https://scrapfly.io/docs/onboarding) 

 Not ready? Get our newsletter instead. 

 

## Explore this Article with AI

 [ ChatGPT ](https://chat.openai.com/?q=Summarize%20this%20page%3A%20https%3A%2F%2Fscrapfly.io%2Fblog%2Fanswers%2Fhow-to-set-authorization-with-curl-full-examples-guide) [ Gemini ](https://www.google.com/search?udm=50&aep=11&q=Summarize%20this%20page%3A%20https%3A%2F%2Fscrapfly.io%2Fblog%2Fanswers%2Fhow-to-set-authorization-with-curl-full-examples-guide) [ Grok ](https://x.com/i/grok?text=Summarize%20this%20page%3A%20https%3A%2F%2Fscrapfly.io%2Fblog%2Fanswers%2Fhow-to-set-authorization-with-curl-full-examples-guide) [ Perplexity ](https://www.perplexity.ai/search/new?q=Summarize%20this%20page%3A%20https%3A%2F%2Fscrapfly.io%2Fblog%2Fanswers%2Fhow-to-set-authorization-with-curl-full-examples-guide) [ Claude ](https://claude.ai/new?q=Summarize%20this%20page%3A%20https%3A%2F%2Fscrapfly.io%2Fblog%2Fanswers%2Fhow-to-set-authorization-with-curl-full-examples-guide) 



 ## Related Articles

 [  

 curl 

### How to Use cURL GET Requests

Here's everything you need to know about cURL GET requests and some common pitfalls you should avoid.

 

 ](https://scrapfly.io/blog/posts/how-to-use-curl-get-requests) [  

 http tools 

### How to Use cURL For Web Scraping

In this article, we'll go over a step-by-step guide on sending and configuring HTTP requests with cURL. We'll also explo...

 

 ](https://scrapfly.io/blog/posts/how-to-use-curl-for-web-scraping) [  

 http curl 

### How to Ignore cURL SSL Errors

Learn to handle SSL errors in cURL, including using self-signed certificates. Explore common issues, safe practices.

 

 ](https://scrapfly.io/blog/posts/guide-to-curl-ignore-ssl-errors) 

  ## Related Questions

- [ Q How to click on cookie popups and modal alerts in Puppeteer? ](https://scrapfly.io/blog/answers/how-to-click-on-modal-alerts-like-cookie-pop-up-in-puppeteer)
- [ Q How to Set User Agent With cURL? ](https://scrapfly.io/blog/answers/how-to-set-curl-user-agent)
- [ Q How to click on cookie popups and modal alerts in Playwright? ](https://scrapfly.io/blog/answers/how-to-click-on-modal-alerts-like-cookie-pop-up-in-playwright)
- [ Q How to click on cookie popups and modal alerts in Selenium? ](https://scrapfly.io/blog/answers/how-to-click-on-modal-alerts-like-cookie-pop-up-in-selenium)
 
  



   



 Scale your web scraping effortlessly, **1,000 free credits** [Start Free](https://scrapfly.io/register)