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”


17
18
19
# File 'lib/rails_jwt_auth/jwt_manager.rb', line 17

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

.decode_from_request(request) ⇒ Object



29
30
31
# File 'lib/rails_jwt_auth/jwt_manager.rb', line 29

def self.decode_from_request(request)
  decode(request.env['HTTP_AUTHORIZATION']&.split&.last)
end

.encode(payload) ⇒ Object

Encodes and signs JWT Payload with expiration



10
11
12
13
# File 'lib/rails_jwt_auth/jwt_manager.rb', line 10

def self.encode(payload)
  payload.reverse_merge!(meta)
  JWT.encode(payload, secret_key_base)
end

.metaObject

Default options to be encoded in the token



22
23
24
25
26
27
# File 'lib/rails_jwt_auth/jwt_manager.rb', line 22

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