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, #update, #whitelist_params
Instance Method Details
#api_resource ⇒ Object
9
10
11
|
# File 'lib/lago/api/resources/webhook.rb', line 9
def api_resource
'webhooks'
end
|
#public_key ⇒ Object
17
18
19
20
21
22
23
24
25
|
# File 'lib/lago/api/resources/webhook.rb', line 17
def public_key
path = '/api/v1/webhooks/json_public_key'
response = connection.get(path, identifier: nil)[root_name]
webhook_details = JSON.parse(response.to_json, object_class: OpenStruct)
OpenSSL::PKey::RSA.new(Base64.decode64(webhook_details.public_key))
end
|
#root_name ⇒ Object
13
14
15
|
# File 'lib/lago/api/resources/webhook.rb', line 13
def root_name
'webhook'
end
|
#valid_signature?(signature, webhook_payload, cached_key = public_key) ⇒ Boolean
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
# File 'lib/lago/api/resources/webhook.rb', line 27
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
|