Class: RippleToken::Token
- Inherits:
-
Object
- Object
- RippleToken::Token
- Defined in:
- lib/ripple_token/token.rb
Instance Method Summary collapse
- #decode(token) ⇒ Object
-
#initialize(public_key) ⇒ Token
constructor
A new instance of Token.
- #public_path?(method, path) ⇒ Boolean
Constructor Details
#initialize(public_key) ⇒ Token
5 6 7 |
# File 'lib/ripple_token/token.rb', line 5 def initialize(public_key) @public_key = public_key end |
Instance Method Details
#decode(token) ⇒ Object
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/ripple_token/token.rb', line 9 def decode(token) decoded_token = JWT.decode(token, public_key, true, { algorithm: 'RS256' })[0] raise ExpiredTokenError if expired? decoded_token decoded_token rescue JWT::DecodeError => e raise TokenDecodeError, e. rescue JWT::ExpiredSignature => e raise ExpiredTokenError, e. end |
#public_path?(method, path) ⇒ Boolean
20 21 22 23 24 25 26 |
# File 'lib/ripple_token/token.rb', line 20 def public_path?(method, path) return false if Client.public_paths.nil? || Client.public_paths.empty? return true if Client.public_paths[method]&.select { |p| path[p] }&.any? false end |