Skip to content

Commit d8ecc5f

Browse files
authored
📝 Update README for AuthX (#785)
- Changed project name from "Authx" to "AuthX" for consistency. - Improved installation instructions and quick start examples for clarity. - Updated features section to reflect support for Python 3.9+ and Pydantic 2. - Enhanced JWT authentication details, including multiple token locations and access/refresh token support. - Added extra features section for additional capabilities when using `authx-extra`.
1 parent ed0edfd commit d8ecc5f

File tree

1 file changed

+62
-65
lines changed

1 file changed

+62
-65
lines changed

README.md

Lines changed: 62 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Authx
1+
# AuthX
22

33
<p align="center">
44
<a href="https://authx.yezz.me" target="_blank">
@@ -11,10 +11,10 @@
1111

1212
---
1313

14-
| Project | Status |
15-
|---------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
16-
| CI | [ ![ CI ]( https://github.com/yezz123/authx/actions/workflows/ci.yml/badge.svg ) ]( https://github.com/yezz123/authx/actions/workflows/ci.yml ) [ ![ pre-commit.ci status ]( https://results.pre-commit.ci/badge/github/yezz123/authx/main.svg ) ]( https://results.pre-commit.ci/latest/github/yezz123/authx/main ) [ ![ Codecov ]( https://codecov.io/gh/yezz123/authx/branch/main/graph/badge.svg ) ]( https://codecov.io/gh/yezz123/authx ) |
17-
| Meta | [ ![ Package version ]( https://img.shields.io/pypi/v/authx?color=%2334D058&label=pypi%20package ) ]( https://pypi.org/project/authx ) [ ![ Downloads ]( https://static.pepy.tech/badge/authx ) ]( https://pepy.tech/project/authx ) [ ![ Pydantic Version 2 ]( https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/pydantic/pydantic/main/docs/badge/v2.json ) ]( https://pydantic.dev ) [ ![ Ruff ]( https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json ) ]( https://github.com/astral-sh/ruff ) [![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=yezz123_authx&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=yezz123_authx) |
14+
| Project | Status |
15+
|---------|--------|
16+
| CI | [![CI](https://github.com/yezz123/authx/actions/workflows/ci.yml/badge.svg)](https://github.com/yezz123/authx/actions/workflows/ci.yml) [![pre-commit.ci status](https://results.pre-commit.ci/badge/github/yezz123/authx/main.svg)](https://results.pre-commit.ci/latest/github/yezz123/authx/main) [![Codecov](https://codecov.io/gh/yezz123/authx/branch/main/graph/badge.svg)](https://codecov.io/gh/yezz123/authx) |
17+
| Meta | [![Package version](https://img.shields.io/pypi/v/authx?color=%2334D058&label=pypi%20package)](https://pypi.org/project/authx) [![Downloads](https://static.pepy.tech/badge/authx)](https://pepy.tech/project/authx) [![Pydantic Version 2](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/pydantic/pydantic/main/docs/badge/v2.json)](https://pydantic.dev) [![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff) [![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=yezz123_authx&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=yezz123_authx) |
1818

1919
---
2020

@@ -24,75 +24,81 @@
2424

2525
---
2626

27-
Add a Fully registration and authentication or authorization system to your
28-
[FastAPI](https://fastapi.tiangolo.com/) project. **AuthX** is designed to be as
29-
customizable and adaptable as possible.
27+
Add a fully featured authentication and authorization system to your [FastAPI](https://fastapi.tiangolo.com/) project. **AuthX** is designed to be simple, customizable, and secure.
3028

31-
## Features
32-
33-
- [x] Support Python 3.8+ & Pydantic 1.7+.
34-
- [x] Multiple customizable authentication backend:
35-
- [x] JWT authentication backend included
36-
- [x] JWT encoding/decoding for application authentication
37-
- [x] Automatic detection of JWTs in requests:
38-
- [x] JWTs in headers
39-
- [x] JWTs in cookies
40-
- [x] JWTs in query parameters
41-
- [x] JWTs in request bodies
42-
- [x] Cookie authentication backend included
43-
- [x] Middleware for authentication and authorization through JWT.
44-
- [x] Extensible Error Handling System.
45-
46-
### Extra Features
47-
48-
AuthX is designed to be as customizable and adaptable as possible.
49-
50-
So you need to install [`authx-extra`](https://github.com/yezz123/authx-extra) to get extra features.
51-
52-
- [x] Using Redis as a session store & cache.
53-
- [x] Support HTTPCache.
54-
- [x] Support Sessions and Pre-built CRUD functions and Instance to launch Redis.
55-
- [x] Support Middleware of [pyinstrument](https://pyinstrument.readthedocs.io/) to check your service performance.
56-
- [x] Support Middleware for collecting and exposing [Prometheus](https://prometheus.io/) metrics.
57-
58-
**Note:** Check [Release Notes](https://authx.yezz.me/release/).
29+
## Installation
5930

60-
## Project using
31+
```bash
32+
pip install authx
33+
```
6134

62-
Here is a simple way to kickstart your project with AuthX:
35+
## Quick Start
6336

6437
```python
6538
from fastapi import FastAPI, Depends, HTTPException
66-
from authx import AuthX, AuthXConfig, RequestToken
39+
from authx import AuthX, AuthXConfig
6740

6841
app = FastAPI()
6942

7043
config = AuthXConfig(
71-
JWT_ALGORITHM = "HS256",
72-
JWT_SECRET_KEY = "SECRET_KEY",
73-
JWT_TOKEN_LOCATION = ["headers"],
44+
JWT_SECRET_KEY="your-secret-key", # Change this!
45+
JWT_TOKEN_LOCATION=["headers"],
7446
)
7547

7648
auth = AuthX(config=config)
7749
auth.handle_errors(app)
7850

79-
@app.get('/login')
51+
@app.post("/login")
8052
def login(username: str, password: str):
81-
if username == "xyz" and password == "xyz":
82-
token = auth.create_access_token(uid=username)
83-
return {"access_token": token}
84-
raise HTTPException(401, detail={"message": "Invalid credentials"})
85-
86-
@app.get("/protected", dependencies=[Depends(auth.get_token_from_request)])
87-
def get_protected(token: RequestToken = Depends()):
88-
try:
89-
auth.verify_token(token=token)
90-
return {"message": "Hello world !"}
91-
except Exception as e:
92-
raise HTTPException(401, detail={"message": str(e)}) from e
53+
if username == "test" and password == "test":
54+
token = auth.create_access_token(uid=username)
55+
return {"access_token": token}
56+
raise HTTPException(401, detail="Invalid credentials")
57+
58+
@app.get("/protected", dependencies=[Depends(auth.access_token_required)])
59+
def protected():
60+
return {"message": "Hello World"}
61+
```
62+
63+
**Test it:**
64+
65+
```bash
66+
# Get a token
67+
curl -X POST "http://localhost:8000/login?username=test&password=test"
68+
69+
# Access protected route
70+
curl -H "Authorization: Bearer <your-token>" http://localhost:8000/protected
71+
```
72+
73+
## Features
74+
75+
- Support for Python 3.9+ and Pydantic 2
76+
- JWT authentication with multiple token locations:
77+
- Headers (Bearer token)
78+
- Cookies (with CSRF protection)
79+
- Query parameters
80+
- JSON body
81+
- Access and refresh token support
82+
- Token freshness for sensitive operations
83+
- Token blocklist/revocation
84+
- Extensible error handling
85+
86+
### Extra Features
87+
88+
Install [`authx-extra`](https://github.com/yezz123/authx-extra) for additional features:
89+
90+
```bash
91+
pip install authx-extra
9392
```
9493

95-
## Contributors and sponsors
94+
- Redis session store and cache
95+
- HTTP caching
96+
- Performance profiling with pyinstrument
97+
- Prometheus metrics
98+
99+
**Note:** Check [Release Notes](https://authx.yezz.me/release/).
100+
101+
## Contributors and Sponsors
96102

97103
<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
98104
[![All Contributors](https://img.shields.io/badge/all_contributors-16-orange.svg?style=flat-square)](#contributors-)
@@ -136,15 +142,6 @@ Thanks goes to these wonderful people
136142

137143
<!-- ALL-CONTRIBUTORS-LIST:END -->
138144

139-
<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
140-
<!-- prettier-ignore-start -->
141-
<!-- markdownlint-disable -->
142-
143-
<!-- markdownlint-restore -->
144-
<!-- prettier-ignore-end -->
145-
146-
<!-- ALL-CONTRIBUTORS-LIST:END -->
147-
148145
This project follows the
149146
[all-contributors](https://github.com/all-contributors/all-contributors)
150147
specification. Contributions of any kind welcome!

0 commit comments

Comments
 (0)