import hashlib
import base64


def get_validation_hash(value: str) -> str:
    """
    Computes a hash value to be embedded in the ID Token, like at_hash and c_hash.

    Specification: https://openid.net/specs/openid-connect-core-1_0.html#toc
    """
    hasher = hashlib.sha256()
    hasher.update(value.encode("utf-8"))
    hash = hasher.digest()

    half_hash = hash[0 : int(len(hash) / 2)]
    # Remove the Base64 padding "==" at the end
    base64_hash = base64.urlsafe_b64encode(half_hash)[:-2]

    return base64_hash.decode("utf-8")