A solid-OIDC client
Project description
Solid OIDC Client
A client to use Solid-OIDC authentication.
Status
This is in beta: use with care. Expect bugs and breaking changes even with minor version updates.
Currently following features are missing:
- refreshing expired tokens
- persistent client id and client secret
Contributing
Contributions are welcome. These could be additional features, bug fixes, automated testing, better documentation or any other contribution.
Example app
Here is a simple example that authenticates users with this library and makes authenticated requests in the python backend: https://github.com/Otto-AA/solid-flask
Installation
pip install solid_oidc_client
Usage
Following code guides you through the authentication process:
from solid_oidc_client import SolidOidcClient, SolidAuthSession, MemStore
# create a client instance
solid_oidc_client = SolidOidcClient(storage=MemStore())
OAUTH_CALLBACK_URI = '/oauth/callback'
# register this application with the issuer (client_id and client_secret are currently only stored in memory, regardless of the previous storage)
# the redirect url in this case is /oauth/callback
solid_oidc_client.register_client('https://login.inrupt.com/', [OAUTH_CALLBACK_URI])
# initiate a login by redirecting the user to this url
# store the path you want to redirect the user after the login ('/')
login_url = solid_oidc_client.create_login_uri('/', OAUTH_CALLBACK_URI)
# wait for the user to login with their identity provider
# listen on /oauth/callback
# then get code and state from the query params
code = flask.request.args['code']
state = flask.request.args['state']
# and use them to get an authentication session
# internally this will store an access token and key for dpop
session = solid_oidc_client.finish_login(
code=code,
state=state,
callback_uri=OAUTH_CALLBACK_URI,
)
# use this session to make authenticated requests
private_url = 'https://pod.example.org/private/secret.txt'
auth_headers = session.get_auth_headers(private_url, 'GET')
res = requests.get(url=tested_url, headers=auth_headers)
print(res.text)
# optionally serialize and deserialize the sessions to store them as a string client/server side
flask.session['auth'] = session.serialize()
session = SolidAuthSession.deserialize(flask.session['auth'])
Acknowledgments
This is based on solid-flask by Rai.
Project details
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 solid_oidc_client-0.0.3.tar.gz
.
File metadata
- Download URL: solid_oidc_client-0.0.3.tar.gz
- Upload date:
- Size: 4.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 79ae88ce2c58c155e08137bf65554033a684222cfddae523aba92f583c1560bc |
|
MD5 | 50653204610319089daebe5517ffc2c7 |
|
BLAKE2b-256 | bafce3b7e612e6e2470d800bd2f4fa52941dbf5a18a5bd7cd1698532feb518b6 |
File details
Details for the file solid_oidc_client-0.0.3-py3-none-any.whl
.
File metadata
- Download URL: solid_oidc_client-0.0.3-py3-none-any.whl
- Upload date:
- Size: 6.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 202f1c3f393a01412c40bbbd9be9bf9a6cbb07e97110fcaf541bbc67ba93db49 |
|
MD5 | 3616839197a5f3dfbb2c90dbde2c3f1b |
|
BLAKE2b-256 | d83775fb739f90b7ea1134b29c6f837558aeb58a158e04a8aceef3961f7041d6 |