Skip to content

Inconsistent handling of payload claim data types #282

@jamesstonehill

Description

@jamesstonehill

When passing in a Time object as the value of the exp claim, if the key of the payload is a string it raises a JWT::InvalidPayload error. When using the symbol as the key, it does not raise the error.

When the exp claim key is a string

exp_payload = { 'exp' => Time.now }
token = JWT.encode exp_payload, 'asdf'
# => JWT::InvalidPayload: exp claim must be an integer

When the exp claim key is a symbol

exp_payload = { exp: Time.now }
token = JWT.encode exp_payload, 'asdf'
# => "eyJhbGciOiJIUzI1NiJ9.eyJleHAiOiIyMDE4LTA5LTA3IDEzOjA3OjU0ICswMTAwIn0.9PxmdZFISuVXQQTDA6bw4vavK428o0R1WvcIZ5np6Lg"

Symbol and string keys in the payload should be handle in a consistent way.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions