LoginSignup
6
0

More than 1 year has passed since last update.

AndroidでFirebase + Sign in with Apple 実装

Posted at

やること

AndroidでSign in with Appleができるようにする

前提

Firebaseプロジェクト作成済のアプリであること

概要

  1. IdentifierのSign in with Apple をオンにする
  2. ServiceId作成
  3. プライベートリレー用の設定
  4. Sign in with Apple用秘密鍵作成
  5. Firebase側の設定
  6. コード書こう

1. IdentifierのSign in with Apple をオンにする

Apple Developer Consoleにログイン
-> Certificates, Identifiers & Profiles を開く
-> Sign in with Apple を実装したいアプリのIdentifierを選択
-> CapabilitiesタブのSign in with Appleにチェックを入れる
-> Editを押下し、Enable as a primary App IDを選択してSave
-> 右上のSaveを押下

2. ServiceIDの作成と設定

Sign in with Apple 用にServiceIDを作成します。
ここで作成したIDをこの後の手順でFirebase側に設定します。

作成
Apple Developer Consoleにログイン
-> Certificates, Identifiers & Profiles を開く
-> Identifierを選択し、+ボタンを押下
-> Services IDs を選択してcontinue
-> descriptionとidentifierを入力してcontinue
-> 内容を確認してregister

設定
Identifierを選択し、作成したServiceIdを選択
-> Sign in with Apple のConfigureを押下
-> Primary App ID はSign In with Appleを実装するアプリのIDを選択
-> Website URLs の+ボタンを押下
-> Domains and Subdomains に下記を設定
${FIREBASE_PROJECT_ID}.firebaseapp.com
-> Return URLs に下記を設定
https://${FIREBASE_PROJECT_ID}.firebaseapp.com/__/auth/handler

3. プライベートリレー用の設定

ユーザーはAppleIDとして設定しているメールアドレスを非公開にして、ランダムなメールアドレスを生成して使用することができます。そのような設定をしているユーザーとコミュニケーションを取るためのメールアドレスをあらかじめ設定しておく必要があります。

Apple Developer Consoleにログイン
-> Certificates, Identifiers & Profiles を開く
-> Servicesを選択し、Sign in with Apple for Email Communication のconfigureを押下
-> +ボタンを押下
-> Domains and Subdomains に下記を入力
${FIREBASE_PROJECT_ID}.firebaseapp.com
-> Email Addresses に下記を入力
noreply@${FIREBASE_PROJECT_ID}.firebaseapp.com
-> Next押下し、内容を確認してRegister押下

4. Sign in with Apple用秘密鍵作成

ここで作成した秘密鍵をこの後の手順でFirebase側に設定します。

Apple Developer Consoleにログイン
-> Certificates, Identifiers & Profiles を開く
-> Keysを押下

Keyを作成してある場合
既にPush通知利用のためなど、Keyを作成してある場合は、EditでSign in with Appleにもチェックを入れればOK
この時PrimaryIDは何でもOK

Keyを作成していない場合
+ボタン押下
-> Key Nameを入力
-> Sign in with Apple にチェックを入れる
-> configureを押下できるようになるので押下
-> PrimaryIDを選択してsave
-> Continue押下し、内容を確認してRegister押下
-> 秘密鍵をダウンロード
この鍵は1度しかダウンロードできない。適切な場所に保管する。

5. Firebase側の設定

設定するのはこの4つです。
ServiceID, Apple TeamID, KeyID, 秘密鍵

Firebaseプロジェクトを開く
-> 構築 > Authentication 選択
-> Sign-in methodタブを選択
-> ログインプロバイダにAppleを追加し、有効にする
-> Appleを選択するとサービスIDの入力欄があるので2で作成したServiceIDを入力する
-> サービスID入力欄の下にOAuth コードフローの構成(省略可)とあるので押下する
-> Apple TeamID, 4で作成したKeyIDと秘密鍵を入力する
-> 保存押下

6. コード書こう

公式の手順通りの実装すればOK
https://firebase.google.com/docs/auth/android/apple#handle_the_sign-in_flow_with_the_firebase_sdk

参考

Apple側設定手順
https://help.apple.com/developer-account/#/devde676e696

Firebase 手順
https://firebase.google.com/docs/auth/android/apple#join-the-apple-developer-program

6
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
0