Authicola
A Python package offering convenient methods for OAuth2.0 authentication
Currently, Google and GitHub have been implemented
Expects a config object passed into the class on instantiation of the Authicola class.
Scopes are accepted as arguments by the config, but they can also be passed in as a kwarg on the Authicola class method for the driver or a method on the driver itself.
E.g.
DRIVERS = {
'google': {
'client_id': os.environ.get('GOOGLE_CLIENT'),
'client_secret': os.environ.get('GOOGLE_SECRET'),
'redirect_uri': os.environ.get('GOOGLE_REDIRECT'),
'scopes': ['profile', 'email']
},
'github': {
'client_id': os.environ.get('GITHUB_CLIENT'),
'client_secret': os.environ.get('GITHUB_SECRET'),
'redirect_uri': os.environ.get('GITHUB_REDIRECT'),
'scopes': ['read:user', 'public_repo']
}
}
from authicola import Authicola
a = Authicola(DRIVERS)
# default scope from config used
authorization_url = a.driver('google').redirect_uri()
# https://accounts.google.com/o/oauth2/v2/auth?scope=email+profile&access_type=offline&redirect_uri=<your-redirect-uri>&response_type=code&client_id=<your-client-id>
# only email scope requested as kwarg, overrides config for driver
authorization_url = a.driver('google', scopes=['email']).redirect_uri()
# https://accounts.google.com/o/oauth2/v2/auth?scope=email&access_type=offline&redirect_uri=<your-redirect-uri>&response_type=code&client_id=<your-client-id>
# only profile and email scopes requested manually, this time as method on the driver class .scopes, overrides config for driver
authorization_url = a.driver('google').scopes('email', 'profile').redirect_uri()
# https://accounts.google.com/o/oauth2/v2/auth?scope=email+profile&access_type=offline&redirect_uri=<your-redirect-uri>&response_type=code&client_id=<your-client-id>
An optional state parameter can be used in the same way as scope (without the default value), for prevention of CSRF attacks.
E.g.
# not state param used
authorization_url = a.driver('github').redirect_uri()
# state param set as kwarg
authorization_url = a.driver('github', state='state-string-here').redirect_uri()
# state param set as class method state
authorization_url = a.driver('github').state('state-string-here').redirect_uri()
On callback from the authentication provider, a params dict is expected for parsing to retrieve the user. An optional state parameter is also accepted, and if passed in it will be used to validate against the callback url params state param
E.g.
# callack endpoint
a = Authicola(DRIVERS)
params = request.GET
user = a.driver('google').user(params)
###
{
'id': <id>,
'email': 'garyburgmann@gmail.com',
'verified_email': True,
'name': 'Gary Burgmann',
'given_name': 'Gary',
'family_name': 'Burgmann',
'picture': '<pic-url>',
'locale': 'en-GB'
}
###
# or to validate the state between redirect and callback. the state sting can be any unguessable string you like
def redirect(self):
state = uuid.uuid4().hex
self.request.session.set('github_redirect', state)
authorization_url = self.authicola.driver('github').state(state).redirect_uri()
return request().redirect(authorization_url)
def callback(self):
state = self.request.session.get('github_redirect')
user = self.authicola.driver('github').user(request().all(), state)
return user
Metadata
Release files for authicola 0.0.7
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 | |
|---|---|---|---|---|
| authicola-0.0.7.tar.gz | 4.5 kB | Without provenance | Details |
Release files / authicola-0.0.7.tar.gz
| Download URL | authicola-0.0.7.tar.gz |
|---|---|
| Size | 4.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
cb126168839e8cfc61f9b1da08e8b67bf2fc52f16bd11e87ceffa53e3b53ffa9
|
|
BLAKE2b-256 checksum How to use checksums |
b9c4c72daa32e23e18da65766fa2960110612cb167282cb174a8d6b8e984b3f2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.33.0 CPython/3.7.3
|
Security for authicola 0.0.7
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.
To learn more about protecting yourself from malicious actors, visit our package security documentation.