Skip to content

Add option to skip signature verification #821

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion examples/aiohttp-echo/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ async def echo(self, request):
async def main(port=8000):
async_api_client = AsyncApiClient(configuration)
line_bot_api = AsyncMessagingApi(async_api_client)
parser = WebhookParser(channel_secret)
# Dummy value is fine to skip webhook signature verification
parser = WebhookParser("Dummy Channel Secret", lambda: True)

handler = Handler(line_bot_api, parser)

Expand Down
5 changes: 3 additions & 2 deletions linebot/v3/webhook.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,13 @@ def __init__(self, events=None, destination=None):
class WebhookParser(object):
"""Webhook Parser."""

def __init__(self, channel_secret):
def __init__(self, channel_secret, skip_signature_verification = lambda: False):
"""__init__ method.

:param str channel_secret: Channel secret (as text)
"""
self.signature_validator = SignatureValidator(channel_secret)
self.skip_signature_verification = skip_signature_verification

def parse(self, body, signature, as_payload=False):
"""Parse webhook request body as text.
Expand All @@ -129,7 +130,7 @@ def parse(self, body, signature, as_payload=False):
| :py:class:`linebot.v3.webhook.WebhookPayload`
:return: Events list, or WebhookPayload instance
"""
if not self.signature_validator.validate(body, signature):
if not self.skip_signature_verification() and not self.signature_validator.validate(body, signature):
raise InvalidSignatureError(
'Invalid signature. signature=' + signature)

Expand Down