import hashlib
import base64


def code_challenge(verifier):
    """
    Function to generate code challenge based on RFC spec.
    See: https://tools.ietf.org/html/rfc7636#section-4.2
    """

    digest = hashlib.sha256(verifier).digest()
    return base64.urlsafe_b64encode(digest).rstrip(b"=")