From e84133364bd6c2c29641b4b0a02706a974b131f7 Mon Sep 17 00:00:00 2001 From: knst-kotov Date: Wed, 10 Nov 2021 16:46:16 +0300 Subject: [PATCH] fix oauth --- auth/oauth.py | 9 ++++++--- create_crt.sh | 24 ++++++++++++------------ settings.py | 3 ++- 3 files changed, 20 insertions(+), 16 deletions(-) diff --git a/auth/oauth.py b/auth/oauth.py index 3d71be48..87d427f2 100644 --- a/auth/oauth.py +++ b/auth/oauth.py @@ -1,10 +1,12 @@ from authlib.integrations.starlette_client import OAuth -from starlette.responses import PlainTextResponse +from starlette.responses import RedirectResponse + +from urllib.parse import quote_plus from auth.authorize import Authorize from auth.identity import Identity -from settings import OAUTH_CLIENTS +from settings import OAUTH_CLIENTS, OAUTH_CALLBACK_URL oauth = OAuth() @@ -81,4 +83,5 @@ async def oauth_authorize(request): } user = Identity.identity_oauth(user_input) token = await Authorize.authorize(user, device="pc") - return PlainTextResponse(token) + redirect_uri = "%s?token=%s" % (OAUTH_CALLBACK_URL, quote_plus(token)) + return RedirectResponse(url = redirect_uri) diff --git a/create_crt.sh b/create_crt.sh index 0bd7c54e..6d0f4a28 100644 --- a/create_crt.sh +++ b/create_crt.sh @@ -1,12 +1,12 @@ -#!/bin/bash - -openssl req -newkey rsa:4096 \ - -x509 \ - -sha256 \ - -days 3650 \ - -nodes \ - -out discours.crt \ - -keyout discours.key \ - -subj "/C=RU/ST=Moscow/L=Moscow/O=Discours/OU=Site/CN=build.discours.io" - -openssl x509 -in discours.crt -out discours.pem -outform PEM +#!/bin/bash + +openssl req -newkey rsa:4096 \ + -x509 \ + -sha256 \ + -days 3650 \ + -nodes \ + -out discours.crt \ + -keyout discours.key \ + -subj "/C=RU/ST=Moscow/L=Moscow/O=Discours/OU=Site/CN=build.discours.io" + +openssl x509 -in discours.crt -out discours.pem -outform PEM diff --git a/settings.py b/settings.py index 9dee1051..dc921bb5 100644 --- a/settings.py +++ b/settings.py @@ -3,7 +3,8 @@ from os import environ PORT = 8080 -BACKEND_URL = "https://localhost:8080" +BACKEND_URL = environ.get("BACKEND_URL") or "https://localhost:8080" +OAUTH_CALLBACK_URL = environ.get("OAUTH_CALLBACK_URL") or "https://localhost:8080/authorized" DB_URL = environ.get("DATABASE_URL") or environ.get("DB_URL") or "sqlite:///db.sqlite3" JWT_ALGORITHM = "HS256"