error with python and python-jose in lambda function

3.1k Views Asked by At

I am somewhat new to python and have never used it before to verify jwt tokens.

I'm writing a lambda function. I'm sure the issue is something simple but can't seem to get around it.

I keep getting this error:

{
  "errorType": "JWTError",
  "errorMessage": "Error decoding token headers.",
  "stackTrace": [
    "  File \"/var/task/index.py\", line 43, in handler\n    claims = token_verifier(keys, token)\n",
    "  File \"/var/task/index.py\", line 74, in token_verifier\n    headers = jwt.get_unverified_headers(token)\n",
    "  File \"/var/task/jose/jwt.py\", line 193, in get_unverified_headers\n    return get_unverified_header(token)\n",
    "  File \"/var/task/jose/jwt.py\", line 173, in get_unverified_header\n    raise JWTError('Error decoding token headers.')\n"
  ]
}

I am creating a virtual envrionment on my Mac for 3.7 and have a pretty simple requirements.txt file:

python-jose
configparser
ecdsa
future
pyasn1
rsa
six
urllib3

My code blows up on this 1st line:

    headers = jwt.get_unverified_headers(token)
    kid = headers['kid']

...

It doesn't matter what the actual token value is, it's obviously an issue with the way I'm using the libraries. Probably some incompatibility. I've googled and have not seen anyone else having this issue so it must be something really stupid I'm doing :)

Can someone please help? Thanks.

1

There are 1 best solutions below

1
On BEST ANSWER

The error is coming because the structure of your token is invalid. The token should be in the form of this abc.abc.abc. Header, Payload and Signature separated by 3 dots.