筆記: Sign In with Apple

2020022017:06



Apple 規定, 2020/04 起所有用到第三方登入的 App (例如提供 FB 帳號登入、Google 帳號登入)
都必需提供 Apple ID 登入功能 (Sign In with Apple)


這篇文章有完整的說明 + 整個專案範例:
iOS 13 - How to Integrate Sign In with Apple in your Application?
(專案範例)


有個小問題是
當用戶選擇不提供真實 email 的狀況時
用戶登入,Apple 都會給一個虛擬信箱 [email protected]
apple 說,寄信這個虛擬信箱時,apple 會自動轉到用戶真實的信箱
目前實測是會被退信 ,
錯誤訊息是: 550 5.1.1 Relay not allowed

特別該注意的是這裡:
用戶以 Apple ID 登入後,Apple 會給你用戶的個資 (如 姓名、email )
用戶的個資,Apple 只會給你一次,Apple 只會給你一次
當用戶第二次再登入時, Apple 就不會再給你個資,app 端只會收到 user id (appleIDCredential.user)
 
// ASAuthorizationControllerDelegate function for successful authorization
func authorizationController(controller: ASAuthorizationController, didCompleteWithAuthorization authorization: ASAuthorization) {
    if let appleIDCredential = authorization.credential as? ASAuthorizationAppleIDCredential { 
        // Create an account in your system.
        let userIdentifier = appleIDCredential.user
        let userFirstName = appleIDCredential.fullName?.givenName
        let userLastName = appleIDCredential.fullName?.familyName
        let userEmail = appleIDCredential.email
        
        //Navigate to other view controller
    } else if let passwordCredential = authorization.credential as? ASPasswordCredential {
        // Sign in using an existing iCloud Keychain credential.
        let username = passwordCredential.user
        let password = passwordCredential.password
        
        //Navigate to other view controller
    }
}

另外,蘋果的用戶可在這裡查詢自己曾以 Apple ID 登入哪些 app:
https://appleid.apple.com/account/manage

網頁版的 Sign In with Apple ,參考這個:
What the Heck is Sign In with Apple?