Module: RailsJwtAuth::JwtManager

Defined in:
lib/rails_jwt_auth/jwt_manager.rb

Class Method Summary collapse

Class Method Details

.decode(token) ⇒ Object

Decodes the JWT with the signed secret

“exp”=>148…, “iss”=>“RJA”, “alg”=>“HS256”


19
20
21
# File 'lib/rails_jwt_auth/jwt_manager.rb', line 19

def self.decode(token)
  JWT.decode(token, secret_key_base)
end

.encode(payload) ⇒ Object

Encodes and signs JWT Payload with expiration

Raises:



10
11
12
13
14
15
# 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

.metaObject

Default options to be encoded in the token



24
25
26
27
28
29
# 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_baseObject



5
6
7
# 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