Skip to main content

feedr-oauth2

This is a Python library that implements the client side of following OAuth 2.0 flows:

  • Authorization Code
  • Client Credentials
  • Device Code
  • Refresh Token

The implementation follows the OAuth2 standard described in https://oauth.net/2/.

Quickstart

Authorization Code

from feedr.oauth2.authorization_code import Client, PKCE

client = ac.Client(
  auth_uri='https://authorization-server.com/oauth2/authorize',
  token_uri='https://authorization-server.com/oauth2/token',
  client_id='...',
  client_secret='...',
  redirect_uri='...',
  use_pkce=True,
)

# ------------------
# /api/login
# ------------------

request = client.authorization_request(
  scope='read+write',
  redirect_uri=EXTERNAL_URL + '/api/login/collect',
)

persist_state(request.state, request.pkce)

return redirect(request.auth_uri)

# ------------------
# /api/login/collect?code=...&state=...
# ------------------

pkce: PKCE = retrieve_state(state)

response = client.authorization_code(code, pkce)

print(response)  # AccessTokenResponse(access_token='...', token_type='bearer', ...)

Client Credentials

from feedr.oauth2.client_credentials as Client

client = Client(
  token_uri='https://authorization-server.com/oauth2/token',
  client_id='...',
  client_secret='...',
)

token_info = client.get_token()
print(token_info)  # AccessTokenResponse(access_token='...', token_type='bearer', ...)

Device Code

from feedr.oauth2.device_code import Client

client = Client(
  device_code_uri='https://authorization-server.com/device/code',
  token_uri='https://authorization-server.com/oauth2/token',
  client_id='...',
  client_secret='...',
)

request = client.get_device_code()
print(f'Visit {request.verification_url} and enter the code {request.user_code}.')

token_info = client.poll(request)
print(token_info)  # AccessTokenResponse(access_token='...', token_type='bearer', ...)

Refresh Token

The authorization_code.Client class has a refresh_token() method that makes refreshing the access token easy by simply supplying the refresh token.

new_token = client.refresh_token(token_info.refresh_token)

Alternatively, the refresh_token.Client can be used to create a refresh_token request.

client = Client(
  token_uri='https://authorization-server.com/oauth2/token',
  refresh_token='...',
  client_id='...',
  client_secret='...',
)

token_info = client.get_token()
print(token_info)  # AccessTokenResponse(access_token='...', token_type='bearer', ...)

Copyright © 2020 Niklas Rosenstein

Metadata

Release files for feedr.oauth2 0.1.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for feedr.oauth2 0.1.3
File Size Uploaded
feedr.oauth2-0.1.3.tar.gz 8.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for feedr.oauth2 0.1.3
File Interpreter ABI Platform
feedr.oauth2-0.1.3-py3-none-any.whl Python 3 none any Details

Total release size: 17.5 kB

Release files / feedr.oauth2-0.1.3.tar.gz

Download URL feedr.oauth2-0.1.3.tar.gz
Size 8.3 kB
Tags Source
SHA-256 checksum
How to use checksums
1a1c9f7ddfaae00b17f340dc51ef743f65d6aa4319f4beb870a048cc60c47c99
BLAKE2b-256 checksum
How to use checksums
d9e6f06275210119ebec5aa1833a32fe08755653f3f07986cccfcf4825759cf8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.5

Release files / feedr.oauth2-0.1.3-py3-none-any.whl

Download URL feedr.oauth2-0.1.3-py3-none-any.whl
Size 9.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
fd6b65e5f0445e6f8b9e6d6d49c9e8787e1ed70ea9cb86afb413c28b7f1b1777
BLAKE2b-256 checksum
How to use checksums
a38fb1ec614daecad5a17423cfef21df00dc84bda4be3e324653cc0c79135b58
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.5

Release history Release notifications | RSS feed

This release

0.1.3 This release

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page