Class: Wor::Authentication::TokenManager
- Inherits:
-
Object
- Object
- Wor::Authentication::TokenManager
- Defined in:
- lib/wor/authentication/token_manager.rb
Instance Method Summary collapse
- #decode(token) ⇒ Object
- #encode(payload) ⇒ Object
-
#initialize(key) ⇒ TokenManager
constructor
A new instance of TokenManager.
Constructor Details
#initialize(key) ⇒ TokenManager
Returns a new instance of TokenManager.
6 7 8 |
# File 'lib/wor/authentication/token_manager.rb', line 6 def initialize(key) @key = key end |
Instance Method Details
#decode(token) ⇒ Object
14 15 16 17 18 19 |
# File 'lib/wor/authentication/token_manager.rb', line 14 def decode(token) payload = JWT.decode(token, @key)[0] Wor::Authentication::DecodedToken.new(payload) rescue raise Wor::Authentication::Exceptions::InvalidAuthorizationToken end |
#encode(payload) ⇒ Object
10 11 12 |
# File 'lib/wor/authentication/token_manager.rb', line 10 def encode(payload) JWT.encode(payload, @key) end |