import base64 import hashlib import hmac import json import logging from typing import Any def verify_northpass_authorization(auth_token: str, request_data: dict) -> bool: """ Verifies that the authorization token is valid. Args: auth_token: The authorization token provided from Northpass request_data: The data provided by Northpass Returns: True if the authorization token is valid or False if not """ asm_northpass_secret = "EXAMPLE-SECRET".encode("utf-8") encoded_body = json.dumps(request_data.__dict__, separators=(",", ":")).encode("utf-8") asm_hash = hmac.new(key=asm_northpass_secret, msg=encoded_body, digestmod=hashlib.sha256).digest() return auth_token == base64.b64encode(asm_hash).decode("utf-8")