ruby-jwt icon indicating copy to clipboard operation
ruby-jwt copied to clipboard

can't create token - 'NotImplementedError: Unsupported signing method'

Open Jpease1020 opened this issue 9 years ago • 5 comments

when I run this code,

payload = 'username'
hmac_secret = 'my$ecretK3y'
token = JWT.encode payload, hmac_secret, 'HS256'

I get this error JSON::GeneratorError: only generation of JSON objects or arrays allowed

I am using ruby version 2.3.0 in a rails 4.2.6 project

Jpease1020 avatar Jan 31 '17 16:01 Jpease1020

Your payload needs to be a hash.

payload = {
    username: 'username'
}

excpt avatar Jan 31 '17 17:01 excpt

I changed the payload to

payload = { username: 'username' }

and ran

payload = { username: 'username' }
hmac_secret = 'my$ecretK3y'
JWT.encode(payload, hmac_secret, "H256")

and I get this error

NotImplementedError: Unsupported signing method

Jpease1020 avatar Jan 31 '17 18:01 Jpease1020

@Jpease1020 Were you able to solve this? I am having same issue!

HimaChitalia avatar Aug 23 '17 10:08 HimaChitalia

@HimaChitalia

Have you checked for typos? Sometimes I catch myself fast typing H256 instead of HS256 or E512 instead of ES512.

excpt avatar Aug 24 '17 19:08 excpt

@HimaChitalia

Have you checked for typos? Sometimes I catch myself fast typing H256 instead of HS256 or E512 instead of ES512.

Great thanks!

GlenCorreia avatar May 05 '21 13:05 GlenCorreia