Skip to content

Instantly share code, notes, and snippets.

@addic
Created November 11, 2018 12:47
Show Gist options
  • Save addic/2772c2eadb5d7f719053792568a998e5 to your computer and use it in GitHub Desktop.
Save addic/2772c2eadb5d7f719053792568a998e5 to your computer and use it in GitHub Desktop.
Ruby on Rails JWT wrapper class
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