import config from auth.atlas.atlas_token_decoder import AtlasTokenDecoder from auth.atlas.models import AtlasM2MTokenSchema from utils.json_encoder import DataclassDictionaryDecoder from utils.exceptions import Unauthorized class AtlasM2MAuthService: token = None atlas_token_decoder = AtlasTokenDecoder() def __init__(self, token): self.token = token def authorize(self): payload = self.atlas_token_decoder.decode( self.token, schema=AtlasM2MTokenSchema, issuer=config.ATLAS_M2M_TOKEN_ISSUER, options={"verify_aud": False}, ) self.__validate_payload(payload) def __validate_payload(self, token_data): if not token_data.aud or token_data.aud != config.DECIBEL_M2M_ATLAS_BRIDGE_AUDIENCE: raise Unauthorized("Incorrect audience") return True