Skip to content

Commit

Permalink
Magical
Browse files Browse the repository at this point in the history
  • Loading branch information
Josh-XT committed May 9, 2024
1 parent 3c0285c commit 9bf43e3
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
6 changes: 6 additions & 0 deletions MagicalAuth.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from DB import User, get_session
import os
import pyotp
import requests
from datetime import datetime
from fastapi import HTTPException
from gtauthclient import GTAuthClient
Expand All @@ -21,6 +22,7 @@
- SENDGRID_FROM_EMAIL: Default email address to send emails from
- ENCRYPTION_SECRET: Encryption key for the GTAuthClient
- MAGIC_LINK_URL: URL to send in the email for the user to click on
- REGISTRATION_WEBHOOK: URL to send a POST request to when a user registers
"""


Expand Down Expand Up @@ -125,6 +127,10 @@ def register(
session.add(user)
session.commit()
session.close()
# Send registration webhook out to third party application such as AGiXT to create a user there.
registration_webhook = os.environ.get("REGISTRATION_WEBHOOK", "")
if registration_webhook:
requests.post(registration_webhook, json={"email": self.email})
# Return mfa_token for QR code generation
return mfa_token

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ MagicalAuth is a simple but magical authentication system for Python application
- `MAGIC_LINK_URL`: The URL that the magic link will point to. This should be the URL of the application that will handle the magic link. It will send query parameters `email` and `token` to this URL that will be used on the `/login` endpoint to authenticate the user.
- `SENDGRID_API_KEY`: The API key for SendGrid. This is used to send the magic link email to the user.
- `SENDGRID_FROM_EMAIL`: The email address that the magic link email will be sent from. This should be a verified email address in SendGrid.
- `REGISTRATION_WEBHOOK`: The URL that the registration webhook will be sent to. This should be the URL of the application that will handle the registration webhook. It will send a POST request with a JSON body containing the user's email address.

## Usage

Expand Down
3 changes: 2 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ services:
volumes:
- ./data:/var/lib/postgresql/data
magicalauth:
image: ghcr.io/gt-ngpt/magicalauth:main
image: ghcr.io/devxt-llc/magicalauth:main
init: true
depends_on:
- magicalauthdb
Expand All @@ -26,6 +26,7 @@ services:
SENDGRID_API_KEY: ${SENDGRID_API_KEY}
SENDGRID_FROM_EMAIL: ${SENDGRID_FROM_EMAIL}
MAGIC_LINK_URL: ${MAGIC_LINK_URL}
REGISTRATION_WEBHOOK: ${REGISTRATION_WEBHOOK}
UVICORN_WORKERS: 5
LOGLEVEL: INFO
restart: always
Expand Down

0 comments on commit 9bf43e3

Please sign in to comment.