imagekit-developer/imagekit-python

Wrong auth parameters

Closed this issue · 1 comments

get_authenticated_params implementation is wrong. The default value of token should be calculated before calculating the signature. If the function is not passed token then signature is calculated using an empty string but response returns a random generated token value.

    default_expire = int(dt.now().strftime("%s")) + DEFAULT_TIME_DIFF
    auth_params = {"token": token, "expire": expire, "signature": ""}

    if not private_key:
        return
    signature = hmac.new(
        key=private_key.encode(),
        msg=(token + str(expire)).encode(),
        digestmod=hashlib.sha1,
    ).hexdigest()

    auth_params["token"] = token or str(uuid.uuid4())
    auth_params["expire"] = expire or default_expire
    auth_params["signature"] = signature

    return auth_params

The issue has been fixed in v2.2.3