Example #1
0
    async def authenticate(
        self, conn: HTTPConnection
    ) -> typing.Optional[typing.Tuple["AuthCredentials", "OdooUser"]]:
        if "Authorization" not in conn.headers:
            return

        auth = conn.headers["Authorization"]
        try:
            scheme, credentials = auth.split()
            if scheme.lower() != "basic":
                return
            decoded = b64decode(credentials).decode("ascii")
        except (ValueError, UnicodeDecodeError, binascii.Error):
            raise AuthenticationError("Invalid basic auth credentials")

        database, _, login, _, password = decoded.partition(":")
        try:
            uid = odoo.Authentication().authenticate(database, login, password)
            scopes = ["authenticated", database]
            return AuthCredentials(scopes), OdooUser(login, database, uid)
        except odoo.Exceptions().AccessDenied:
            return AuthCredentials(), UnauthenticatedUser()
 async def _(request: Request):
     pair = await backend.authenticate(request)
     if pair is None:
         pair = AuthCredentials(), UnauthenticatedUser()
     request.scope["auth"], request.scope["user"] = pair
Example #3
0
 async def authenticate(self, request):
     state = self.check(request)
     if state is None:
         return AuthCredentials([]), UnauthenticatedUser()
     return state.credentials, state.authenticated_user
Example #4
0
 def authenticated_user(self):
     if self.is_authenticated() and self.user:
         if isinstance(self.user, User):
             return SimpleUser(self.user.email)
     return UnauthenticatedUser()