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.1.tar.gz (4.9 kB view details)

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: solid_oidc_client-0.0.1.tar.gz
  • Upload date:
  • Size: 4.9 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.1.tar.gz
Algorithm Hash digest
SHA256 ab250956bbaf9c2cb5d79e1bde0871d51590df685fb8ce69f9a9889b8999dac5
MD5 941f08b31500221c9df9b34f821b2226
BLAKE2b-256 b18d5ace6b409f1552dc69c8c55a242ba6be4992ffb97a04afbcba2926c3c638

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for solid_oidc_client-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e0e44ba90a905b8327ad7831f43e248fab603d5b36fb00f36147643938eaf8a7
MD5 29e511725b0ee44e8fbdd1c66b2e944e
BLAKE2b-256 29b81243692046db3ba9acb8b95247920cced7c23cfc15c9c79089831ef2ca2c

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