如何在Ruby中为AppStore API访问生成令牌?

发布于 2025-02-10 11:53:36 字数 280 浏览 0 评论 0 原文

在下面的链接中,解释了如何使用标题和有效载荷生成JWT令牌以访问Apple API 但是,我看不到如何组合标头和有效载荷。 有人可以在ruby中以示例

In the link below is explained how to generate JWT token with header and payload to access the Apple API
However I don't see how to combine header and payload.
Can someone make an example in ruby

https://developer.apple.com/documentation/appstoreserverapi/generating_tokens_for_api_requests

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

森罗 2025-02-17 11:53:36

只需使用 jwt gem 。这是一个维护良好的图书馆,并定期更新。也许也可以没有宝石也可以做到这一点,但是与安全性有关的任何事情都应该在生产中是气密的,所以我只能选择宝石。

寻找正确的加密算法(Apple似乎正在使用ES256),并在文档中找到它,以查看如何使用该图表创建令牌的示例。

使用GEM创建基本JWT令牌的格式(自定义标头字段是可选的)是:

JWT.encode your_payload, your_private_key, encryption_algorithm, custom_header_fields

Just use the jwt gem. It's a well-maintained library with regular updates. It's probably possible to do it without a gem too, but anything having to do with security should be air-tight in production, so I would just go with the gem.

Look for the correct encryption algorithm (Apple seems to be using ES256) and find it in the documentation to see an example of how to create a token with that.

The format for creating a basic JWT token with the gem (custom header fields are optional) is this:

JWT.encode your_payload, your_private_key, encryption_algorithm, custom_header_fields
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文