gpt4 book ai didi

google-apps-script - 使用 Apps 脚本为 Twilio 的 Authy 构建 JWT

转载 作者:行者123 更新时间:2023-12-01 03:05:21 24 4
gpt4 key购买 nike

No-PII user registration JWT在 Twilio 的 authy 中添加用户需要我们从头开始构建 JWT。

我尝试到处寻找如何使用 Google Apps 脚本创建 JWT,但没有找到实现这一目标的正确方法。它特别需要是 HS256 alg。

我要求最终的有效载荷看起来完全像这样 -

// Example Payload
{
"iss": "My Authy App",
"iat": 1554395479,
"exp": 1554395879,
"context": {
"custom_user_id": "3YgAIZklGPHmwpJfIC0PDy0E7l763OF3BHZo1p2xKhY",
"authy_app_id": "1111111"
}
}

// Example Header
{
"alg": "HS256",
"typ": "JWT"
}

有人可以帮我解决这个问题,或者给我指出一个合适的文章/文档吗?

最佳答案

使用 Google Apps 脚本获取 URL 的一般语法如下:

var body={
"iss": "My Authy App",
"iat": 1554395479,
"exp": 1554395879,
"context": {
"custom_user_id": "3YgAIZklGPHmwpJfIC0PDy0E7l763OF3BHZo1p2xKhY",
"authy_app_id": "1111111"
};
var header={
"alg": "HS256",
"typ": "JWT"
};
var url='YOUR URL';
var options={
method: 'POST',
headers: header,
muteHttpExceptions: true,
contentType: 'application/json',
payload: JSON.stringify(body)
};
var response=UrlFetchApp.fetch(url, options);

根据您提供的文档链接,您可能需要提供 API key 。在这种情况下,您的 URL 应该类似于 var url=basicURL+"apikey="+XXX
我没有 Twilio 帐户来测试它,但上面提供的示例是 Apps 脚本的一般过程,您可以在以下链接下找到更多引用:
  • Working with Third-Party APIs
  • External APIs
  • Twilio Send a SMS message

    Note that in the latter sample the payload is not in quotes.

  • 关于google-apps-script - 使用 Apps 脚本为 Twilio 的 Authy 构建 JWT,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58197769/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com