无法验证从松弛通过AWS API Gateway到Lambda的消息

纽约公爵

我试图通过我的AWS API网关验证松弛消息,我传递给Lambda函数的示例是

{'method': 'POST', 'body': {'token': 'xxxxxx', 'team_id': 'xxxxxx', 'api_app_id': 'xxxxxx', 'event': {'client_msg_id': 'xxxxxx-xxxxxx-xxxxxx-xxxxxx-xxxxxx', 'type': 'message', 'text': 'test', 'user': 'xxxxxx', 'ts': 'xxxxxx.xxxx', 'team': 'xxxxxx', 'blocks': [{'type': 'rich_text', 'block_id': 'xxx', 'elements': [{'type': 'rich_text_section', 'elements': [{'type': 'text', 'text': 'test'}]}]}], 'channel': 'xxxxxx', 'event_ts': 'xxxxxx.xxxx', 'channel_type': 'im'}, 'type': 'event_callback', 'event_id': 'xxxxxxxxx', 'event_time': 1576188370, 'authed_users': ['xxxxxxx']}, 'headers': {'Accept': '*/*', 'Accept-Encoding': 'gzip,deflate', 'Content-Type': 'application/json', 'Host': 'xxxxxxxxxx.execute-api.us-east-1.amazonaws.com', 'User-Agent': 'Slackbot 1.0 (+https://api.slack.com/robots)', 'X-Amzn-Trace-Id': 'Root=1-xxxxxx-xxxxxxxxx', 'X-Forwarded-For': '54.xxx.xxx.xxx', 'X-Forwarded-Port': '443', 'X-Forwarded-Proto': 'https', 'X-Slack-Request-Timestamp': '1576188371', 'X-Slack-Signature': 'v0=xxxxxxxxxxxxxxxxxxxxxxxx'}}

正文/ request_body的摘录

{'token': 'xxxxxx', 'team_id': 'xxxxxx', 'api_app_id': 'xxxxxx', 'event': {'client_msg_id': 'xxxxxx-xxxxxx-xxxxxx-xxxxxx-xxxxxx', 'type': 'message', 'text': 'test', 'user': 'xxxxxx', 'ts': 'xxxxxx.xxxx', 'team': 'xxxxxx', 'blocks': [{'type': 'rich_text', 'block_id': 'xxx', 'elements': [{'type': 'rich_text_section', 'elements': [{'type': 'text', 'text': 'test'}]}]}], 'channel': 'xxxxxx', 'event_ts': 'xxxxxx.xxxx', 'channel_type': 'im'}, 'type': 'event_callback', 'event_id': 'xxxxxxxxx', 'event_time': 1576188370, 'authed_users': ['xxxxxxx']}

我要提取X-Slack-Signature,X-Slack-Request-Timestamp和对象的主体,然后将其传递给以下函数

def verify_slack_request(slack_signature=None, slack_request_timestamp=None, request_body=None):
    slack_signing_secret = 'xxxxxxxxxxxxxxxxxxxxxxxxxx'
    print(request_body)
    data_body = json.dumps(request_body)

    basestring = 'v0:' + slack_request_timestamp + ':' + json.dumps(request_body, indent=None)
    slack_signing_secret = bytes(slack_signing_secret, 'utf-8')
    unicode_basestring = bytes(basestring, 'utf-8')
    my_signature = 'v0=' + hmac.new(slack_signing_secret, unicode_basestring, hashlib.sha256).hexdigest()

    print(my_signature)
    print(slack_signature)

我遇到的问题是,该方法传递的松弛签名和我的签名未对齐,我已经能够验证松弛斜杠命令,但常规的聊天命令似乎无法使用此方法。

阿伦·K

问题是json.dumps不能删除键和值之间的空格。该函数需要一个separators参数来删除空格

尝试以下代码,您应该将lambda事件的主体作为dict(而非字符串)传递给此函数。

import json
import hashlib
import hmac

def create_signature(secret, timestamp, data):

    newdata =json.dumps(data, separators=(',', ':'))

    req = ('v0:' + str(timestamp) + ':' + newdata).encode()
    print('sigBaseString: ', req)
    request_signature= 'v0='+hmac.new(
        str.encode(secret),
        req, hashlib.sha256
    ).hexdigest()

    return request_signature

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

使用API Gateway的AWS Lambda错误消息

来自分类Dev

通过 API Gateway 保护对 AWS Lambda 的访问

来自分类Dev

无法通过 ajax 调用 aws API Gateway

来自分类Dev

如何将消息发送到特定的connectionId到AWS API Gateway Websockets?

来自分类Dev

AWS API Gateway {“消息”:“缺少身份验证令牌”}

来自分类Dev

Python aws-lambda返回xml文件到aws-api-gateway

来自分类Dev

无法通过GPRS连接调用AWS API Gateway GET URL

来自分类Dev

到AWS API Gateway的Ajax请求无法解析json响应

来自分类Dev

无法通过API获取松弛的用户个人资料信息

来自分类Dev

使用AWS API Gateway HTTP API设置Lambda代理

来自分类Dev

使用AWS API Gateway Lambda构建Web后端api

来自分类Dev

通过javascript AND凭证提供程序对AWS API Gateway进行了身份验证

来自分类Dev

AWS API Gateway-专用端点-禁止消息

来自分类Dev

从 Python POST 到 AWS Gateway API 到 Dynamodb

来自分类Dev

AWS API Gateway默认响应和触发AWS Lambda

来自分类Dev

AWS API Gateway默认响应和触发AWS Lambda

来自分类Dev

AWS Lambda NodeJS - OAuth 到 Google API

来自分类Dev

使用松弛API将消息发布到松弛中时,如何忽略表情符号?

来自分类Dev

通过AWS API Gateway和Lambda函数返回动态内容类型

来自分类Dev

通过CLI设置AWS API Gateway时,如何确定Lambda的路径或操作?

来自分类Dev

如何通过GET方法将API Gateway与Lambda集成

来自分类Dev

返回标头内容-API Gateway + AWS Lambda

来自分类Dev

Java:如何从API Gateway获取AWS Lambda事件的Request对象?

来自分类Dev

如何使用多种方法从API Gateway触发AWS Lambda?

来自分类Dev

为什么API Gateway无法从Lambda获得响应?

来自分类Dev

AWS API Gateway / Cognito用户池/ Lambda无法传递调用者凭证

来自分类Dev

通过AWS API Gateway后JPG损坏

来自分类Dev

AWS Lambda网关API给出错误消息

来自分类Dev

通过AWS API Gateway对移动应用程序客户端进行身份验证(社交登录)

Related 相关文章

  1. 1

    使用API Gateway的AWS Lambda错误消息

  2. 2

    通过 API Gateway 保护对 AWS Lambda 的访问

  3. 3

    无法通过 ajax 调用 aws API Gateway

  4. 4

    如何将消息发送到特定的connectionId到AWS API Gateway Websockets?

  5. 5

    AWS API Gateway {“消息”:“缺少身份验证令牌”}

  6. 6

    Python aws-lambda返回xml文件到aws-api-gateway

  7. 7

    无法通过GPRS连接调用AWS API Gateway GET URL

  8. 8

    到AWS API Gateway的Ajax请求无法解析json响应

  9. 9

    无法通过API获取松弛的用户个人资料信息

  10. 10

    使用AWS API Gateway HTTP API设置Lambda代理

  11. 11

    使用AWS API Gateway Lambda构建Web后端api

  12. 12

    通过javascript AND凭证提供程序对AWS API Gateway进行了身份验证

  13. 13

    AWS API Gateway-专用端点-禁止消息

  14. 14

    从 Python POST 到 AWS Gateway API 到 Dynamodb

  15. 15

    AWS API Gateway默认响应和触发AWS Lambda

  16. 16

    AWS API Gateway默认响应和触发AWS Lambda

  17. 17

    AWS Lambda NodeJS - OAuth 到 Google API

  18. 18

    使用松弛API将消息发布到松弛中时,如何忽略表情符号?

  19. 19

    通过AWS API Gateway和Lambda函数返回动态内容类型

  20. 20

    通过CLI设置AWS API Gateway时,如何确定Lambda的路径或操作?

  21. 21

    如何通过GET方法将API Gateway与Lambda集成

  22. 22

    返回标头内容-API Gateway + AWS Lambda

  23. 23

    Java:如何从API Gateway获取AWS Lambda事件的Request对象?

  24. 24

    如何使用多种方法从API Gateway触发AWS Lambda?

  25. 25

    为什么API Gateway无法从Lambda获得响应?

  26. 26

    AWS API Gateway / Cognito用户池/ Lambda无法传递调用者凭证

  27. 27

    通过AWS API Gateway后JPG损坏

  28. 28

    AWS Lambda网关API给出错误消息

  29. 29

    通过AWS API Gateway对移动应用程序客户端进行身份验证(社交登录)

热门标签

归档