Class: RailsJwtAuth::Jwt::Manager
- Inherits:
-
Object
- Object
- RailsJwtAuth::Jwt::Manager
- 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”].
-
.encode(payload) ⇒ Object
Encodes and signs JWT Payload with expiration.
-
.expired?(payload) ⇒ Boolean
Validates if the token is expired by exp parameter.
-
.meta ⇒ Object
Default options to be encoded in the token.
-
.valid_payload?(payload) ⇒ Boolean
Validates the payload hash for expiration and meta claims.
Class Method Details
.decode(token) ⇒ Object
Decodes the JWT with the signed secret
- “exp”=>148…, “iss”=>“RJA”, “alg”=>“HS256”
14 15 16 |
# File 'lib/rails_jwt_auth/jwt/manager.rb', line 14 def self.decode(token) JWT.decode(token, Rails.application.secrets.secret_key_base) end |
.encode(payload) ⇒ Object
Encodes and signs JWT Payload with expiration
7 8 9 10 |
# File 'lib/rails_jwt_auth/jwt/manager.rb', line 7 def self.encode(payload) payload.reverse_merge!() JWT.encode(payload, Rails.application.secrets.secret_key_base) end |
.expired?(payload) ⇒ Boolean
Validates if the token is expired by exp parameter
32 33 34 |
# File 'lib/rails_jwt_auth/jwt/manager.rb', line 32 def self.expired?(payload) Time.at(payload['exp']) < Time.now end |
.meta ⇒ Object
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. { exp: RailsJwtAuth.jwt_expiration_time.from_now.to_i, iss: RailsJwtAuth.jwt_issuer } end |
.valid_payload?(payload) ⇒ Boolean
Validates the payload hash for expiration and meta claims
19 20 21 |
# File 'lib/rails_jwt_auth/jwt/manager.rb', line 19 def self.valid_payload?(payload) payload && !expired?(payload) && payload['iss'] == [:iss] end |