Skip to content

Commit

Permalink
Get noauth user from DB
Browse files Browse the repository at this point in the history
  • Loading branch information
davidbrochart committed Sep 21, 2021
1 parent ba6a2ba commit 9431b94
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 14 deletions.
16 changes: 11 additions & 5 deletions plugins/auth/fps_auth/backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@
from .db import secret, get_user_db


NOAUTH_EMAIL = "[email protected]"
NOAUTH_USER = UserDB(
id="d4ded46b-a4df-4b51-8d83-ae19010272a7",
email=NOAUTH_EMAIL,
hashed_password="",
)


class NoAuth(SecurityBase):
def __call__(self):
return "noauth"
Expand All @@ -29,13 +37,11 @@ def __init__(self, user: UserDB, name: str = "noauth"):
self.scheme = NoAuth()

async def __call__(self, credentials, user_manager):
# always return the user no matter what
return self.user
noauth_user = await user_manager.user_db.get_by_email(NOAUTH_EMAIL)
return noauth_user or self.user


noauth_email = "[email protected]"
noauth_user = UserDB(email=noauth_email, hashed_password="")
noauth_authentication = NoAuthAuthentication(noauth_user)
noauth_authentication = NoAuthAuthentication(NOAUTH_USER)


class UserManager(BaseUserManager[UserCreate, UserDB]):
Expand Down
19 changes: 10 additions & 9 deletions plugins/auth/fps_auth/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@

from .config import get_auth_config
from .db import user_db, secret, database, engine, UserTable
from .backends import users, current_user, cookie_authentication, noauth_email
from .backends import (
users,
current_user,
cookie_authentication,
NOAUTH_USER,
NOAUTH_EMAIL,
)
from .models import (
User,
UserDB,
Expand Down Expand Up @@ -68,14 +74,9 @@ async def shutdown():


async def create_noauth_user():
user = await user_db.get_by_email(noauth_email)
if user is None:
user = UserDB(
id="d4ded46b-a4df-4b51-8d83-ae19010272a7",
email=noauth_email,
hashed_password="",
)
await user_db.create(user)
noauth_user = await user_db.get_by_email(NOAUTH_EMAIL)
if noauth_user is None:
await user_db.create(NOAUTH_USER)


async def create_token_user():
Expand Down

0 comments on commit 9431b94

Please sign in to comment.