Class: Lago::Api::Resources::Webhook
- Inherits:
-
Base
- Object
- Base
- Lago::Api::Resources::Webhook
show all
- Defined in:
- lib/lago/api/resources/webhook.rb
Instance Attribute Summary
Attributes inherited from Base
#client
Instance Method Summary
collapse
Methods inherited from Base
#create, #destroy, #get, #get_all, #initialize, #root_name, #update, #whitelist_params
Instance Method Details
#api_resource ⇒ Object
7
8
9
|
# File 'lib/lago/api/resources/webhook.rb', line 7
def api_resource
'webhooks'
end
|
#public_key ⇒ Object
11
12
13
14
15
16
|
# File 'lib/lago/api/resources/webhook.rb', line 11
def public_key
path = '/api/v1/webhooks/public_key'
webhooks_public_key = connection.get(path, identifier: nil)
OpenSSL::PKey::RSA.new(Base64.decode64(webhooks_public_key))
end
|
#valid_signature?(signature, webhook_payload, cached_key = public_key) ⇒ Boolean
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
# File 'lib/lago/api/resources/webhook.rb', line 18
def valid_signature?(signature, webhook_payload, cached_key = public_key)
decoded_signature = JWT.decode(
signature,
cached_key,
true,
{
algorithm: 'RS256',
iss: client.api_url || Lago::Api::BASE_URL,
verify_iss: true,
},
).first
decoded_signature['data'] == webhook_payload.to_json
rescue JWT::InvalidIssuerError, JWT::VerificationError
false
end
|