Last active
November 1, 2023 06:16
-
-
Save hrchu/b53e12389d2e4b0d01ddd29fe4a4d9eb to your computer and use it in GitHub Desktop.
play solid_oidc_client
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
In [2]: from solid_oidc_client import SolidOidcClient, MemStore | |
...: solid_oidc_client = SolidOidcClient(storage=MemStore()) | |
...: import requests | |
In [4]: issuer = 'https://login.inrupt.com/' | |
...: redirect_url = 'http://localhost:3333/oauth/callback' | |
...: solid_oidc_client.register_client(issuer, [redirect_url]) | |
In [5]: login_url = solid_oidc_client.create_login_uri('/', redirect_url) | |
...: print(login_url) | |
https://login.inrupt.com/authorization?code_challenge=NgXRy3KX9i06ormTidcbtyU0i5b1ObMV9yxnBu778vg&state=e6e6b544-4639-4fa7-b101-b0d1241e005d&response_type=code&redirect_uri=http%3A%2F%2Flocalhost%3A3333%2Foauth%2Fcallback&code_challenge_method=S256&client_id=dc0076ef-00ad-42c3-906a-7dd278187a92&scope=openid+offline_access | |
In [6]: code = '33b4d3ca-7a3c-4e30-abe5-838313066875' | |
In [7]: state='e6e6b544-4639-4fa7-b101-b0d1241e005d' | |
In [8]: session = solid_oidc_client.finish_login( | |
...: code=code, | |
...: state=state, | |
...: callback_uri=redirect_url) | |
In [12]: tested_url = 'https://storage.inrupt.com/68cc69f9-b1e3-487f-b4c9-af0518eb9830/private/test.jpeg' | |
In [14]: headers = session.get_auth_headers(tested_url, 'GET') | |
In [15]: headers | |
Out[15]: | |
{'Authorization': 'DPoP eyJraWQiOiJISmhrMmJNdEpIMEIiLCJ0eXAiOiJKV1QiLCJhbGciOiJFUzI1NiJ9.eyJ3ZWJpZCI6Imh0dHBzOi8vaWQuaW5ydXB0LmNvbS9wZXRlcnRjIiwiY25mIjp7ImprdCI6IjhqUWJYczdwN2FQR0s3Sm5zdTlPbmQzY25xdVI3T0hyVTRxVFZoeFdVYkEifSwic3ViIjoicGV0ZXJ0YyIsImF1ZCI6InNvbGlkIiwiY2xpZW50X2lkIjoiZGMwMDc2ZWYtMDBhZC00MmMzLTkwNmEtN2RkMjc4MTg3YTkyIiwiaXNzIjoiaHR0cHM6Ly9sb2dpbi5pbnJ1cHQuY29tIiwiaWF0IjoxNjk4ODE3NjU4LCJleHAiOjE2OTg4MTc5NTgsImp0aSI6ImVhMTQ0MzMyLTJiYWItNDBmZC1iYzdmLWZiNjlkZjdjYTRlZiJ9.nMnucyISSOo1OfV8kugswqWEVQGA1v6RUKW8BgEA6gmXl3dkmKvx8z8YYjuW5sRNl17-dV5toSyZcQvlJDRrYA', | |
'DPoP': 'eyJhbGciOiJFUzI1NiIsImp3ayI6eyJjcnYiOiJQLTI1NiIsImt0eSI6IkVDIiwieCI6InVocXJ5Nkc4V0dxeGFKZF9PSF9rNy05cVI5UEhudDRocmtWcmlnQklTZVEiLCJ5IjoiNmhHRlVVek50d1J0NE5JUmc5OTl5LWNIQXFlNHQxTDg3VGIzR2xrS1VPOCJ9LCJ0eXAiOiJkcG9wK2p3dCJ9.eyJodG0iOiJHRVQiLCJodHUiOiJodHRwczovL3N0b3JhZ2UuaW5ydXB0LmNvbS82OGNjNjlmOS1iMWUzLTQ4N2YtYjRjOS1hZjA1MThlYjk4MzAvcHJpdmF0ZS90ZXN0LmpwZWciLCJpYXQiOjE2OTg4MTc3ODksImp0aSI6IjQyNWNkNTkwLTkwZWQtNGZmMC04NGZkLWQ5MGY3NzJjNWNhNCJ9.fID8k7Yxv3eRgt0Qv5jJT0JPoYW20GNefOGpcZqRCycxXE8uEcbWka5ruvKMPBHJjZs9Gbml6iu-cZ7Ki5Nckg'} | |
In [18]: res = requests.get(url=tested_url, headers=headers) | |
In [19]: res.text |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ref https://github.com/Otto-AA/solid-oidc-py