Skip to content

Commit

Permalink
docs: Add requests.auth code sample
Browse files Browse the repository at this point in the history
  • Loading branch information
edgarrmondragon committed Feb 3, 2023
1 parent b20750e commit 8554e26
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions docs/code_samples.md
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,31 @@ class CachedAuthStream(RESTStream):
return APIAuthenticatorBase(stream=self)
```

### Use one of `requests`'s built-in authenticators

```python
from requests.auth import HTTPDigestAuth
from singer_sdk.streams import RESTStream

class DigestAuthStream(RESTStream):
"""A stream with digest authentication."""

@property
def authenticator(self) -> HTTPDigestAuth:
"""Stream authenticator."""
return HTTPDigestAuth(
username=self.config["username"],
password=self.config["password"],
)
```

`HTTPBasicAuth` and `HTTPProxyAuth` area also available in `requests.auth`. The community
has also published a few packages with custom authenticators. For example:

- [`requests-aws4auth`](https://github.com/meltano/sdk/issues/1105#:~:text=tedder/requests%2Daws4auth): AWS v4 authentication
- [`requests_auth`](https://github.com/Colin-b/requests_auth): A collection of authenticators
for various services and protocols including Azure, Okta and NTLM.

### Custom response validation

Some APIs deviate from HTTP status codes to report failures. For those cases,
Expand Down

0 comments on commit 8554e26

Please # to comment.