I'm trying to implement authorization in my cloudfront distribution. It has worked so far until I ran into size limitation. I'm now running into the cloudfront error message Max allowed: 1048576
, which is roughly ~1MB. But after installing the authlib
package the total size is around 6MB. My method for validating tokens look roughly like this:
from authlib.jose import JsonWebToken
jwk = get_jwk()
claims_options = {
"iss": {"essential": True, "value": ISSUER},
"aud": {"essential": True, "value": AUDIENCE}
}
jwt = JsonWebToken()
claims = jwt.decode(token, jwk, claims_options=claims_options)
claims.validate()
The whole thing works beautifully until the size limitation.
My ideas to get around this are:
- Find another package than authlib that is smaller/more efficient.
- Write my own code which validates hash signature of JWT (get around the need for authlib package).
- Write the Lambda in javascript to leverage the NodeJSfunction, which according to docs are efficient in packaging the lambda. In the hopes of that its enough.
Perhaps there are more alternatives, but these are the ones I could come up with which are desirable in descending order. Requesting assistance on either of these options or perhaps totally different solution.