module Slosilo
Constants
- VERSION
- adapter
Attributes
adapter[RW]
encryption_key[W]
Public Class Methods
JWT(raw)
click to toggle source
Try to convert by detecting token representation and parsing
# File lib/slosilo/jwt.rb, line 111 def self.JWT raw if raw.is_a? JWT raw elsif raw.respond_to?(:to_h) || raw =~ /\A\s*\{/ JWT.parse_json raw else JWT.parse_compact raw end rescue raise ArgumentError, "invalid value for JWT(): #{raw.inspect}" end
[](id)
click to toggle source
# File lib/slosilo/keystore.rb, line 46 def [] id keystore.get id end
[]=(id, value)
click to toggle source
# File lib/slosilo/keystore.rb, line 42 def []= id, value keystore.put id, value end
each(&block)
click to toggle source
# File lib/slosilo/keystore.rb, line 50 def each(&block) keystore.each(&block) end
encryption_key()
click to toggle source
# File lib/slosilo/attr_encrypted.rb, line 76 def encryption_key @encryption_key end
sign(object)
click to toggle source
# File lib/slosilo/keystore.rb, line 54 def sign object self[:own].sign object end
token_signer(token)
click to toggle source
Looks up the signer by public key fingerprint and checks the validity of the signature. If the token is JWT
, exp and/or iat claims are also verified; the caller is responsible for validating any other claims.
# File lib/slosilo/keystore.rb, line 65 def token_signer token begin # see if maybe it's a JWT token = JWT token fingerprint = token.header['kid'] rescue ArgumentError fingerprint = token['key'] end key, id = keystore.get_by_fingerprint fingerprint if key && key.token_valid?(token) return id else return nil end end
token_valid?(token)
click to toggle source
# File lib/slosilo/keystore.rb, line 58 def token_valid? token keystore.any? { |k| k.token_valid? token } end
Private Class Methods
keystore()
click to toggle source
# File lib/slosilo/keystore.rb, line 85 def keystore @keystore ||= Keystore.new end