Metadata-Version: 2.1
Name: easy-auth
Version: 0.143
Summary: Create a centralized Authentication and Authorization token server. Easily secure FastAPI endpoints based on Users, Groups, Roles or Permissions with very little database usage.
Home-page: https://github.com/codemation/easyauth
Author: Joshua Jamison
Author-email: joshjamison1@gmail.com
License: UNKNOWN
Platform: UNKNOWN
Classifier: Programming Language :: Python :: 3
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Requires-Python: >=3.7, <4
Description-Content-Type: text/markdown
Requires-Dist: makefun (==1.9.5)
Requires-Dist: PyJWT (==2.0.0)
Requires-Dist: python-jwt (==3.3.0)
Requires-Dist: fastapi
Requires-Dist: uvicorn
Requires-Dist: python-multipart (==0.0.5)
Requires-Dist: easyadmin (>=0.150)
Requires-Dist: easyrpc (>=0.241)
Provides-Extra: all
Requires-Dist: aiopyql (>=0.357) ; extra == 'all'
Requires-Dist: cryptography ; extra == 'all'
Requires-Dist: bcrypt (==3.2.0) ; extra == 'all'
Requires-Dist: uvloop ; extra == 'all'
Requires-Dist: example ; extra == 'all'
Requires-Dist: httptools ; extra == 'all'
Requires-Dist: gunicorn ; extra == 'all'
Requires-Dist: fastapi-mail (==0.3.7) ; extra == 'all'
Requires-Dist: email-validator ; extra == 'all'
Provides-Extra: client
Provides-Extra: server
Requires-Dist: aiopyql (>=0.357) ; extra == 'server'
Requires-Dist: cryptography ; extra == 'server'
Requires-Dist: bcrypt (==3.2.0) ; extra == 'server'
Requires-Dist: uvloop ; extra == 'server'
Requires-Dist: example ; extra == 'server'
Requires-Dist: httptools ; extra == 'server'
Requires-Dist: gunicorn ; extra == 'server'
Requires-Dist: fastapi-mail (==0.3.7) ; extra == 'server'
Requires-Dist: email-validator ; extra == 'server'

![](./images/logo_t.png)
<br>
#
Create a centralized Authentication and Authorization token server. Easily secure FastAPI endpoints based on Users, Groups, Roles or Permissions with very little database usage.

[![Documentation Status](https://readthedocs.org/projects/easyauth/badge/?version=latest)](https://easyauth.readthedocs.io/en/latest/?badge=latest) [![PyPI version](https://badge.fury.io/py/easy-auth.svg)](https://pypi.org/project/easy-auth/)

<h2>Documentation</h1> 

[https://easyauth.readthedocs.io/en/latest/](https://easyauth.readthedocs.io/en/latest/)

## Key Features
- Centralized Authentication - Create Users / Groups / Roles / Actions once, use everywhere. 
- Admin GUI 
- JWT Token Authentication with RSA private / public key verification
- Easily backup / restore configration
- Builtin client login & cookie system

## Quick Start
```bash

$ virtualenv -p <python3.X> easy-auth-env
$ source easy-auth-env/bin/activate

(easy-auth) $ pip install easy-auth[server] 

(easy-auth) $ pip install easy-auth[client] # without db 

```
##  Basic Server

Configure require env variables via a .json
```Bash
$ cat > server_env.json <<EOF
{
    "DB_TYPE": "sqlite",
    "DB_NAME": "auth",
    "ISSUER": "EasyAuth",
    "SUBJECT": "EasyAuthAuth",
    "AUDIENCE": "EasyAuthApis",
    "KEY_PATH": "/my_key-location",
    "KEY_NAME": "test_key"
}
EOF
```

```python
#test_server.py
from fastapi import FastAPI

from easyauth.server import EasyAuthServer

server = FastAPI()

@server.on_event('startup')
async def startup():
    server.auth = await EasyAuthServer.create(
        server, 
        '/auth/token',
        auth_secret='abcd1234',
        admin_title='EasyAuth - Company',
        admin_prefix='/admin',
        env_from_file='server_sqlite.json'
    )

```
Start Sever
```bash
$ uvicorn --host 0.0.0.0 --port 8330 test_server:server
```

## Basic Client


```python
#test_client.py
from fastapi import FastAPI

from easyauth.client import EasyAuthClient

server = FastAPI()

@server.on_event('startup')
async def startup():
@server.on_event('startup')
async def startup():
    server.auth = await EasyAuthClient.create(
        server,
        token_server='0.0.0.0',
        token_server_port=8090,
        auth_secret='abcd1234',
        default_permissions={'groups': ['users']}
    )

    # grants access to users matching default_permissions
    @server.auth.get('/default')
    async def default():
        return f"I am default"

    # grants access to only specified users
    @server.auth.get('/', users=['jane'])
    async def root():
        return f"I am root"

    # grants access to members of 'users' or 'admins' group.
    @server.auth.get('/groups', groups=['users', 'admins'])
    async def groups():
        return f"I am groups"

    # grants access to all members of 'users' group 
    # or a groups with role of 'basic' or advanced
    @server.auth.get('/roles', roles=['basic', 'advanced'], groups=['users'])
    async def roles():
        return f"Roles and Groups"

    # grants access to all members of groups with a roles granting 'BASIC_CREATE'
    @server.auth.get('/actions', actions=['BASIC_CREATE'])
    async def action():
        return f"I am actions"
```
![](docs/images/login.png)


## Server 
<h3>See 0.0.0.0:8330/docs </h3>

![](docs/images/api/api.png)

### GUI
![](docs/images/admin_gui.png)

## Client

![](images/client.png)

![](images/OAuth.png)



