def __init__( self, authorizationUrl: str, tokenUrl: str, refreshUrl: Optional[str] = None, 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( authorizationCode={ "authorizationUrl": authorizationUrl, "tokenUrl": tokenUrl, "refreshUrl": refreshUrl, "scopes": scopes, } ) super().__init__( flows=flows, scheme_name=scheme_name, description=description, auto_error=auto_error, )
def __init__( self, issuer: str, audience: str, client_ids: list[str], scopes: Optional[dict[str, str]] = None, scheme_name: Optional[str] = None, description: Optional[str] = None, auto_error: Optional[bool] = True, ): # Parameters for JWT validation self.issuer = issuer.rstrip("/") self.audience = audience self.client_ids = client_ids # Flows and scopes for Swagger UI if not scopes: scopes = {} # Currently we only allow authorizationCode flow. Others can be added later. flows = OAuthFlowsModel( authorizationCode={ "authorizationUrl": f"{self.issuer}/v1/authorize", "tokenUrl": f"{self.issuer}/v1/token", "refreshUrl": f"{self.issuer}/v1/token", "scopes": scopes, }) self.model = OAuth2Model(flows=flows, description=description) self.scheme_name = scheme_name or self.__class__.__name__ self.auto_error = auto_error
def __init__( self, scheme_name: Optional[str] = None, auto_error: bool = True, ): flows = OAuthFlowsModel() super().__init__(flows=flows, scheme_name=scheme_name, auto_error=auto_error)
def __init__(self, *, flows: OAuthFlowsModel = OAuthFlowsModel(), scheme_name: str = None, auto_error: bool = True): self.model = OAuth2Model(flows=flows) self.scheme_name = scheme_name or self.__class__.__name__ self.auto_error = auto_error
def __init__(self, token_url: str, scheme_name: Optional[str] = None, scopes: Optional[dict] = None, auto_error: bool = True): if scopes is None: scopes = {} flows = OAuthFlowsModel(password=OAuthFlowPassword(tokenUrl=token_url, scopes=scopes)) super().__init__(flows=flows, scheme_name=scheme_name, auto_error=auto_error)
def __init__(self, *, flows: Union[OAuthFlowsModel, Dict[str, Dict[str, Any]]] = OAuthFlowsModel(), scheme_name: Optional[str] = None, auto_error: Optional[bool] = True): self.model = OAuth2Model(flows=flows) self.scheme_name = scheme_name or self.__class__.__name__ self.auto_error = auto_error
def __init__( self, tokenUrl: str, scheme_name: str = None, auto_error: bool = True, ): flows = OAuthFlowsModel(password={"tokenUrl": tokenUrl}) super().__init__(flows=flows, scheme_name=scheme_name, auto_error=auto_error)
def __init__( self, tokenUrl: str, scheme_name: Optional[str] = None, scopes: Optional[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)
def __init__(self, tokenUrl: str, scheme_name: str = None, scopes: dict = None): if not scopes: scopes = {} flows = OAuthFlowsModel(password={ "tokenUrl": tokenUrl, "scopes": scopes }) super().__init__(flows=flows, scheme_name=scheme_name)
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, )
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)
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)
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 }) # type: ignore super().__init__(flows=flows, scheme_name=scheme_name, auto_error=auto_error)
def __init__( self, authorizationUrl: str, tokenUrl: str, refreshUrl: str = None, scheme_name: str = None, scopes: 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)
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")
def __init__(self, *, flows: OAuthFlowsModel = OAuthFlowsModel(), scheme_name: str = None): self.model = OAuth2Model(flows=flows) self.scheme_name = scheme_name or self.__class__.__name__
def __init__(self, tokenUrl:str, scheme_name:str=None, scopes:dict=None, auto_error:bool=True, cookie_name="ACESS_TOKEN"): self.cookie_name = cookie_name if not scopes: scopes = {} flows = OAuthFlowsModel(password={"tokenUrl": tokenUrl, "scopes": scopes}) super().__init__(flows=flows, scheme_name=scheme_name, auto_error=auto_error)