我的网站支持使用 Apple 登录。
在此服务的配置中,我在这里有一个端点:
我在此端点收到的是如下 JSON:
"{"payload":"eyJraW...................NLnyA"}
但是,我绝对没有在任何地方找到如何解密/解码此有效负载...
“了解更多”链接将我发送至此处:https://developer.apple.com/help/account/configure-app-capabilities/about-sign-in-with-apple
这个下面的页面是这样的:https://developer.apple.com/help/account/configure-app-capabilities/enabling-server-to-server-notifications
我不知道如何解释这些消息...
有人知道我需要做什么才能读取这些有效负载吗?
最佳答案
看起来服务器到服务器通知的一般过程已概述here 。这是文档必须说的:
These notifications contain a cryptographically signed payload, in JSON Web Signature (JWS) format, signed by Apple’s private key. After your server receives a notification, examine the JWS payload and use the algorithm specified in the header’s alg parameter to validate the signature. For more information, see Fetch Apple’s public key for verifying token signature.
所以,这个有效负载
实际上只是一个 JWT (使用您选择的 JWT 库进行验证/解码,有很多可供选择)。由于任何人都可以访问您的端点,因此您需要验证 token 是否确实来自 Apple。注意:不要尝试自己解码 JWT。出于安全考虑,最好让图书馆为您做这件事。
After validating the token signature, your server performs work according to the type value in the events claim of the token. The notification payload object contains information about user-initiated account modification events.
解码后的 JWT 将包含类似以下内容(示例来自文档):
{
"iss": "https://appleid.apple.com",
"aud": "com.mytest.app",
"iat": 1508184845,
"jti": "abede...67890",
"events": {
"type": "email-enabled",
"sub": "820417.faa325acbc78e1be1668ba852d492d8a.0219",
"email": "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="3550450c5e4607415b455d7545475c43544150475059544c1b54454559505c511b565a58" rel="noreferrer noopener nofollow">[email protected]</a>",
"is_private_email": "true"
"event_time": 1508184845
}
}
events.type
包含发生的事件(完整列表为 here ), token 的其余部分包含您需要的其他所有内容。
关于apple-push-notifications - 如何解码/解密 Apple 服务器到服务器通知?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/75342214/