Fix #36: fix token url in auto doc (#38)

* Fix #36: fix token url in auto doc

* Define OAuth scheme in authentication base with default /users/login tokenUrl
* Allow to override it through contructor argument of auth class

* Fix test coverage of BaseAuthentication
This commit is contained in:
François Voron
2019-11-03 09:20:16 +01:00
committed by GitHub
parent 6f8bf57d0a
commit 47ad4ce1cc
3 changed files with 25 additions and 10 deletions

View File

@ -1,6 +1,7 @@
from typing import Callable
from fastapi import HTTPException
from fastapi.security import OAuth2PasswordBearer
from starlette import status
from starlette.responses import Response
@ -15,8 +16,20 @@ class BaseAuthentication:
Base adapter for generating and decoding authentication tokens.
Provides dependency injectors to get current active/superuser user.
:param scheme: Optional authentication scheme for OpenAPI.
Defaults to `OAuth2PasswordBearer(tokenUrl="/users/login")`.
Override it if your login route lives somewhere else.
"""
scheme: OAuth2PasswordBearer
def __init__(self, scheme: OAuth2PasswordBearer = None):
if scheme is None:
self.scheme = OAuth2PasswordBearer(tokenUrl="/users/login")
else:
self.scheme = scheme
async def get_login_response(self, user: BaseUserDB, response: Response):
raise NotImplementedError()