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 c6caacc
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions docs/code_samples.md
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,34 @@ 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`](https://requests.readthedocs.io/en/latest/api/#requests.auth.HTTPBasicAuth) and
[`HTTPProxyAuth`](https://requests.readthedocs.io/en/latest/api/#requests.auth.HTTPProxyAuth)
are also available in `requests.auth`. In addition to `requests.auth` classes, the community
has published a few packages with custom authenticator classes, which are compatible with the SDK.
For example:

- [`requests-aws4auth`](https://github.com/tedder/requests-aws4auth): 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 c6caacc

Please sign in to comment.