Class: JwtAuthEngine::TokenService
- Inherits:
-
Object
- Object
- JwtAuthEngine::TokenService
- Defined in:
- app/services/jwt_auth_engine/token_service.rb
Overview
Encodes and decodes JWT access/refresh tokens for the engine.
Constant Summary collapse
- ACCESS_TYPE =
'access'- REFRESH_TYPE =
'refresh'- ALGORITHM =
'HS256'
Class Method Summary collapse
-
.decode_access(token) ⇒ Object
Decodes an access token.
-
.decode_refresh(token) ⇒ Object
Decodes a refresh token.
-
.encode_access(payload) ⇒ Object
Encodes an access token with the given payload.
-
.encode_refresh(payload) ⇒ Object
Encodes a refresh token with the given payload.
Class Method Details
.decode_access(token) ⇒ Object
Decodes an access token. Raises on invalid/expired token.
30 31 32 |
# File 'app/services/jwt_auth_engine/token_service.rb', line 30 def decode_access(token) decode(token, expected_type: ACCESS_TYPE) end |
.decode_refresh(token) ⇒ Object
Decodes a refresh token. Raises on invalid/expired token.
35 36 37 |
# File 'app/services/jwt_auth_engine/token_service.rb', line 35 def decode_refresh(token) decode(token, expected_type: REFRESH_TYPE) end |
.encode_access(payload) ⇒ Object
Encodes an access token with the given payload. Automatically adds exp and token_type.
16 17 18 19 |
# File 'app/services/jwt_auth_engine/token_service.rb', line 16 def encode_access(payload) exp = JwtAuthEngine.configuration.access_token_expiry.from_now.to_i encode(payload.merge(exp: exp, token_type: ACCESS_TYPE)) end |
.encode_refresh(payload) ⇒ Object
Encodes a refresh token with the given payload. Automatically adds exp and token_type.
22 23 24 25 |
# File 'app/services/jwt_auth_engine/token_service.rb', line 22 def encode_refresh(payload) exp = JwtAuthEngine.configuration.refresh_token_expiry.from_now.to_i encode(payload.merge(exp: exp, token_type: REFRESH_TYPE)) end |