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.
- .secret_key_base ⇒ Object
-
.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”
18 19 20 |
# File 'lib/rails_jwt_auth/jwt/manager.rb', line 18 def self.decode(token) JWT.decode(token, secret_key_base) end |
.encode(payload) ⇒ Object
Encodes and signs JWT Payload with expiration
11 12 13 14 |
# File 'lib/rails_jwt_auth/jwt/manager.rb', line 11 def self.encode(payload) payload.reverse_merge!() JWT.encode(payload, secret_key_base) end |
.expired?(payload) ⇒ Boolean
Validates if the token is expired by exp parameter
36 37 38 |
# File 'lib/rails_jwt_auth/jwt/manager.rb', line 36 def self.expired?(payload) Time.at(payload['exp']) < Time.now end |
.meta ⇒ Object
Default options to be encoded in the token
28 29 30 31 32 33 |
# File 'lib/rails_jwt_auth/jwt/manager.rb', line 28 def self. { exp: RailsJwtAuth.jwt_expiration_time.from_now.to_i, iss: RailsJwtAuth.jwt_issuer } end |
.secret_key_base ⇒ Object
6 7 8 |
# File 'lib/rails_jwt_auth/jwt/manager.rb', line 6 def self.secret_key_base Rails.application.secrets.secret_key_base || Rails.application.credentials.secret_key_base end |
.valid_payload?(payload) ⇒ Boolean
Validates the payload hash for expiration and meta claims
23 24 25 |
# File 'lib/rails_jwt_auth/jwt/manager.rb', line 23 def self.valid_payload?(payload) payload && !expired?(payload) && payload['iss'] == [:iss] end |