Skip to content
This repository has been archived by the owner on Mar 22, 2021. It is now read-only.

No error raised when key is missing #212

Open
d-Pixie opened this issue Apr 27, 2018 · 2 comments · May be fixed by #261
Open

No error raised when key is missing #212

d-Pixie opened this issue Apr 27, 2018 · 2 comments · May be fixed by #261

Comments

@d-Pixie
Copy link

d-Pixie commented Apr 27, 2018

Just started a new Rails (5.2) API app using Knock and copied some setup from an existing project. Couldn't get it to work, I got a TypeError (no implicit conversion of nil into String): from jwt (1.5.6) lib/jwt.rb:80:in 'digest'.

When my brain caught up I realised that I had not set a secret_key_base in config/secrets.yml. Adding one solved the problem but it would have been even better if Knock warned us if we are trying to run without keys :)

Thanks for a great gem.

@serco-chen
Copy link

@d-Pixie add this line in config/initializers/knock.rb

config.token_secret_signature_key = -> { Rails.application.credentials.fetch(:secret_key_base) }

@JoshCheek
Copy link

I agree that it would be nice if the lib would check that it's not nil, I was similarly confused. Also, I think it's supposed to be Rails.application.secret_key_base, otherwise I'm pretty sure you'll wind up using the same key in dev and test as you do in prod.

We can see that it will choose a different value for test and dev, and will allow for environment vairable overriding in production, but then fall back to the credentials.secret_key_base suggested above:

https://github.com/rails/rails/blob/d7f48c9c39befaf23ccd63e0248a3bd5bf295ee5/railties/lib/rails/application.rb#L428-L436

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
3 participants