"""Auth Microservice. The auth microservice is responsible for creating a token for a user / login and password combinaison everytime a user succesfully logs in. In addition of creating the token, the service is also responsible for making sure it is still active and valid. When Grass receives a request with the data for client, user and token, it performs an additional request to ows-auth to confirm all those information are valid, and the token is still active. """ from typing import List from ddtrace import tracer from jwtauth.exceptions import JWTAuthError from jwtauth.utils import jwt_auth_from_environment from grass import config @tracer.wrap() def validate_auth0_token(token: str, override_audience: List[str] = []): """Validate an Auth0 Token. Args: token (str): the jwt access token Returns: tuple: the user information, status and jwt payload """ message = None status = 200 payload = None try: jwt_auth = jwt_auth_from_environment(environment=config.environment) if override_audience: jwt_auth.audience = override_audience payload = jwt_auth.get_token(token) except JWTAuthError as err: message = f'Error with authentication token {err}' except Exception as err: message = f'Unable to parse authentication token {err}' if message: status = 401 return message, status, payload