apple-push-notifications - 如何解码/解密 Apple 服务器到服务器通知?

标签 apple-push-notifications apple-sign-in server-to-server

我的网站支持使用 Apple 登录。

在此服务的配置中,我在这里有一个端点:

enter image description here

我在此端点收到的是如下 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/

相关文章:

ios - 需要指导在 Cordova 应用程序中使用 native APNs/GCM 为 iOS 推送通知

authentication - CloudKit 服务器到服务器身份验证

ios - 未找到模块 'apple_sign_in'

apple-developer - 在使用 Apple 登录 - Apple ID 配置中禁用启用为主要 App ID 选项

docker - 如果外部无法直接访问api,为什么内部服务之间的通信需要像oauth这样的授权?

ios - 没有 APNS 的推送通知

ios - 将远程通知与部署目标 8.1 和 XCODE 6.1 一起使用

iphone - 在后台模式下未收到 iOS APNS

ios - 苹果登录 : How to use it for custom server endpoint authentication?