Skip to content

Commit ddbbd44

Browse files
committed
Add option to skip signature verification
1 parent 11d3273 commit ddbbd44

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

examples/aiohttp-echo/app.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,8 @@ async def echo(self, request):
8989
async def main(port=8000):
9090
async_api_client = AsyncApiClient(configuration)
9191
line_bot_api = AsyncMessagingApi(async_api_client)
92-
parser = WebhookParser(channel_secret)
92+
# Dummy value is fine to skip webhook signature verification
93+
parser = WebhookParser("Dummy Channel Secret", lambda: True)
9394

9495
handler = Handler(line_bot_api, parser)
9596

linebot/v3/webhook.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,12 +112,13 @@ def __init__(self, events=None, destination=None):
112112
class WebhookParser(object):
113113
"""Webhook Parser."""
114114

115-
def __init__(self, channel_secret):
115+
def __init__(self, channel_secret, skip_signature_verification = lambda: False):
116116
"""__init__ method.
117117
118118
:param str channel_secret: Channel secret (as text)
119119
"""
120120
self.signature_validator = SignatureValidator(channel_secret)
121+
self.skip_signature_verification = skip_signature_verification
121122

122123
def parse(self, body, signature, as_payload=False):
123124
"""Parse webhook request body as text.
@@ -129,7 +130,7 @@ def parse(self, body, signature, as_payload=False):
129130
| :py:class:`linebot.v3.webhook.WebhookPayload`
130131
:return: Events list, or WebhookPayload instance
131132
"""
132-
if not self.signature_validator.validate(body, signature):
133+
if not self.skip_signature_verification() and not self.signature_validator.validate(body, signature):
133134
raise InvalidSignatureError(
134135
'Invalid signature. signature=' + signature)
135136

0 commit comments

Comments
 (0)