- if indata.get("username"):
- token, projects = self.backend.authenticate_with_user_password(
- indata.get("username"), indata.get("password"))
- elif session:
- token, projects = self.backend.authenticate_with_token(
- session.get("id"), indata.get("project_id"))
- else:
- raise AuthException("Provide credentials: username/password or Authorization Bearer token",
- http_code=HTTPStatus.UNAUTHORIZED)
-
- if indata.get("project_id"):
- project_id = indata.get("project_id")
- if project_id not in projects:
- raise AuthException("Project {} not allowed for this user".format(project_id),
- http_code=HTTPStatus.UNAUTHORIZED)
- else:
- project_id = projects[0]
-
- if not session:
- token, projects = self.backend.authenticate_with_token(token, project_id)
-
- if project_id == "admin":
- session_admin = True
- else:
- session_admin = reduce(lambda x, y: x or (True if y == "admin" else False),
- projects, False)
+ current_token = None
+ if session:
+ current_token = session.get("token")
+ token_info = self.backend.authenticate(
+ user=indata.get("username"),
+ password=indata.get("username"),
+ token=current_token,
+ project=indata.get("project_id")
+ )
+
+ # if indata.get("username"):
+ # token, projects = self.backend.authenticate_with_user_password(
+ # indata.get("username"), indata.get("password"))
+ # elif session:
+ # token, projects = self.backend.authenticate_with_token(
+ # session.get("id"), indata.get("project_id"))
+ # else:
+ # raise AuthException("Provide credentials: username/password or Authorization Bearer token",
+ # http_code=HTTPStatus.UNAUTHORIZED)
+ #
+ # if indata.get("project_id"):
+ # project_id = indata.get("project_id")
+ # if project_id not in projects:
+ # raise AuthException("Project {} not allowed for this user".format(project_id),
+ # http_code=HTTPStatus.UNAUTHORIZED)
+ # else:
+ # project_id = projects[0]
+ #
+ # if not session:
+ # token, projects = self.backend.authenticate_with_token(token, project_id)
+ #
+ # if project_id == "admin":
+ # session_admin = True
+ # else:
+ # session_admin = reduce(lambda x, y: x or (True if y == "admin" else False),
+ # projects, False)