Module: Slosilo
- Defined in:
- lib/slosilo/jwt.rb,
lib/slosilo/key.rb,
lib/slosilo/errors.rb,
lib/slosilo/random.rb,
lib/slosilo/version.rb,
lib/slosilo/keystore.rb,
lib/slosilo/symmetric.rb,
lib/slosilo/attr_encrypted.rb,
lib/slosilo/adapters/file_adapter.rb,
lib/slosilo/adapters/mock_adapter.rb,
lib/slosilo/adapters/memory_adapter.rb,
lib/slosilo/adapters/sequel_adapter.rb,
lib/slosilo/adapters/abstract_adapter.rb,
lib/slosilo/adapters/sequel_adapter/migration.rb
Defined Under Namespace
Modules: Adapters, EncryptedAttributes, Extension, Random
Classes: Error, JWT, Key, Keystore, Symmetric
Constant Summary
collapse
- VERSION =
"3.0.1"
Class Attribute Summary collapse
Class Method Summary
collapse
Class Attribute Details
.adapter ⇒ Object
Returns the value of attribute adapter.
82
83
84
|
# File 'lib/slosilo/keystore.rb', line 82
def adapter
@adapter
end
|
.encryption_key ⇒ Object
79
80
81
|
# File 'lib/slosilo/attr_encrypted.rb', line 79
def encryption_key
@encryption_key
end
|
Class Method Details
.[](id) ⇒ Object
46
47
48
|
# File 'lib/slosilo/keystore.rb', line 46
def [] id
keystore.get id
end
|
.[]=(id, value) ⇒ Object
42
43
44
|
# File 'lib/slosilo/keystore.rb', line 42
def []= id, value
keystore.put id, value
end
|
.each(&block) ⇒ Object
50
51
52
|
# File 'lib/slosilo/keystore.rb', line 50
def each(&block)
keystore.each(&block)
end
|
.JWT(raw) ⇒ Object
Try to convert by detecting token representation and parsing
111
112
113
114
115
116
117
118
119
120
121
|
# 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
|
.sign(object) ⇒ Object
54
55
56
|
# File 'lib/slosilo/keystore.rb', line 54
def sign object
self[:own].sign object
end
|
.token_signer(token) ⇒ Object
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.
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
# File 'lib/slosilo/keystore.rb', line 65
def token_signer token
begin
token = JWT token
fingerprint = token.['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) ⇒ Boolean
58
59
60
|
# File 'lib/slosilo/keystore.rb', line 58
def token_valid? token
keystore.any? { |k| k.token_valid? token }
end
|