Skip to content

Commit

Permalink
Merge branch 'master' of github.com:freenit-framework/backend
Browse files Browse the repository at this point in the history
  • Loading branch information
mekanix committed Feb 12, 2022
2 parents da61ad0 + 74ab141 commit ad4e148
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 12 deletions.
12 changes: 11 additions & 1 deletion bin/freenit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@ if [ -z "${TYPE}" ]; then
help >&2
exit 1
fi

case "${TYPE}" in
project|backend|react|svelte)
;;
*)
help >&2
exit 1
;;
esac
shift

NAME="${1}"
Expand Down Expand Up @@ -494,4 +503,5 @@ EOF
echo "DEVEL_MODE = YES" >vars.mk
}

project

${TYPE}
4 changes: 2 additions & 2 deletions freenit/api/auth.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from ..auth import cookieAuthentication, fastapiUsers
from ..auth import authBackend, fastapiUsers
from ..config import getConfig
from .router import api

config = getConfig()

tags = ["auth"]
api.include_router(fastapiUsers.get_auth_router(cookieAuthentication), prefix="/auth", tags=tags)
api.include_router(fastapiUsers.get_auth_router(authBackend), prefix="/auth", tags=tags)
api.include_router(fastapiUsers.get_register_router(), prefix="/auth", tags=tags)
api.include_router(fastapiUsers.get_reset_password_router(), prefix="/auth", tags=tags)
api.include_router(fastapiUsers.get_verify_router(), prefix="/auth", tags=tags)
19 changes: 11 additions & 8 deletions freenit/auth.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
from fastapi import Depends
from fastapi_users import BaseUserManager, FastAPIUsers
from fastapi_users.authentication import CookieAuthentication
from fastapi_users.authentication import AuthenticationBackend, CookieTransport, JWTStrategy
from fastapi_users.db import OrmarUserDatabase

from .config import getConfig

config = getConfig()
auth = config.get_user()
cookieAuthentication = CookieAuthentication(
secret=config.secret,
lifetime_seconds=3600,
cookie_secure=config.cookie_secure,
)
authBackends = [cookieAuthentication]
cookie_transport = CookieTransport(cookie_max_age=3600,cookie_httponly=True)

def get_jwt_strategy() -> JWTStrategy:
return JWTStrategy(secret=config.secret, lifetime_seconds=3600)

authBackend = AuthenticationBackend(
name="freenit",
transport=cookie_transport,
get_strategy=get_jwt_strategy,
)

class UserManager(BaseUserManager[auth.UserCreate, auth.UserDB]):
user_db_model = auth.UserDB
Expand All @@ -31,7 +34,7 @@ def get_user_manager(user_db: OrmarUserDatabase = Depends(get_user_db)):

fastapiUsers = FastAPIUsers(
get_user_manager,
authBackends,
[authBackend],
auth.User,
auth.UserCreate,
auth.UserUpdate,
Expand Down
2 changes: 1 addition & 1 deletion freenit/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version = "0.2.16"
version = "0.2.18"
2 changes: 2 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@
"isort",
],
"test": [
"black",
"isort",
"pytest-asyncio",
"pytest-factoryboy",
],
Expand Down

0 comments on commit ad4e148

Please sign in to comment.