module RailsJwtAuth::JwtManager

Public Class Methods

decode(token) click to toggle source

Decodes the JWT with the signed secret

{“auth_token”=>“xxx”, “exp”=>148…, “iss”=>“RJA”}, {“typ”=>“JWT”, “alg”=>“HS256”}
# File lib/rails_jwt_auth/jwt_manager.rb, line 19
def self.decode(token)
  JWT.decode(token, secret_key_base)
end
encode(payload) click to toggle source

Encodes and signs JWT Payload with expiration

# File lib/rails_jwt_auth/jwt_manager.rb, line 10
def self.encode(payload)
  raise InvalidJwtPayload unless payload

  payload.reverse_merge!(meta)
  JWT.encode(payload, secret_key_base)
end
meta() click to toggle source

Default options to be encoded in the token

# File lib/rails_jwt_auth/jwt_manager.rb, line 24
def self.meta
  {
    exp: RailsJwtAuth.jwt_expiration_time.from_now.to_i,
    iss: RailsJwtAuth.jwt_issuer
  }
end
secret_key_base() click to toggle source
# File lib/rails_jwt_auth/jwt_manager.rb, line 5
def self.secret_key_base
  Rails.application.secrets.secret_key_base || Rails.application.credentials.secret_key_base
end