A client library for OAuth2
Project description
Presentation
- OAuth2Client is a simple python client library for OAuth2. It is based on the requests
It is now supported for python 2 and 3
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.
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.