Skip to main content

A solid-OIDC client

Project description

Running

  • Run python3 -m venv vev to create a virtual environment (so you don't install dependencies globally)
  • Start the virtual environment, e.g. . venv/bin/activate
  • Install dependencies pip install -r requirements.txt

Now you can start the application with python solid_flask_main.py. Append eg --issuer https://login.inrupt.com/ to run it with a different issuer.

Authentication Flow

Following code guides you through the authentication process:

from solid_oidc import SolidOidcClient
from solid_auth_session import SolidAuthSession
from storage import 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'])

TODOs

  • persist client id and secret
  • refresh tokens when they expire

Acknowledgments

This is a fork of solid-flask by Rai. I've refactored the authentication logic to be more reusable.

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

solid_oidc_client-0.0.2.tar.gz (5.1 kB view details)

Uploaded Source

Built Distribution

solid_oidc_client-0.0.2-py3-none-any.whl (6.5 kB view details)

Uploaded Python 3

File details

Details for the file solid_oidc_client-0.0.2.tar.gz.

File metadata

  • Download URL: solid_oidc_client-0.0.2.tar.gz
  • Upload date:
  • Size: 5.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.2

File hashes

Hashes for solid_oidc_client-0.0.2.tar.gz
Algorithm Hash digest
SHA256 4946d86ec168412562c35309a60a2d466c00d421cfaeb6b9b232a0065ee15a62
MD5 bdd83cc97445b45a80c977fbd0564c8f
BLAKE2b-256 1496fd9eaa3687c304f218184b44b81d3c4fad2f036fcf4658a16a8df3d667cd

See more details on using hashes here.

File details

Details for the file solid_oidc_client-0.0.2-py3-none-any.whl.

File metadata

File hashes

Hashes for solid_oidc_client-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 1e87322f4f494d38f9d5287e1f157c113bd4ae81169b2315990f19886e6e5250
MD5 98de9d3c5344f1f05d0ede7f903decda
BLAKE2b-256 2b93c6baa9137c3103c74834db2b3b3af7672d44d5d84c37f4a7eb0671e0a9aa

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page