Class: AtomicAdmin::JwtToken::SecretDecoder
- Inherits:
-
Object
- Object
- AtomicAdmin::JwtToken::SecretDecoder
- Defined in:
- lib/atomic_admin/jwt_token/secret_decoder.rb
Overview
Decodes a JWT token using a known secret. This is used for decoding JWT tokens issued by the application itself for the old admin app
Constant Summary collapse
- ALGORITHM =
"HS512".freeze
Instance Method Summary collapse
- #decode(token, validate = true) ⇒ Object
- #decode!(token) ⇒ Object
-
#initialize(secret, algorithm = ALGORITHM) ⇒ SecretDecoder
constructor
A new instance of SecretDecoder.
Constructor Details
#initialize(secret, algorithm = ALGORITHM) ⇒ SecretDecoder
Returns a new instance of SecretDecoder.
7 8 9 10 |
# File 'lib/atomic_admin/jwt_token/secret_decoder.rb', line 7 def initialize(secret, algorithm = ALGORITHM) @secret = secret @algorithm = algorithm end |
Instance Method Details
#decode(token, validate = true) ⇒ Object
12 13 14 15 16 17 18 19 |
# File 'lib/atomic_admin/jwt_token/secret_decoder.rb', line 12 def decode(token, validate = true) JWT.decode( token, @secret, validate, { algorithm: @algorithm }, ) end |
#decode!(token) ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/atomic_admin/jwt_token/secret_decoder.rb', line 21 def decode!(token) token = decode(token) raise AtomicAdmin::JwtToken::InvalidTokenError, "Unable to decode jwt token" if token.blank? raise AtomicAdmin::JwtToken::InvalidTokenError, "Invalid token payload" if token.empty? token[0] end |