Metadata-Version: 2.1
Name: solid_oidc_client
Version: 0.0.1
Summary: A solid-OIDC client
Project-URL: Homepage, https://github.com/Otto-AA/solid-oidc-py
Project-URL: Bug Tracker, https://github.com/Otto-AA/solid-oidc-py/issues
Author-email: A_A <21040751+Otto-AA@users.noreply.github.com>
License-File: LICENSE
Classifier: Development Status :: 3 - Alpha
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Requires-Python: >=3.7
Description-Content-Type: text/markdown

## 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:

```python
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](https://gitlab.com/agentydragon/solid-flask/) by Rai. I've refactored the authentication logic to be more reusable.
