Updated to expose auth_app instead of app_route
This commit is contained in:
49
README.md
49
README.md
@@ -75,17 +75,18 @@ This example configures myauth to use MongoDB as its backend.
|
||||
```Python
|
||||
|
||||
from fastapi import FastAPI
|
||||
from myauth import create_app_router_for_mongoDB
|
||||
|
||||
from myauth import create_auth_app_for_mongodb
|
||||
|
||||
# 1. Initialize FastAPI app
|
||||
app = FastAPI()
|
||||
|
||||
# 2. Configure repositories for MongoDB
|
||||
auth_router = create_app_router_for_mongoDB(mongodb_url="mongodb://localhost:27017",
|
||||
jwt_secret="THIS_NEEDS_TO_BE_CHANGED")
|
||||
auth_app = create_auth_app_for_mongodb(mongodb_url="mongodb://localhost:27017",
|
||||
jwt_secret="THIS_NEEDS_TO_BE_CHANGED")
|
||||
|
||||
# 3. Include the authentication routes
|
||||
app.include_router(auth_router)
|
||||
app.mount("/auth", auth_app)
|
||||
|
||||
|
||||
@app.get("/")
|
||||
@@ -100,19 +101,20 @@ This example configures myauth to use PostgreSQL as its backend.
|
||||
```Python
|
||||
|
||||
from fastapi import FastAPI
|
||||
from myauth import create_app_router_for_postgreSQL
|
||||
|
||||
from myauth import create_auth_app_for_postgresql
|
||||
|
||||
# 1. Initialize FastAPI app
|
||||
app = FastAPI()
|
||||
|
||||
# 2. Configure repositories for MongoDB
|
||||
auth_router = create_app_router_for_mongoDB(postgresql_url="mongodb://localhost:27017",
|
||||
username="admin",
|
||||
password="password",
|
||||
jwt_secret="THIS_NEEDS_TO_BE_CHANGED")
|
||||
# 2. Configure repositories for PostgreSQL
|
||||
auth_app = create_auth_app_for_postgresql(postgresql_url="mongodb://localhost:27017",
|
||||
username="admin",
|
||||
password="password",
|
||||
jwt_secret="THIS_NEEDS_TO_BE_CHANGED")
|
||||
|
||||
# 3. Include the authentication routes
|
||||
app.include_router(auth_router)
|
||||
app.mount("/auth", auth_app)
|
||||
|
||||
|
||||
@app.get("/")
|
||||
@@ -127,16 +129,17 @@ This example configures myauth to use SQLite, which is ideal for development or
|
||||
```Python
|
||||
|
||||
from fastapi import FastAPI
|
||||
from myauth import create_app_router_for_sqlite
|
||||
|
||||
from myauth import create_auth_app_for_sqlite
|
||||
|
||||
# 1. Initialize FastAPI app
|
||||
app = FastAPI()
|
||||
|
||||
# 2. Configure repositories for MongoDB
|
||||
auth_router = create_app_router_for_sqlite(db_path="./UserDB", jwt_secret="THIS_NEEDS_TO_BE_CHANGED")
|
||||
auth_app = create_auth_app_for_sqlite(db_path="./UserDB", jwt_secret="THIS_NEEDS_TO_BE_CHANGED")
|
||||
|
||||
# 3. Include the authentication routes
|
||||
app.include_router(auth_router)
|
||||
app.mount("/auth", auth_app)
|
||||
|
||||
|
||||
@app.get("/")
|
||||
@@ -159,8 +162,9 @@ pip install "myauth[email]"
|
||||
```Python
|
||||
|
||||
from fastapi import FastAPI
|
||||
|
||||
from myauth import create_auth_app_for_sqlite
|
||||
from myauth.emailing.smtp import SMTPEmailService
|
||||
from myauth import create_app_router_for_sqlite
|
||||
|
||||
# 1. Initialize FastAPI app
|
||||
app = FastAPI()
|
||||
@@ -175,11 +179,11 @@ email_service = SMTPEmailService(
|
||||
)
|
||||
|
||||
# 3. Configure repositories for MongoDB
|
||||
auth_router = create_app_router_for_sqlite(db_path="./UserDB", jwt_secret="THIS_NEEDS_TO_BE_CHANGED",
|
||||
email_service=email_service)
|
||||
auth_app = create_auth_app_for_sqlite(db_path="./UserDB", jwt_secret="THIS_NEEDS_TO_BE_CHANGED",
|
||||
email_service=email_service)
|
||||
|
||||
# 4. Include the authentication routes
|
||||
app.include_router(auth_router)
|
||||
app.mount("/auth", auth_app)
|
||||
```
|
||||
|
||||
### Option 2: Create a Custom Email Service
|
||||
@@ -189,8 +193,9 @@ If you use a third-party service (like AWS SES, Mailgun) that requires an API, y
|
||||
```Python
|
||||
|
||||
from fastapi import FastAPI
|
||||
|
||||
from myauth import create_auth_app_for_sqlite
|
||||
from myauth.emailing.base import EmailService
|
||||
from myauth import create_app_router_for_sqlite
|
||||
|
||||
# 1. Initialize FastAPI app
|
||||
app = FastAPI()
|
||||
@@ -220,11 +225,11 @@ class CustomEmailService(EmailService):
|
||||
email_service = CustomEmailService(api_key="YOUR_API_KEY_HERE")
|
||||
|
||||
# 3. Pass your custom service to AuthService
|
||||
auth_router = create_app_router_for_sqlite(db_path="./UserDB", jwt_secret="THIS_NEEDS_TO_BE_CHANGED",
|
||||
email_service=email_service)
|
||||
auth_app = create_auth_app_for_sqlite(db_path="./UserDB", jwt_secret="THIS_NEEDS_TO_BE_CHANGED",
|
||||
email_service=email_service)
|
||||
|
||||
# 4. Include the authentication routes
|
||||
app.include_router(auth_router)
|
||||
app.mount("/auth", auth_app)
|
||||
|
||||
```
|
||||
|
||||
|
||||
Reference in New Issue
Block a user