예제 #1
0
 def __init__(
     self,
     tokenUrl: str,
     scheme_name: str = None,
     scopes: dict = None,
     auto_error: bool = True,
 ):
     if not scopes:
         scopes = {}
     flows = OAuthFlowsModel(password={"tokenUrl": tokenUrl, "scopes": scopes})
     super().__init__(flows=flows, scheme_name=scheme_name, auto_error=auto_error)
예제 #2
0
 def __init__(
     self,
     tokenUrl: str,
     scheme_name: Optional[str] = None,
     description: Optional[str] = None,
     auto_error: bool = True,
 ):
     flows = OAuthFlowsModel(password={"tokenUrl": tokenUrl})
     super().__init__(
         flows=flows,
         scheme_name=scheme_name,
         description=description,
         auto_error=auto_error,
     )
예제 #3
0
 def __init__(
     self,
     token_url: str,
     refresh_url: str,
     scheme_name: str = None,
     scopes: Dict[str, str] = None,
     auto_error: bool = True,
 ):
     if not scopes:  # pragma: no cover
         scopes = {}
     flows = OAuthFlowsModel(password=OAuthFlowPassword(
         tokenUrl=token_url, refreshUrl=refresh_url, scopes=scopes))
     super(OAuth2PasswordBearer, self).__init__(flows=flows,
                                                scheme_name=scheme_name,
                                                auto_error=auto_error)
예제 #4
0
 def __init__(
     self,
     tokenUrl: str,
     scheme_name: Optional[str] = None,
     scopes: Optional[Dict[str, str]] = None,
     description: Optional[str] = None,
     auto_error: bool = True,
 ):
     if not scopes:
         scopes = {}
     flows = OAuthFlowsModel(password={"tokenUrl": tokenUrl, "scopes": scopes})
     super().__init__(
         flows=flows,
         scheme_name=scheme_name,
         description=description,
         auto_error=auto_error,
     )
예제 #5
0
 def __init__(
     self,
     authorizationUrl: str,
     tokenUrl: str,
     refreshUrl: Optional[str] = None,
     scheme_name: Optional[str] = None,
     scopes: Optional[dict] = None,
     auto_error: bool = True,
 ):
     if not scopes:
         scopes = {}
     flows = OAuthFlowsModel(
         authorizationCode={
             "authorizationUrl": authorizationUrl,
             "tokenUrl": tokenUrl,
             "refreshUrl": refreshUrl,
             "scopes": scopes,
         }
     )
     super().__init__(flows=flows, scheme_name=scheme_name, auto_error=auto_error)
예제 #6
0
    def __init__(
        self,
        authorizationUrl: str,
        tokenUrl: str,
        handler: MSALAuthCodeHandler,
        refreshUrl: Optional[str] = None,
        scopes: Optional[Dict[str, str]] = None,
    ):
        self.handler = handler
        if not scopes:
            scopes = {}
        self.scheme_name = self.__class__.__name__

        flows = OAuthFlowsModel(
            authorizationCode=OAuthFlowAuthorizationCode(
                authorizationUrl=authorizationUrl,
                tokenUrl=tokenUrl,
                scopes=scopes,
                refreshUrl=refreshUrl,
            )
        )
        # needs further investigation (type...)
        self.model = OAuth2Model(flows=flows, type=SecuritySchemeType.oauth2)
from fastapi.param_functions import Depends
from fastapi.security import OAuth2
from fastapi.security.utils import get_authorization_scheme_param
from jose import jwt
from jsonschema import ValidationError
from model.model.common.user import User
from starlette import status

from watchmen.auth.storage.user import load_user_by_name
from watchmen.common.security.index import validate_jwt
from watchmen.common.security.pat.pat_model import PersonAccessToken
from watchmen.common.security.pat.pat_service import verifyPAT
from watchmen_boot.config.config import settings

tokenUrl = f"{settings.API_V1_STR}/login/access-token"
flows = OAuthFlowsModel(password={"tokenUrl": tokenUrl, "scopes": {}})
reusable_oauth2 = OAuth2(flows=flows)


def get_current_user(authorization=Depends(reusable_oauth2)) -> User:
    scheme, token = get_authorization_scheme_param(authorization)
    username = get_username(scheme, token)

    user = load_user_by_name(username)

    if settings.DEFAULT_DATA_ZONE_ON:
        user.tenantId = "1"

    if not user:
        raise HTTPException(status_code=status.HTTP_401_UNAUTHORIZED,
                            detail="User not found")
예제 #8
0
 def __init__(self,
              *,
              flows: OAuthFlowsModel = OAuthFlowsModel(),
              scheme_name: str = None):
     self.model = OAuth2Model(flows=flows)
     self.scheme_name = scheme_name or self.__class__.__name__