Skip to content

Commit

Permalink
Merge pull request #42 from yezz123/Documentation
Browse files Browse the repository at this point in the history
Create a Simple Readme
  • Loading branch information
yezz123 authored Sep 20, 2021
2 parents 50f7a88 + bd2dd29 commit 655be5b
Showing 1 changed file with 118 additions and 4 deletions.
122 changes: 118 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,122 @@
# AuthX
Ready to use and customizable Authentications and Oauth2 management for FastAPI ⚡

- Start working by Checking the Trello Board:
- Ready to use and customizable Authentications and Oauth2 management for FastAPI ⚡

<https://trello.com/b/0NNZMP8T/authx>
## Getting Started

- I Try to Fix Multiple Issues relate to Tests
### Prerequisites

- Python 3.9
- FastAPI
- Docker

### Project setup

```sh
# clone the repo
$ git clone https://github.com/yezz123/AuthX.git

# move to the project folder
$ cd DogeAPI
```

### Creating virtual environment

- Create a virtual environment using virtualenv.

```shell
# creating virtual environment
$ virtualenv venv

# activate virtual environment
$ source venv/bin/activate

# install all dependencies
$ pip install -r requirements.txt
```

## Running the Docker Container

- We have the Dockerfile created in above section. Now, we will use the Dockerfile to create the image of the FastAPI app and then start the FastAPI app container.
- Using a preconfigured `Makefile` tor run the Docker Compose:

```sh
# Pull the latest image
$ make pull

# Build the image
$ make build

# test the image
$ make test

```

##

Project using :

```python
# auth.py
...
from AuthX import Authentication

auth = Authentication()

# main.py
...
from .auth import auth
...
app.include_router(auth.auth_router, prefix="/api/users")
app.include_router(auth.social_router, prefix="/auth")
app.include_router(auth.password_router, prefix="/api/users")
app.include_router(auth.admin_router, prefix="/api/users")
app.include_router(auth.search_router, prefix="/api/users")
...
```

### Startup

```python
# in a startup event
from .auth import auth
...
auth.set_cache(cache) # aioredis client
auth.set_database(database) # motor client
...
```

### Dependency injections

```python
from fastapi import APIRouter, Depends
from AuthX import User
from .auth import auth

router = APIRouter()

@router.get("/anonim")
def anonim_test(user: User = Depends(auth.get_user)):
...

@router.get("/user")
def user_test(user: User = Depends(auth.get_authenticated_user)):
...

@router.get("/admin", dependencies=[Depends(auth.admin_required)])
def admin_test():
...

```

### Dependency injections only

```python
from AuthX import AuthX
auth = AuthX(...)

# startup
...
auth.set_cache(cache) # aioredis
...
```

0 comments on commit 655be5b

Please sign in to comment.