

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# Amazon SNS 與 Firebase Cloud Messaging 身分驗證設定的整合
<a name="sns-fcm-authentication-methods"></a>

本主題說明如何從 Google 取得必要的 FCM API (HTTP v1) 登入資料，以搭配 AWS API AWS CLI 和 使用 AWS 管理主控台。

**重要**  
2024 年 3 月 26 日 – Amazon SNS 支援適用於 Apple 裝置和 Webpush 目的地的 FCM HTTP v1 API。我們建議您在 2024 年 6 月 1 日或之前將現有的行動推送應用程式遷移至最新的 FCM HTTP v1 API，以避免應用程式中斷。  
2024 年 1 月 18 日 – Amazon SNS 推出對 FCM HTTP v1 API 的支援，以將行動推播通知交付至 Android 裝置。  
2023 年 6 月 20 日 – Google 已棄用其 Firebase Cloud Messaging (FCM) 舊版 HTTP API。Amazon SNS 現在支援使用 FCM HTTP v1 API 交付至所有裝置類型。我們建議您在 2024 年 6 月 1 日或之前將現有的行動推送應用程式遷移至最新的 FCM HTTP v1 API，以避免中斷。

您可以透過提供將您識別為應用程式開發人員的資訊，授權 Amazon SNS 將推播通知傳送到您的應用程式。如要進行身份驗證，請在[建立平台應用程式時](https://docs.aws.amazon.com/sns/latest/api/API_SetPlatformApplicationAttributes.html)提供 **API 金鑰**或**權杖**。您可以從 [Firebase 應用程式主控台](https://firebase.google.com/?gad=1&gclid=CjwKCAiA0syqBhBxEiwAeNx9N27M7zxHjlS74_gp4mAS4QTMQH5J35sTO29od-yauuq259zzX_I2DRoCrbsQAvD_BwE&gclsrc=aw.ds)取得以下資訊：

**API 金鑰**  
API 金鑰是呼叫 Firebase 舊版 API 時使用的憑證。2024 年 6 月 20 日，Google 將刪除 FCM 舊版 API。如果您目前正在使用 API 金鑰作為平台憑證，則可以通過選擇**權杖**作為選項，並上傳 Firebase 應用程式的相關 JSON 檔案來更新平台憑據。

**Token** (字符)  
呼叫 HTTP v1 API 時，會使用簡短的即時存取字符。這是 Firebase 建議用來傳推送通知的 API。為了生成存取權杖，Firebase 以私有金鑰文件 (也稱為 service.json 檔案) 的形式提供給開發人員一組憑證。

## 先決條件
<a name="sns-fcm-authentication-prerequisite"></a>

您必須先取得 FCM service.json 憑證，然後才能開始在 Amazon SNS 中管理 FCM 設定。如要獲取您的 service.json 憑證，請參閱 Google Firebase 文件中的[從舊版 FCM API 遷移到 HTTP v1](https://firebase.google.com/docs/cloud-messaging/migrate-v1)。

## 使用 CLI 管理 FCM 設定
<a name="sns-fcm-authentication-api"></a>

您可以使用 AWS API 建立 FCM 推送通知。 AWS 帳戶中 Amazon SNS 資源的數量和大小有限。如需詳細資訊，請參閱《 *AWS 一般參考 指南*》中的 [Amazon Simple Notification Service 端點和配額](https://docs.aws.amazon.com/general/latest/gr/sns.html)。

**建立 FCM 推送通知與 Amazon SNS 主題 (AWS API)**  
使用**金鑰**憑證時，`PlatformCredential` 是 `API key`。使用**權杖**憑證時，`PlatformCredential` 是 JSON 格式的私有金鑰檔案：
+ [https://docs.aws.amazon.com/sns/latest/api/API_CreatePlatformApplication.html](https://docs.aws.amazon.com/sns/latest/api/API_CreatePlatformApplication.html)

**擷取現有 Amazon SNS 主題 (AWS API) 的 FCM 憑證類型**  
擷取憑證類型 `"AuthenticationMethod": "Token"` 或 ` "AuthenticationMethod": "Key"`：
+ [GetPlatformApplicationAttributes](https://docs.aws.amazon.com/sns/latest/api/API_GetPlatformApplicationAttributes.html)

**設定現有 Amazon SNS 主題 (AWS API) 的 FCM 屬性**  
設置 FCM 屬性：
+ [SetPlatformApplicationAttributes](https://docs.aws.amazon.com/sns/latest/api/API_SetPlatformApplicationAttributes.html)

## 使用主控台管理 FCM 設定
<a name="sns-fcm-authentication-cli"></a>

您可以使用 AWS Command Line Interface (CLI) 建立 FCM 推送通知。 AWS 帳戶中 Amazon SNS 資源的數量和大小有限。如需詳細資訊，請參閱 [Amazon Simple Notification Service 端點和配額](https://docs.aws.amazon.com/general/latest/gr/sns.html)。

**若要與 Amazon SNS 主題一起建立 FCM 推送通知 (AWS CLI)**  
使用**金鑰**憑證時，`PlatformCredential` 是 `API key`。使用**權杖**憑證時，`PlatformCredential` 是 JSON 格式的私有金鑰檔案。使用 AWS CLI 時，檔案必須是字串格式，且必須忽略特殊字元。若要正確格式化檔案，Amazon SNS 建議您使用下列命令：`SERVICE_JSON=`jq @json <<< cat service.json``：
+ [create-platform-application](https://docs.aws.amazon.com/cli/latest/reference/sns/create-platform-application.html)

**如要擷取現有 Amazon SNS 主題的 FCM 憑證類型 (AWS CLI)。**  
擷取憑證類型 `"AuthenticationMethod": "Token"` 或 ` "AuthenticationMethod": "Key"`：
+ [get-platform-application-attributes](https://docs.aws.amazon.com/cli/latest/reference/sns/get-platform-application-attributes.html)

**如要設置現有 Amazon SNS 主題的 FCM 屬性 (AWS CLI)**  
設置 FCM 屬性：
+ [set-platform-application-attributes](https://docs.aws.amazon.com/cli/latest/reference/sns/set-platform-application-attributes.html)

## 管理 FCM 設定 (主控台)
<a name="sns-fcm-authentication-console"></a>

使用下列步驟在 Amazon SNS 中輸入和管理 Firebase Cloud Messaging (FCM) 登入資料。

1. 登入 [Amazon SNS 主控台](https://console.aws.amazon.com/sns/home)。

1. 在導覽窗格中，選取**推送通知**。

1. 在**平台應用程式**區段中，選取您要編輯其登入資料的 **FCM 平台應用程式**，然後選擇**編輯**。

1. 在 **Firebase Cloud Messaging Credentials** 區段中，選擇下列其中一個選項：
   + 以**字符為基礎的身分驗證** （建議的方法） – 上傳您從 Firebase 主控台下載的**私有金鑰檔案** (JSON)。此檔案包含為 FCM 通知產生短期存取字符所需的登入資料。若要取得此檔案：

     1. 前往 [Firebase 應用程式主控台](https://firebase.google.com/?gad=1&gclid=CjwKCAiA0syqBhBxEiwAeNx9N27M7zxHjlS74_gp4mAS4QTMQH5J35sTO29od-yauuq259zzX_I2DRoCrbsQAvD_BwE&gclsrc=aw.ds)。

     1. 在**專案設定**中，選取**雲端傳訊**。

     1. 下載**私有金鑰** JSON 檔案 （用於字符型身分驗證方法）。
   + **API 金鑰身分驗證** – 如果您偏好使用較舊的 API 金鑰身分驗證方法，請在提供的欄位中輸入 **Google API 金鑰**。若要取得此檔案：

     1. 前往 [Firebase 應用程式主控台](https://firebase.google.com/?gad=1&gclid=CjwKCAiA0syqBhBxEiwAeNx9N27M7zxHjlS74_gp4mAS4QTMQH5J35sTO29od-yauuq259zzX_I2DRoCrbsQAvD_BwE&gclsrc=aw.ds)。

     1. 在**專案設定**中，選取**雲端傳訊**。

     1. 複製用於傳送通知的**伺服器金鑰** (API 金鑰）。

1. 完成後，請選擇**儲存變更**。

**相關主題**
+ [在 Amazon SNS 中使用 Google Firebase Cloud Messaging v1 承載](sns-fcm-v1-payloads.md)