Class: JWTSessions::Token
- Inherits:
-
Object
- Object
- JWTSessions::Token
- Defined in:
- lib/jwt_sessions/token.rb
Constant Summary collapse
- DECODE_ERROR =
"cannot decode the token"
Class Method Summary collapse
- .decode(token, claims = {}) ⇒ Object
- .decode!(token) ⇒ Object
- .encode(payload) ⇒ Object
- .meta ⇒ Object
Class Method Details
.decode(token, claims = {}) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/jwt_sessions/token.rb', line 15 def decode(token, claims = {}) = { algorithm: JWTSessions.algorithm }.merge(JWTSessions.).merge(claims) JWT.decode(token, JWTSessions.public_key, JWTSessions.validate?, ) rescue JWT::ExpiredSignature => e raise Errors::Expired, e. rescue JWT::InvalidIssuerError, JWT::InvalidIatError, JWT::InvalidAudError, JWT::InvalidSubError, JWT::InvalidJtiError => e raise Errors::ClaimsVerification, e. rescue JWT::DecodeError => e raise Errors::Unauthorized, e. rescue StandardError raise Errors::Unauthorized, DECODE_ERROR end |
.decode!(token) ⇒ Object
28 29 30 31 32 33 |
# File 'lib/jwt_sessions/token.rb', line 28 def decode!(token) = { algorithm: JWTSessions.algorithm } JWT.decode(token, JWTSessions.public_key, false, ) rescue StandardError raise Errors::Unauthorized, DECODE_ERROR end |
.encode(payload) ⇒ Object
10 11 12 13 |
# File 'lib/jwt_sessions/token.rb', line 10 def encode(payload) exp_payload = .merge(payload) JWT.encode(exp_payload, JWTSessions.private_key, JWTSessions.algorithm) end |
.meta ⇒ Object
35 36 37 |
# File 'lib/jwt_sessions/token.rb', line 35 def { "exp" => JWTSessions.access_expiration } end |