OAuth2Client
Note
This library extends the original library OAuth2Client with the ability of id_token. To distinguish this library from the original OAuth2Client this library uses the prefix sd. Therefore, the PyPi project name is sd-oauth2-client.
Presentation
- OAuth2Client is a simple python client library for OAuth2. It is based on the requests
- warning:
Starting version 1.2.0, versions older that python 3.6.0 will not be supported anymore. This late version was released by the end 2016.
For those that are still using python 2.7, it won’t be supported by the end of 2020 and all library shall stop supporting it.
Login process
For now it can handle two token process:
Authorization code
User Credentials
Client Credentials
User credentials
Getting a couple of access and refresh token is much easier:
scopes = ['scope_1', 'scope_2']
service_information = ServiceInformation('https://authorization-server/oauth/authorize',
'https://token-server/oauth/token',
'client_id',
'client_secret',
scopes)
manager = CredentialManager(service_information,
proxies=dict(http='http://localhost:3128', https='http://localhost:3128'))
manager.init_with_user_credentials('login', 'password')
_logger.debug('Access got = %s', manager._access_token)
# Here access and refresh token may be used
Client credentials
You can also get a token with client credentials process
manager = CredentialManager(service_information,
proxies=dict(http='http://localhost:3128', https='http://localhost:3128'))
manager.init_with_client_credentials()
# here application admin operation may be called
Refresh token
Provided that you kept a previous refresh_token, you can initiate your credential manager with it:
manager = CredentialManager(service_information,
proxies=dict(http='http://localhost:3128', https='http://localhost:3128'))
manager.init_with_token('my saved refreshed token')
Token expiration
CredentialManager class handle token expiration by calling the CredentialManager._is_token_expired static method. This implementation is not accurate for all OAuth server implementation. You’d better extend CredentialManager class and override _is_token_expired method.
Read other fields from token response
CredentialManager can be subclassed to handle other token response fields such as id_token in OpenId protocol.
class OpenIdCredentialManager(CredentialManager):
def __init__(self, service_information, proxies=None):
super(OpenIdCredentialManager, self).__init__(service_information, proxies)
self.id_token = None
def _process_token_response(self, token_response, refresh_token_mandatory):
id_token = token_response.get('id_token')
OpenIdCredentialManager._check_id(id_token)
super(OpenIdCredentialManager, self)._process_token_response(token_response, refresh_token_mandatory)
self.id_token = id_token
@staticmethod
def _check_id(id_token):
# check that open id token is valid
pass
Metadata
Release files for sd-oauth2-client 1.4.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| sd_oauth2_client-1.4.2.tar.gz | 13.9 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| sd_oauth2_client-1.4.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 26.2 kB
Release files / sd_oauth2_client-1.4.2.tar.gz
| Download URL | sd_oauth2_client-1.4.2.tar.gz |
|---|---|
| Size | 13.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
78f530dd3a728855e992a926e4156a997616da8cfc6332f723e335b2109b57df
|
|
BLAKE2b-256 checksum How to use checksums |
54c66a91d0524c0ad309337d96ae3418d83c7a3a350cbf8625dd5c6858c534e1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.0 CPython/3.9.19
|
Release files / sd_oauth2_client-1.4.2-py3-none-any.whl
| Download URL | sd_oauth2_client-1.4.2-py3-none-any.whl |
|---|---|
| Size | 12.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
6ae21f9bd0bacf2b11fb1903b04768ae2edddc9e8ed1a59412b30d3ac3aa410e
|
|
BLAKE2b-256 checksum How to use checksums |
5b926004bb7454d84bbf8452f4e5afd8a63915b3f6352b28a2e6350b9ebd0669
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.0 CPython/3.9.19
|
Security for sd-oauth2-client 1.4.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.