auth and minor fixes

This commit is contained in:
Igor Lobanov
2022-11-22 04:11:26 +01:00
parent 9215facb75
commit 8963781ca3
9 changed files with 30 additions and 15 deletions

View File

@@ -11,6 +11,7 @@ from auth.jwtcodec import JWTCodec
from auth.tokenstorage import TokenStorage
from base.exceptions import InvalidToken
from services.auth.users import UserStorage
from settings import SESSION_TOKEN_HEADER
class SessionToken:
@@ -48,10 +49,12 @@ class JWTAuthenticate(AuthenticationBackend):
async def authenticate(
self, request: HTTPConnection
) -> Optional[Tuple[AuthCredentials, AuthUser]]:
if "Auth" not in request.headers:
if SESSION_TOKEN_HEADER not in request.headers:
return AuthCredentials(scopes=[]), AuthUser(user_id=None)
token = request.headers.get("Auth", "")
token = request.headers.get(SESSION_TOKEN_HEADER, "")
try:
payload = await SessionToken.verify(token)
except Exception as exc:

View File

@@ -25,6 +25,8 @@ async def send_auth_email(user, token, lang="ru"):
"h:X-Mailgun-Variables": "{ \"token\": \"%s\" }" % token
}
print('[auth.email] payload: %r' % payload)
# debug
# print('http://localhost:3000/?modal=auth&mode=confirm-email&token=%s' % token)
response = requests.post(
api_url,
auth=("api", MAILGUN_API_KEY),