twilio.js 浏览器软电话 - JWT 签名验证问题 (Mac OSX / Chrome)
twilio.js browser softphone - issue with JWT signature validation (Mac OSX / Chrome)
使用 Twilio 官方 tutorial code here,我得到一个 phone 数字和一个 TwiML 应用程序 运行 很好,然后启动 flask
服务器和 ngrok
转发过程。操作系统和浏览器是Chrome 53.0.2785.143 (64-bit) on Mac OSX
.
不幸的是,它失败了,给出了这个错误:Twilio.Device Error: JWT signature validation failed
如屏幕截图所示:
我试过这样 {debug : true}
来电:
Twilio.Device.setup(data.token, { debug: true });
并得到以下输出:
但目前还不清楚是怎么回事。如果我尝试将返回的实际兼容性令牌放入 Python 控制台(使用 JWT encoder/decoder)and trying to decode it using the Twilio secret auth token and the HS256 algorithm:
from jose import jwt
token = "xxxxx" # compatibility token from above in browser
print jwt.decode(token, TWILIO_AUTH_TOKEN, algorithms=['HS256'])
我收到以下错误:
/Users/me/.virtualenvs/myenv/lib/python2.7/site-packages/jose/jwt.pyc in decode(token, key, algorithms, options, audience, issuer, subject, access_token)
132 payload = jws.verify(token, key, algorithms, verify=verify_signature)
133 except JWSError as e:
--> 134 raise JWTError(e)
135
136 # Needed for at_hash verification
JWTError: Signature verification failed.
所以也许他们没有使用它作为编码解码的秘密,所以不确定这证明了多少。
有什么想法吗?
有几件事可以尝试。
首先:确保您使用的是实际的 AccountSID 和 AuthToken,不要尝试使用 "Test Credentials"。如果您使用的是试用帐户,则一切正常,twilio 仅在语音呼叫前添加了问候语。
其次:确保您已创建 TwiML 应用程序并在 "allowClientOutgoing" 方法期间使用关联的 AppID 用于 "applicationId"。
这应该可以帮助您完成 JWT 签名过程。如果您的服务器似乎无法正常工作。我刚刚构建了一个位于 here 的 Google Apps 脚本版本。只需按照代码中的符号制作副本以放置您的凭据和 appId,然后您就可以查看它是否与您的服务器有关。
要使用,只需向已发布的应用程序脚本发出 GET 请求 URL,它将重新调整令牌。
确保 JWT 签名正确后的其他步骤。
对于传出,您需要回拨到您的服务器以发送回一些带有命令的 TwiML 以拨打传出号码。附加的 Google Apps 脚本中也有一个设置。将脚本 url 添加到您注册的 twilio 号码的语音回调部分,并将其设置为 POST 请求。
传出的 TwiML 示例
<Response><Dial callerId="+//enter your registered phonenumber here////">'+tocall+'</Dial></Response>'
对于传入连接,您需要使用一些代码设置 TwiML Bin,以拨打您在 "allowIncoming(clientName)" 方法中使用的用户的姓名。
传入的 TwiML 示例
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Dial>
<Client>//client name or id registered during token generation here\</Client>
</Dial>
</Response>
然后将TwiML Bin分配到控制台内注册电话号码的传入端。
使用 Twilio 官方 tutorial code here,我得到一个 phone 数字和一个 TwiML 应用程序 运行 很好,然后启动 flask
服务器和 ngrok
转发过程。操作系统和浏览器是Chrome 53.0.2785.143 (64-bit) on Mac OSX
.
不幸的是,它失败了,给出了这个错误:Twilio.Device Error: JWT signature validation failed
如屏幕截图所示:
我试过这样 {debug : true}
来电:
Twilio.Device.setup(data.token, { debug: true });
并得到以下输出:
但目前还不清楚是怎么回事。如果我尝试将返回的实际兼容性令牌放入 Python 控制台(使用 JWT encoder/decoder)and trying to decode it using the Twilio secret auth token and the HS256 algorithm:
from jose import jwt
token = "xxxxx" # compatibility token from above in browser
print jwt.decode(token, TWILIO_AUTH_TOKEN, algorithms=['HS256'])
我收到以下错误:
/Users/me/.virtualenvs/myenv/lib/python2.7/site-packages/jose/jwt.pyc in decode(token, key, algorithms, options, audience, issuer, subject, access_token)
132 payload = jws.verify(token, key, algorithms, verify=verify_signature)
133 except JWSError as e:
--> 134 raise JWTError(e)
135
136 # Needed for at_hash verification
JWTError: Signature verification failed.
所以也许他们没有使用它作为编码解码的秘密,所以不确定这证明了多少。
有什么想法吗?
有几件事可以尝试。
首先:确保您使用的是实际的 AccountSID 和 AuthToken,不要尝试使用 "Test Credentials"。如果您使用的是试用帐户,则一切正常,twilio 仅在语音呼叫前添加了问候语。
其次:确保您已创建 TwiML 应用程序并在 "allowClientOutgoing" 方法期间使用关联的 AppID 用于 "applicationId"。
这应该可以帮助您完成 JWT 签名过程。如果您的服务器似乎无法正常工作。我刚刚构建了一个位于 here 的 Google Apps 脚本版本。只需按照代码中的符号制作副本以放置您的凭据和 appId,然后您就可以查看它是否与您的服务器有关。 要使用,只需向已发布的应用程序脚本发出 GET 请求 URL,它将重新调整令牌。
确保 JWT 签名正确后的其他步骤。
对于传出,您需要回拨到您的服务器以发送回一些带有命令的 TwiML 以拨打传出号码。附加的 Google Apps 脚本中也有一个设置。将脚本 url 添加到您注册的 twilio 号码的语音回调部分,并将其设置为 POST 请求。
传出的 TwiML 示例
<Response><Dial callerId="+//enter your registered phonenumber here////">'+tocall+'</Dial></Response>'
对于传入连接,您需要使用一些代码设置 TwiML Bin,以拨打您在 "allowIncoming(clientName)" 方法中使用的用户的姓名。
传入的 TwiML 示例
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Dial>
<Client>//client name or id registered during token generation here\</Client>
</Dial>
</Response>
然后将TwiML Bin分配到控制台内注册电话号码的传入端。