A client library for OAuth2
Project description
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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file oauth2-client-1.4.2.tar.gz
.
File metadata
- Download URL: oauth2-client-1.4.2.tar.gz
- Upload date:
- Size: 11.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: Python-urllib/3.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5381900448ff1ae762eb7c65c501002eac46bb5ca2f49477fdfeaf9e9969f284 |
|
MD5 | 5072bf03f27ec7d9bf27b8e9fa90ab88 |
|
BLAKE2b-256 | 1555a2f286428a9b6f638035186762e4379bd65fa37fb82831f0f6163f90119d |
File details
Details for the file oauth2_client-1.4.2-py3-none-any.whl
.
File metadata
- Download URL: oauth2_client-1.4.2-py3-none-any.whl
- Upload date:
- Size: 12.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: Python-urllib/3.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7b938ba8166128a3c4c15ad23ca0c95a2468f8e8b6069d019ebc73360c15c7ca |
|
MD5 | 746546dfe4155974adeff2dd68066552 |
|
BLAKE2b-256 | ec394d2e225376929a04b422a628d6ba839bbe28e2f96b15aca791547cbfb248 |