简体   繁体   English

如何处理 Twilio SMS StatusCallback URL 的身份验证

[英]How authentication is handled for Twilio SMS StatusCallback URL

I have started using Twilio Programmable SMS API to send messages through Twilio.我已经开始使用 Twilio Programmable SMS API 通过 Twilio 发送消息。

As we all know, a message status can be queued , failed or sent , delivered or undelivered , and it changes over a period of time.众所周知,消息状态可以是queuedfailed或已sent 、已delivered或未undelivered ,并且它会在一段时间内发生变化。

As per the documentation, the API has provided an excellent facility to monitor the status of message using StatusCallback request parameter, the value of this parameter is a URL that gets called when message status changes.根据文档,API 提供了一个很好的工具来使用StatusCallback请求参数来监视消息状态,该参数的值是在消息状态更改时调用的 URL。

I am assuming that StatusCallback URL is our custom REST API endpoint that gets called by Twilio whenever the message status changes.我假设 StatusCallback URL 是我们的自定义 REST API 端点,每当消息状态发生变化时,Twilio 都会调用它。 Am I correct?我对么? If yes, how the Twilio is authenticated to call our StatusCallback URL, how the authentication of StatusCallback URL is handled?如果是,Twilio是如何验证调用我们StatusCallback URL,如何认证StatusCallback URL进行处理?

Twilio allows you to set up authentication for webhooks in a couple of ways. Twilio 允许您通过多种方式为 Webhook 设置身份验证。

First, you can set up your endpoint to require HTTP authentication .首先,您可以将端点设置为需要HTTP 身份验证 You can then set the username and password in the URL.然后,您可以在 URL 中设置用户名和密码。 Twilio will first send a request with no Authorization header. Twilio 将首先发送一个没有Authorization标头的请求。 After your server responds with a 401 Unauthorized status code, a WWW-Authenticate header and a realm in the response, Twilio will make the same request with an Authorization header.在您的服务器以401 Unauthorized状态代码、 WWW-Authenticate标头和响应中的realm进行响应后,Twilio 将使用Authorization标头发出相同的请求。

The other way to ensure that it was Twilio was the initiator of a request is to validate the signature that comes as the X-Twilio-Signature header of the request.另一种确保 Twilio 是请求发起者的方法是 验证作为请求的X-Twilio-Signature标头的X-Twilio-Signature The signature is made up of the URL and all the parameters of the request, signed with your account's auth token.签名由 URL 和请求的所有参数组成,并使用您帐户的身份验证令牌进行签名。 If you can generate the same signature, then you can trust it came from Twilio.如果您可以生成相同的签名,那么您可以相信它来自 Twilio。 Check the documentation for how to validate the signature , it's also built into each of the official Twilio helper libraries.检查 文档以了解如何验证签名,它也内置在每个官方 Twilio 帮助程序库中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM