feat(auth): add Google OAuth routes for CostGuard billing
This commit is contained in:
parent
83cef53f24
commit
5d42cd4383
33
main.py
33
main.py
|
|
@ -93,6 +93,39 @@ oauth.register(
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@app.get('/auth/login')
|
||||||
|
async def login(request: Request):
|
||||||
|
"""Redirects user to Google's OAuth 2.0 login page."""
|
||||||
|
redirect_uri = "https://opax.vauco.no/auth/callback"
|
||||||
|
return await oauth.google.authorize_redirect(request, redirect_uri)
|
||||||
|
|
||||||
|
@app.get('/auth/callback', name='auth')
|
||||||
|
async def auth(request: Request):
|
||||||
|
"""
|
||||||
|
Handles the callback from Google's OAuth.
|
||||||
|
Stores user info in session and redirects to the billing dashboard.
|
||||||
|
"""
|
||||||
|
token = await oauth.google.authorize_access_token(request)
|
||||||
|
user = token.get('userinfo')
|
||||||
|
if user:
|
||||||
|
request.session['user'] = dict(user)
|
||||||
|
return RedirectResponse(url='/static/billing-dashboard.html')
|
||||||
|
|
||||||
|
@app.get('/auth/me')
|
||||||
|
@require_auth
|
||||||
|
async def me(request: Request):
|
||||||
|
"""Returns the authenticated user's information."""
|
||||||
|
user = request.session.get('user')
|
||||||
|
return JSONResponse(user)
|
||||||
|
|
||||||
|
@app.get('/auth/logout')
|
||||||
|
async def logout(request: Request):
|
||||||
|
"""Clears the user session and logs them out."""
|
||||||
|
request.session.pop('user', None)
|
||||||
|
return RedirectResponse(url='/static/billing-dashboard.html')
|
||||||
|
|
||||||
|
|
||||||
# Allowed emails for login
|
# Allowed emails for login
|
||||||
ALLOWED_EMAILS = [email.strip() for email in os.environ.get("ALLOWED_EMAILS", "").split(",") if email.strip()]
|
ALLOWED_EMAILS = [email.strip() for email in os.environ.get("ALLOWED_EMAILS", "").split(",") if email.strip()]
|
||||||
ALERT_EMAIL = os.environ.get("ALERT_EMAIL")
|
ALERT_EMAIL = os.environ.get("ALERT_EMAIL")
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user