Skip to content

Commit

Permalink
demonstrate basic http authentication (#605)
Browse files Browse the repository at this point in the history
  • Loading branch information
KappaDistributive authored Jan 7, 2021
1 parent 1b9a276 commit 752b035
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,4 @@
- [Making Requests](web/clients/requests.md)
- [Calling a Web API](web/clients/apis.md)
- [Downloads](web/clients/download.md)
- [Web Authentication](web/clients/authentication.md)
8 changes: 8 additions & 0 deletions src/web.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@
| [Make a partial download with HTTP range headers][ex-progress-with-range] | [![reqwest-badge]][reqwest] | [![cat-net-badge]][cat-net] |
| [POST a file to paste-rs][ex-file-post] | [![reqwest-badge]][reqwest] | [![cat-net-badge]][cat-net] |

## Web Authentication

| Recipe | Crates | Categories |
|--------|--------|------------|
| [Basic Authentication][ex-basic-authentication] | [![reqwest-badge]][reqwest] | [![cat-net-badge]][cat-net] |

[ex-extract-links-webpage]: web/scraping.html#extract-all-links-from-a-webpage-html
[ex-check-broken-links]: web/scraping.html#check-a-webpage-for-broken-links
[ex-extract-mediawiki-links]: web/scraping.html#extract-all-unique-links-from-a-mediawiki-markup
Expand All @@ -64,4 +70,6 @@
[ex-progress-with-range]: web/clients/download.html#make-a-partial-download-with-http-range-headers
[ex-file-post]: web/clients/download.html#post-a-file-to-paste-rs

[ex-basic-authentication]: web/clients/authentication.html#basic-authentication

{{#include links.md}}
5 changes: 5 additions & 0 deletions src/web/clients/authentication.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Authentication

{{#include authentication/basic.md}}

{{#include ../../links.md}}
28 changes: 28 additions & 0 deletions src/web/clients/authentication/basic.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
## Basic Authentication

[![reqwest-badge]][reqwest] [![cat-net-badge]][cat-net]

Uses [`reqwest::RequestBuilder::basic_auth`] to perform a basic HTTP authentication.

```rust,edition2018,no_run
use reqwest::blocking::Client;
use reqwest::Error;
fn main() -> Result<(), Error> {
let client = Client::new();
let user_name = "testuser".to_string();
let password: Option<String> = None;
let response = client
.get("https://httpbin.org/")
.basic_auth(user_name, password)
.send();
println!("{:?}", response);
Ok(())
}
```

[`reqwest::RequestBuilder::basic_auth`]: https://docs.rs/reqwest/*/reqwest/struct.RequestBuilder.html#method.basic_auth

0 comments on commit 752b035

Please sign in to comment.