Invenio OpenID Connect
Installation
Invenio OpenID Connect is on PyPI so all you need is:
$ pip install invenio-openid-connect
Configuration
At first add this client to your openid server and get key and secret.
Do not forget to set the allowed redirect url to:
https://localhost:5000/api/oauth/authorized/openid/
Then configure the backend handler in invenio.cfg
from invenio_openid_connect import InvenioAuthOpenIdRemote
OPENIDC_CONFIG = dict(
base_url='https://<openid-server>/openid/',
consumer_key='<key from openid server>',
consumer_secret='<secret from openid server>',
# request_token_url = base_url
# access_token_url = f'${base_url}/token'
# access_token_method = 'POST'
# authorize_url = f'${base_url}/authorize'
# userinfo_url = f'${base_url}/userinfo'
# scope = 'openid email profile'
# signature_method = 'HMAC-SHA1'
# # fields that will be used as a source of username (in this order, first field with value wins)
# username_fields = ['username', 'preferred_username', 'sub', 'email']
)
OAUTHCLIENT_REST_REMOTE_APPS = dict(
# the class from above, the auth method will be called "openid"
openid=InvenioAuthOpenIdRemote().remote_app(),
)
Note that the redirect uri above ends with openid - this is the same key as in OAUTHCLIENT_REST_REMOTE_APPS.
Usage
After local configuration and allowing access at your , head in your browser to https://localhost:5000/api/oauth/login/openid?next=/api/oauth/state
(openid is the key in OAUTHCLIENT_REST_REMOTE_APPS). You should log in with your openid provider and be redirected to state
API which accesses your userinfo data.
OpenID backend
To extend the functionality of the backend (for example, to add a custom UserInfo class) you might want to write your own backend.
from invenio_openid_connect import InvenioAuthOpenIdRemote
class CISLoginAuthRemote(InvenioAuthOpenIdRemote):
# the name of the config settings in invenio.cfg . Default is OPENIDC_CONFIG
CONFIG_OPENID = 'CIS_LOGIN_CONFIG'
# human stuff
name = 'CIS Login Server'
description = 'Login server at CIS UCT Prague'
icon = ''
# userinfo class
userinfo_cls = CISLoginUserInfoClass
Note that if your userinfo class does not inherit from dict it must implement to_dict method that is used
by the state endpoint.
class CISLoginUserInfoClass:
sub: str = None
name: str = None
preferred_username: str = None
given_name: str = None
family_name: str = None
zoneinfo: str = None
locale: str = None
email: str = None
roles: dict = {}
def __init__(self, userinfo: dict):
for k, v in userinfo.items():
setattr(self, k, v)
self.roles = userinfo.get('http://cis.vscht.cz/openid#roles', {})
def to_dict(self):
return self.__dict__
@property
def username(self):
if self.preferred_username:
return self.preferred_username
elif self.email:
return self.email
return self.sub
Then configure the remote as above.
Metadata
Release files for invenio-openid-connect 2.1.0
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 | |
|---|---|---|---|---|
| invenio-openid-connect-2.1.0.tar.gz | 15.5 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| invenio_openid_connect-2.1.0-py2.py3-none-any.whl | Python 3, Python 2 | none | any | Details |
Total release size: 31.5 kB
Release files / invenio-openid-connect-2.1.0.tar.gz
| Download URL | invenio-openid-connect-2.1.0.tar.gz |
|---|---|
| Size | 15.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7cb17ffc077a1d9cb2c3f57dd1e03301beeb6e71449c7f09e67e4ddf14a50a8e
|
|
BLAKE2b-256 checksum How to use checksums |
9ec2dea2b8ee677f0b8a0f3dfef5b2f6b7c93ed2231e4397109a5b5084403e52
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/53.0.0 requests-toolbelt/0.9.1 tqdm/4.56.2 CPython/3.9.1
|
Release files / invenio_openid_connect-2.1.0-py2.py3-none-any.whl
| Download URL | invenio_openid_connect-2.1.0-py2.py3-none-any.whl |
|---|---|
| Size | 16.1 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
850674edb056d1c47c10a3c16447c43e0db1cdbcda0ea40edac08c8a16532f34
|
|
BLAKE2b-256 checksum How to use checksums |
3e526bfa82f43785db8a50aaed7fcb542db67cfddaa0ead2d55233ef3584b0ec
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/53.0.0 requests-toolbelt/0.9.1 tqdm/4.56.2 CPython/3.9.1
|
Security for invenio-openid-connect 2.1.0
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.