Created
November 11, 2018 12:47
-
-
Save addic/2772c2eadb5d7f719053792568a998e5 to your computer and use it in GitHub Desktop.
Ruby on Rails JWT wrapper class
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class JsonWebToken | |
ALGORITHM = 'HS256'.freeze | |
def self.encode(payload) | |
JWT.encode( | |
payload, | |
secret, | |
ALGORITHM | |
) | |
end | |
def self.decode(token) | |
JWT.decode( | |
token, | |
secret, | |
true, | |
algorithm: ALGORITHM | |
).first | |
end | |
def self.secret | |
Rails.application.secrets.secret_key_base | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment