Module: RailsJwtAuth::JwtManager
- Defined in:
- lib/rails_jwt_auth/jwt_manager.rb
Class Method Summary collapse
-
.decode(token) ⇒ Object
Decodes the JWT with the signed secret [“exp”=>148…, “iss”=>“RJA”, “alg”=>“HS256”].
- .decode_from_request(request) ⇒ Object
-
.encode(payload) ⇒ Object
Encodes and signs JWT Payload with expiration.
-
.meta ⇒ Object
Default options to be encoded in the token.
- .secret_key_base ⇒ Object
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!() JWT.encode(payload, secret_key_base) end |
.meta ⇒ Object
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. { exp: RailsJwtAuth.jwt_expiration_time.from_now.to_i, iss: RailsJwtAuth.jwt_issuer } end |
.secret_key_base ⇒ Object
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 |