def _get_backend_user(name: str = "user"):
     return AuthenticationBackend(
         name=name,
         transport=MockTransport(),
         get_strategy=lambda: UserStrategy(user),
     )
Exemple #2
0
from fastapi_users.authentication import (
    AuthenticationBackend,
    BearerTransport,
    JWTStrategy,
)

SECRET = "SECRET"

bearer_transport = BearerTransport(tokenUrl="auth/jwt/login")


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


authentication_backend = AuthenticationBackend(
    name="jwt",
    transport=bearer_transport,
    get_strategy=get_jwt_strategy,
)
 def _get_backend_none(name: str = "none"):
     return AuthenticationBackend(name=name,
                                  transport=MockTransport(),
                                  get_strategy=lambda: NoneStrategy())
async def test_logout(backend: AuthenticationBackend, user: UserDB):
    strategy = cast(Strategy, backend.get_strategy())
    result = await backend.logout(strategy, user, "TOKEN", Response())
    assert result is None
def backend(transport: Transport,
            get_strategy: Callable[..., Strategy]) -> AuthenticationBackend:
    return AuthenticationBackend(name="mock",
                                 transport=transport,
                                 get_strategy=get_strategy)
Exemple #6
0
def get_mock_authentication(name: str):
    return AuthenticationBackend(
        name=name,
        transport=MockTransport(tokenUrl="/login"),
        get_strategy=lambda: MockStrategy(),
    )
Exemple #7
0
from fastapi_users.db import OrmarUserDatabase

from .config import getConfig

config = getConfig()
auth = config.get_user()
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
    reset_password_token_secret = config.secret
    verification_token_secret = config.secret


def get_user_db():
    yield OrmarUserDatabase(auth.UserDB, auth.UserModel)


def get_user_manager(user_db: OrmarUserDatabase = Depends(get_user_db)):