ChatworkWebhookVerify
Verify ChatWork webhook signature
Installation
Add this line to your application's Gemfile:
gem 'chatwork_webhook_verify'
And then execute:
$ bundle
Or install it yourself as:
$ gem install chatwork_webhook_verify
Basic usage
ChatworkWebhookVerify.verify?(token: token, body: body, signature: signature)
#=> true | false
or
ChatworkWebhookVerify.verify!(token: token, body: body, signature: signature)
#=> raise ChatworkWebhookVerify::InvalidSignatureError if signature is invalid
token
: webhook token (default:ChatworkWebhookVerify.config.token
)- Either
token
orChatworkWebhookVerify.config.token
is required
- Either
body
: request body from webhooksignature
:chatwork_webhook_signature
(query string) orX-ChatWorkWebhookSignature
(request header)
for Rails
call verify_chatwork_webhook_signature!
in your controller
Example 1
class WebhookController < ApplicationController
# `ChatworkWebhookVerify.config.token` is used
before_action :verify_chatwork_webhook_signature!
end
Example 2
class WebhookController < ApplicationController
before_action :verify_chatwork_webhook_signature_with_own_token!
def verify_chatwork_webhook_signature_with_own_token!
verify_chatwork_webhook_signature!("another_token")
end
end
Configuration
ChatworkWebhookVerify.config.token = ENV["CHATWORK_WEBHOOK_TOKEN"]
token
: default webhook token
Contributing
Contribution directions go here.
License
The gem is available as open source under the terms of the MIT License.