https://github.com/torxed/python-olife
Python bindings for
https://github.com/torxed/python-olife
Last synced: 9 months ago
JSON representation
Python bindings for
- Host: GitHub
- URL: https://github.com/torxed/python-olife
- Owner: Torxed
- License: gpl-3.0
- Created: 2019-12-18T21:35:25.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2020-01-22T23:19:27.000Z (almost 6 years ago)
- Last Synced: 2025-01-25T17:15:33.571Z (11 months ago)
- Language: Python
- Homepage: https://github.com/Torxed/obtain.life
- Size: 23.4 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# python-olife
Python bindings for [obtain.life](https://github.com/Torxed/obtain.life).
Used in back-end services to get SSO *(single Sign On)* or to communicate with the obtain.life Identity Management suit *(self-hosted or otherwise)*
Essentiallu a minified version of JWT but a lighter version with Identity Management.
# Features
* [HS256](https://github.com/Torxed/python-olife/wiki/HS256)
* HS384
* HS512
* RS256
* RS384
* RS512
* ES256
* ES384
* ES512
* PS256
* PS384
* PS512
* EdDSA
# How to use
Assuming `git clone git@github.com:Torxed/python-olife.git olife` in your projects root directory:
```python
from olife import olife
life = olife.obtain_life('shared secret if HS256 for instance')
life.subscribe('scientist.cloud', 'shared backend secret, different from shared secret above')
while 1:
data = life.recv(timeout=0.5)
life.parse(data)
# Grab by username defaulting to the domain subscribed above
print(life.is_logged_in('anton'))
# Or by username to a custom domain
print(life.is_logged_in('anton', domain='hvornum.se'))
# Or check by token-reference, usually submitted by a user
# upon every request to validate it's authentication state.
print(life.is_logged_in('A USER SUBMITTED TOKEN'))
```
Note that checking if a user is logged in cross-domain requires a pre-configured shared state between two domains. *(subdomains automatically get a shared state, unless otherwise turned off by the domain owner)*
## User Registration
To register a user, assuming you've set up the domain before hand with the IM. You can use the `register_user` function:
```python
def user_created(data, *args, **kwargs):
print('User creation response:')
print(json.dumps(data, indent=4))
life.register_user(user='anton', domain='obtain.life', callback=user_created)
```
## Event push notifications
To get authentication events pushed from the IM to your back-end service, register a auth hook:
```python
def auth_event(data, *args, **kwargs):
print('User authentication data:')
print(json.dumps(data, indent=4))
life.event_hook('auth', auth_event)
```
For a complete list of events, see [Event types](https://github.com/Torxed/obtain.life/wiki/Event-types) at `obtain.life`