คุณสามารถอนุญาตให้ผู้ใช้ตรวจสอบสิทธิ์กับ Firebase โดยใช้ Apple ID ได้ด้วยการใช้ Firebase SDK เพื่อดำเนินการตามขั้นตอนการลงชื่อเข้าใช้ OAuth 2.0 แบบครบวงจร
ก่อนเริ่มต้น
หากต้องการลงชื่อเข้าใช้ผู้ใช้โดยใช้ Apple ให้กำหนดค่าการลงชื่อเข้าใช้ด้วย Apple ในเว็บไซต์นักพัฒนาซอฟต์แวร์ของ Apple ก่อน จากนั้นเปิดใช้ Apple เป็นผู้ให้บริการลงชื่อเข้าใช้สำหรับโปรเจ็กต์ Firebase ของคุณ
เข้าร่วม Apple Developer Program
เฉพาะสมาชิกของ Apple Developer Program เท่านั้นที่กำหนดค่าฟีเจอร์ลงชื่อเข้าใช้ด้วย Apple ได้
กำหนดค่าการลงชื่อเข้าใช้ด้วย Apple
- เปิดใช้ฟีเจอร์ลงชื่อเข้าใช้ด้วย Apple สำหรับแอปในหน้าใบรับรอง ตัวระบุ และโปรไฟล์ของเว็บไซต์นักพัฒนาแอป Apple
- เชื่อมโยงเว็บไซต์กับแอปตามที่อธิบายไว้ในส่วนแรกของกำหนดค่าการลงชื่อเข้าใช้ด้วย Apple สำหรับเว็บ เมื่อได้รับข้อความแจ้ง ให้ลงทะเบียน URL ต่อไปนี้เป็น URL สำหรับการคืนสินค้า
คุณดูรหัสโปรเจ็กต์ Firebase ได้ในหน้าการตั้งค่าคอนโซล Firebase เมื่อเสร็จแล้ว ให้จดบันทึกรหัสบริการใหม่ซึ่งคุณจะต้องใช้ในส่วนถัดไปhttps://YOUR_FIREBASE_PROJECT_ID.firebaseapp.com/__/auth/handler
- สร้างคีย์ส่วนตัวสำหรับการลงชื่อเข้าใช้ด้วย Apple คุณจะต้องใช้คีย์ส่วนตัวและรหัสคีย์ใหม่ในส่วนถัดไป
- หากคุณใช้ฟีเจอร์ของ Firebase Authentication ที่ส่งอีเมลถึงผู้ใช้ ซึ่งรวมถึงการลงชื่อเข้าใช้ด้วยลิงก์อีเมล การยืนยันอีเมล การเพิกถอนการเปลี่ยนแปลงบัญชี และอื่นๆ ให้กำหนดค่าบริการส่งต่ออีเมลส่วนตัวของ Apple และลงทะเบียน
noreply@YOUR_FIREBASE_PROJECT_ID.firebaseapp.com(หรือโดเมนเทมเพลตอีเมลที่กำหนดเอง) เพื่อให้ Apple ส่งต่ออีเมลที่ Firebase Authentication ส่งไปยังอีเมล Apple ที่ไม่ระบุตัวตนได้
เปิดใช้ Apple เป็นผู้ให้บริการลงชื่อเข้าใช้
- เพิ่ม Firebase ในโปรเจ็กต์ Apple อย่าลืมลงทะเบียนรหัสชุดของแอปเมื่อตั้งค่าแอปในคอนโซล Firebase
- ในคอนโซล Firebase ให้ไปที่ความปลอดภัย > การตรวจสอบสิทธิ์
- ในแท็บวิธีการลงชื่อเข้าใช้ ให้เปิดใช้ผู้ให้บริการการลงชื่อเข้าใช้ Apple ระบุรหัสบริการที่คุณสร้างไว้ในส่วนก่อนหน้า นอกจากนี้ ในส่วนการกำหนดค่าโฟลว์โค้ด OAuth ให้ระบุรหัสทีม Apple รวมถึงคีย์ส่วนตัวและรหัสคีย์ที่คุณสร้างไว้ในส่วนก่อนหน้า
ปฏิบัติตามข้อกำหนดด้านข้อมูลที่ไม่ระบุตัวบุคคลของ Apple
ฟีเจอร์ลงชื่อเข้าใช้ด้วย Apple ช่วยให้ผู้ใช้เลือกที่จะไม่ระบุตัวตนของข้อมูลได้ ซึ่งรวมถึงอีเมลเมื่อลงชื่อเข้าใช้ ผู้ใช้ที่เลือกตัวเลือกนี้จะมีอีเมลที่ใช้โดเมน privaterelay.appleid.com เมื่อใช้ฟีเจอร์ลงชื่อเข้าใช้ด้วย Apple ในแอป คุณต้องปฏิบัติตามนโยบายหรือข้อกำหนดสำหรับนักพัฒนาแอปที่เกี่ยวข้องจาก Apple เกี่ยวกับ Apple ID ที่ไม่ระบุตัวตนเหล่านี้
ซึ่งรวมถึงการขอความยินยอมของผู้ใช้ที่จำเป็นก่อนที่คุณจะเชื่อมโยงข้อมูลส่วนบุคคลที่ระบุตัวบุคคลนั้นได้โดยตรงกับ Apple ID ที่ลบข้อมูลระบุตัวบุคคลออกแล้ว เมื่อใช้การตรวจสอบสิทธิ์ Firebase การดำเนินการนี้อาจรวมถึงการดำเนินการต่อไปนี้
- ลิงก์อีเมลกับ Apple ID ที่ลบข้อมูลระบุตัวบุคคลออก หรือในทางกลับกัน
- ลิงก์หมายเลขโทรศัพท์กับ Apple ID ที่ไม่ระบุตัวบุคคล หรือในทางกลับกัน
- ลิงก์ข้อมูลเข้าสู่ระบบโซเชียลที่ไม่ระบุตัวบุคคล (Facebook, Google ฯลฯ) กับ Apple ID ที่ไม่ระบุตัวบุคคล หรือในทางกลับกัน
โปรดทราบว่ารายการด้านบนเป็นเพียงตัวอย่างบางส่วนเท่านั้น โปรดดูข้อตกลงการอนุญาตให้ใช้สิทธิของ Apple Developer Program ในส่วนการเป็นสมาชิกของบัญชีนักพัฒนาแอปเพื่อให้แน่ใจว่าแอปเป็นไปตามข้อกำหนดของ Apple
ลงชื่อเข้าใช้ด้วย Apple และตรวจสอบสิทธิ์ด้วย Firebase
หากต้องการตรวจสอบสิทธิ์ด้วยบัญชี Apple ก่อนอื่นให้ลงชื่อเข้าใช้บัญชี Apple ของผู้ใช้โดยใช้เฟรมเวิร์ก AuthenticationServices ของ Apple จากนั้นใช้โทเค็นระบุตัวตนจากการตอบกลับของ Apple เพื่อสร้างออบเจ็กต์ AuthCredential ของ Firebase ดังนี้
สำหรับคำขอลงชื่อเข้าใช้ทุกรายการ ให้สร้างสตริงแบบสุ่มหรือ "Nonce" ซึ่งคุณจะใช้เพื่อตรวจสอบว่าโทเค็นระบุตัวตนที่ได้รับนั้นได้รับการให้สิทธิ์เพื่อตอบสนองต่อคำขอตรวจสอบสิทธิ์ของแอปโดยเฉพาะ ขั้นตอนนี้สำคัญต่อการป้องกันการโจมตีแบบ Replay Attack
คุณสามารถสร้าง Nonce ที่ปลอดภัยด้วยการเข้ารหัสลับโดยใช้
SecRandomCopyBytes(_:_:_)ดังตัวอย่างต่อไปนี้Swift
private func randomNonceString(length: Int = 32) -> String { precondition(length > 0) var randomBytes = [UInt8](repeating: 0, count: length) let errorCode = SecRandomCopyBytes(kSecRandomDefault, randomBytes.count, &randomBytes) if errorCode != errSecSuccess { fatalError( "Unable to generate nonce. SecRandomCopyBytes failed with OSStatus \(errorCode)" ) } let charset: [Character] = Array("0123456789ABCDEFGHIJKLMNOPQRSTUVXYZabcdefghijklmnopqrstuvwxyz-._") let nonce = randomBytes.map { byte in // Pick a random character from the set, wrapping around if needed. charset[Int(byte) % charset.count] } return String(nonce) }
Objective-C
// Adapted from https://auth0.com/docs/api-auth/tutorials/nonce#generate-a-cryptographically-random-nonce - (NSString *)randomNonce:(NSInteger)length { NSAssert(length > 0, @"Expected nonce to have positive length"); NSString *characterSet = @"0123456789ABCDEFGHIJKLMNOPQRSTUVXYZabcdefghijklmnopqrstuvwxyz-._"; NSMutableString *result = [NSMutableString string]; NSInteger remainingLength = length; while (remainingLength > 0) { NSMutableArray *randoms = [NSMutableArray arrayWithCapacity:16]; for (NSInteger i = 0; i < 16; i++) { uint8_t random = 0; int errorCode = SecRandomCopyBytes(kSecRandomDefault, 1, &random); NSAssert(errorCode == errSecSuccess, @"Unable to generate nonce: OSStatus %i", errorCode); [randoms addObject:@(random)]; } for (NSNumber *random in randoms) { if (remainingLength == 0) { break; } if (random.unsignedIntValue < characterSet.length) { unichar character = [characterSet characterAtIndex:random.unsignedIntValue]; [result appendFormat:@"%C", character]; remainingLength--; } } } return [result copy]; }
คุณจะส่งแฮช SHA256 ของ Nonce พร้อมกับคำขอลงชื่อเข้าใช้ ซึ่ง Apple จะส่งต่อโดยไม่มีการเปลี่ยนแปลงในการตอบกลับ Firebase จะตรวจสอบการตอบกลับโดยแฮช Nonce เดิมและเปรียบเทียบกับค่าที่ Apple ส่งมา
Swift
@available(iOS 13, *) private func sha256(_ input: String) -> String { let inputData = Data(input.utf8) let hashedData = SHA256.hash(data: inputData) let hashString = hashedData.compactMap { String(format: "%02x", $0) }.joined() return hashString }
Objective-C
- (NSString *)stringBySha256HashingString:(NSString *)input { const char *string = [input UTF8String]; unsigned char result[CC_SHA256_DIGEST_LENGTH]; CC_SHA256(string, (CC_LONG)strlen(string), result); NSMutableString *hashed = [NSMutableString stringWithCapacity:CC_SHA256_DIGEST_LENGTH * 2]; for (NSInteger i = 0; i < CC_SHA256_DIGEST_LENGTH; i++) { [hashed appendFormat:@"%02x", result[i]]; } return hashed; }
เริ่มขั้นตอนการลงชื่อเข้าใช้ของ Apple โดยรวมแฮช SHA256 ของ Nonce และคลาสตัวแทนที่จะจัดการการตอบกลับของ Apple ไว้ในคำขอ (ดูขั้นตอนถัดไป)
Swift
import CryptoKit // Unhashed nonce. fileprivate var currentNonce: String? @available(iOS 13, *) func startSignInWithAppleFlow() { let nonce = randomNonceString() currentNonce = nonce let appleIDProvider = ASAuthorizationAppleIDProvider() let request = appleIDProvider.createRequest() request.requestedScopes = [.fullName, .email] request.nonce = sha256(nonce) let authorizationController = ASAuthorizationController(authorizationRequests: [request]) authorizationController.delegate = self authorizationController.presentationContextProvider = self authorizationController.performRequests() }Objective-C
@import CommonCrypto; - (void)startSignInWithAppleFlow { NSString *nonce = [self randomNonce:32]; self.currentNonce = nonce; ASAuthorizationAppleIDProvider *appleIDProvider = [[ASAuthorizationAppleIDProvider alloc] init]; ASAuthorizationAppleIDRequest *request = [appleIDProvider createRequest]; request.requestedScopes = @[ASAuthorizationScopeFullName, ASAuthorizationScopeEmail]; request.nonce = [self stringBySha256HashingString:nonce]; ASAuthorizationController *authorizationController = [[ASAuthorizationController alloc] initWithAuthorizationRequests:@[request]]; authorizationController.delegate = self; authorizationController.presentationContextProvider = self; [authorizationController performRequests]; }จัดการการตอบกลับของ Apple ในการติดตั้งใช้งาน
ASAuthorizationControllerDelegateหากลงชื่อเข้าใช้สำเร็จ ให้ใช้โทเค็นรหัสจากการตอบกลับของ Apple กับ Nonce ที่ไม่ได้แฮชเพื่อตรวจสอบสิทธิ์กับ Firebase โดยทำดังนี้Swift
@available(iOS 13.0, *) extension MainViewController: ASAuthorizationControllerDelegate { func authorizationController(controller: ASAuthorizationController, didCompleteWithAuthorization authorization: ASAuthorization) { if let appleIDCredential = authorization.credential as? ASAuthorizationAppleIDCredential { guard let nonce = currentNonce else { fatalError("Invalid state: A login callback was received, but no login request was sent.") } guard let appleIDToken = appleIDCredential.identityToken else { print("Unable to fetch identity token") return } guard let idTokenString = String(data: appleIDToken, encoding: .utf8) else { print("Unable to serialize token string from data: \(appleIDToken.debugDescription)") return } // Initialize a Firebase credential, including the user's full name. let credential = OAuthProvider.appleCredential(withIDToken: idTokenString, rawNonce: nonce, fullName: appleIDCredential.fullName) // Sign in with Firebase. Auth.auth().signIn(with: credential) { (authResult, error) in if error { // Error. If error.code == .MissingOrInvalidNonce, make sure // you're sending the SHA256-hashed nonce as a hex string with // your request to Apple. print(error.localizedDescription) return } // User is signed in to Firebase with Apple. // ... } } } func authorizationController(controller: ASAuthorizationController, didCompleteWithError error: Error) { // Handle error. print("Sign in with Apple errored: \(error)") } }Objective-C
- (void)authorizationController:(ASAuthorizationController *)controller didCompleteWithAuthorization:(ASAuthorization *)authorization API_AVAILABLE(ios(13.0)) { if ([authorization.credential isKindOfClass:[ASAuthorizationAppleIDCredential class]]) { ASAuthorizationAppleIDCredential *appleIDCredential = authorization.credential; NSString *rawNonce = self.currentNonce; NSAssert(rawNonce != nil, @"Invalid state: A login callback was received, but no login request was sent."); if (appleIDCredential.identityToken == nil) { NSLog(@"Unable to fetch identity token."); return; } NSString *idToken = [[NSString alloc] initWithData:appleIDCredential.identityToken encoding:NSUTF8StringEncoding]; if (idToken == nil) { NSLog(@"Unable to serialize id token from data: %@", appleIDCredential.identityToken); } // Initialize a Firebase credential, including the user's full name. FIROAuthCredential *credential = [FIROAuthProvider appleCredentialWithIDToken:IDToken rawNonce:self.appleRawNonce fullName:appleIDCredential.fullName]; // Sign in with Firebase. [[FIRAuth auth] signInWithCredential:credential completion:^(FIRAuthDataResult * _Nullable authResult, NSError * _Nullable error) { if (error != nil) { // Error. If error.code == FIRAuthErrorCodeMissingOrInvalidNonce, // make sure you're sending the SHA256-hashed nonce as a hex string // with your request to Apple. return; } // Sign-in succeeded! }]; } } - (void)authorizationController:(ASAuthorizationController *)controller didCompleteWithError:(NSError *)error API_AVAILABLE(ios(13.0)) { NSLog(@"Sign in with Apple errored: %@", error); }
Apple ไม่ได้ระบุ URL ของรูปภาพ ซึ่งต่างจากผู้ให้บริการรายอื่นๆ ที่ Firebase Auth รองรับ
นอกจากนี้ เมื่อผู้ใช้เลือกที่จะไม่แชร์อีเมลกับแอป Apple จะจัดสรรอีเมลที่ไม่ซ้ำกันสำหรับผู้ใช้รายนั้น (ในรูปแบบ xyz@privaterelay.appleid.com) ซึ่งจะแชร์กับแอปของคุณ หากคุณกำหนดค่าบริการส่งต่ออีเมลส่วนตัว Apple จะส่งต่ออีเมลที่ส่งไปยังอีเมลที่ลบข้อมูลระบุตัวบุคคลนั้นไปยังอีเมลจริงของผู้ใช้
การตรวจสอบสิทธิ์อีกครั้งและการลิงก์บัญชี
คุณสามารถใช้รูปแบบเดียวกันนี้กับ reauthenticateWithCredential() ซึ่งใช้เพื่อดึงข้อมูลเข้าสู่ระบบใหม่สำหรับการดำเนินการที่มีความละเอียดอ่อนซึ่งต้องมีการลงชื่อเข้าใช้ล่าสุดได้
Swift
// Initialize a fresh Apple credential with Firebase.
let credential = OAuthProvider.credential(
withProviderID: "apple.com",
IDToken: appleIdToken,
rawNonce: rawNonce
)
// Reauthenticate current Apple user with fresh Apple credential.
Auth.auth().currentUser.reauthenticate(with: credential) { (authResult, error) in
guard error != nil else { return }
// Apple user successfully re-authenticated.
// ...
}
Objective-C
FIRAuthCredential *credential = [FIROAuthProvider credentialWithProviderID:@"apple.com",
IDToken:appleIdToken,
rawNonce:rawNonce];
[[FIRAuth auth].currentUser
reauthenticateWithCredential:credential
completion:^(FIRAuthDataResult * _Nullable authResult,
NSError * _Nullable error) {
if (error) {
// Handle error.
}
// Apple user successfully re-authenticated.
// ...
}];
และคุณสามารถใช้ linkWithCredential() เพื่อลิงก์ผู้ให้บริการข้อมูลประจำตัวรายต่างๆ กับบัญชีที่มีอยู่ได้
โปรดทราบว่า Apple กำหนดให้คุณต้องได้รับความยินยอมอย่างชัดแจ้งจากผู้ใช้ก่อนที่จะลิงก์บัญชี Apple ของผู้ใช้กับข้อมูลอื่นๆ
ฟีเจอร์ลงชื่อเข้าใช้ด้วย Apple จะไม่อนุญาตให้คุณใช้ข้อมูลเข้าสู่ระบบการตรวจสอบสิทธิ์ซ้ำเพื่อลิงก์กับบัญชีที่มีอยู่ หากต้องการลิงก์ข้อมูลเข้าสู่ระบบของฟีเจอร์ลงชื่อเข้าใช้ด้วย Apple กับบัญชีอื่น คุณต้องพยายามลิงก์บัญชีโดยใช้ข้อมูลเข้าสู่ระบบของฟีเจอร์ลงชื่อเข้าใช้ด้วย Apple อันเก่าก่อน จากนั้นตรวจสอบข้อผิดพลาดที่แสดงผลเพื่อค้นหาข้อมูลเข้าสู่ระบบใหม่
ข้อมูลเข้าสู่ระบบใหม่จะอยู่ในพจนานุกรม userInfo ของข้อผิดพลาด และสามารถเข้าถึงได้ผ่านคีย์ AuthErrorUserInfoUpdatedCredentialKey
เช่น หากต้องการลิงก์บัญชี Facebook กับบัญชี Firebase ปัจจุบัน ให้ใช้โทเค็นเพื่อการเข้าถึงที่คุณได้รับจากการลงชื่อเข้าใช้ Facebook ของผู้ใช้ ดังนี้
Swift
// Initialize a Facebook credential with Firebase.
let credential = FacebookAuthProvider.credential(
withAccessToken: AccessToken.current!.tokenString
)
// Assuming the current user is an Apple user linking a Facebook provider.
Auth.auth().currentUser.link(with: credential) { (authResult, error) in
// Facebook credential is linked to the current Apple user.
// The user can now sign in with Facebook or Apple to the same Firebase
// account.
// ...
}
Objective-C
// Initialize a Facebook credential with Firebase.
FacebookAuthCredential *credential = [FIRFacebookAuthProvider credentialWithAccessToken:accessToken];
// Assuming the current user is an Apple user linking a Facebook provider.
[FIRAuth.auth linkWithCredential:credential completion:^(FIRAuthDataResult * _Nullable authResult, NSError * _Nullable error) {
// Facebook credential is linked to the current Apple user.
// The user can now sign in with Facebook or Apple to the same Firebase
// account.
// ...
}];
การเพิกถอนโทเค็น
Apple กำหนดให้แอปที่รองรับการสร้างบัญชีต้องอนุญาตให้ผู้ใช้เริ่มการลบบัญชีภายในแอปได้ ตามที่อธิบายไว้ในหลักเกณฑ์การตรวจสอบ App Store
หากต้องการปฏิบัติตามข้อกำหนดนี้ ให้ทำตามขั้นตอนต่อไปนี้
ตรวจสอบว่าคุณได้กรอกข้อมูลในส่วนรหัสบริการและการกำหนดค่าโฟลว์โค้ด OAuth ของการกำหนดค่าผู้ให้บริการฟีเจอร์ลงชื่อเข้าใช้ด้วย Apple ตามที่ระบุไว้ในส่วนกำหนดค่าฟีเจอร์ลงชื่อเข้าใช้ด้วย Apple
เนื่องจาก Firebase ไม่ได้จัดเก็บโทเค็นผู้ใช้เมื่อสร้างผู้ใช้ด้วยการลงชื่อเข้าใช้ด้วย Apple คุณจึงต้องขอให้ผู้ใช้ลงชื่อเข้าใช้อีกครั้งก่อนที่จะเพิกถอนโทเค็นและลบบัญชี
Swift
private var currentNonce: String? private func deleteCurrentUser() { do { let nonce = try CryptoUtils.randomNonceString() currentNonce = nonce let appleIDProvider = ASAuthorizationAppleIDProvider() let request = appleIDProvider.createRequest() request.requestedScopes = [.fullName, .email] request.nonce = CryptoUtils.sha256(nonce) let authorizationController = ASAuthorizationController(authorizationRequests: [request]) authorizationController.delegate = self authorizationController.presentationContextProvider = self authorizationController.performRequests() } catch { // In the unlikely case that nonce generation fails, show error view. displayError(error) } }
รับรหัสการให้สิทธิ์จาก
ASAuthorizationAppleIDCredentialและใช้รหัสดังกล่าวเพื่อเรียกใช้Auth.auth().revokeToken(withAuthorizationCode:)เพื่อเพิกถอนโทเค็นของผู้ใช้Swift
private var user: User? func authorizationController(controller: ASAuthorizationController, didCompleteWithAuthorization authorization: ASAuthorization) { guard let appleIDCredential = authorization.credential as? ASAuthorizationAppleIDCredential else { print("Unable to retrieve AppleIDCredential") return } guard let _ = currentNonce else { fatalError("Invalid state: A login callback was received, but no login request was sent.") } guard let appleAuthCode = appleIDCredential.authorizationCode else { print("Unable to fetch authorization code") return } guard let authCodeString = String(data: appleAuthCode, encoding: .utf8) else { print("Unable to serialize auth code string from data: \(appleAuthCode.debugDescription)") return } Task { do { try await Auth.auth().revokeToken(withAuthorizationCode: authCodeString) try await user?.delete() self.updateUI() } catch { self.displayError(error) } } }
สุดท้าย ให้ลบบัญชีผู้ใช้ (และข้อมูลที่เกี่ยวข้องทั้งหมด)
ขั้นตอนถัดไป
หลังจากที่ผู้ใช้ลงชื่อเข้าใช้เป็นครั้งแรก ระบบจะสร้างบัญชีผู้ใช้ใหม่และลิงก์กับข้อมูลเข้าสู่ระบบ ซึ่งได้แก่ ชื่อผู้ใช้และรหัสผ่าน หมายเลขโทรศัพท์ หรือข้อมูลผู้ให้บริการตรวจสอบสิทธิ์ที่ผู้ใช้ลงชื่อเข้าใช้ ระบบจะจัดเก็บบัญชีใหม่นี้เป็นส่วนหนึ่งของโปรเจ็กต์ Firebase และสามารถใช้เพื่อระบุผู้ใช้ในทุกแอปในโปรเจ็กต์ ไม่ว่าผู้ใช้จะลงชื่อเข้าใช้ด้วยวิธีใดก็ตาม
-
ในแอป คุณสามารถดูข้อมูลโปรไฟล์พื้นฐานของผู้ใช้ได้จากออบเจ็กต์
Userดูหัวข้อจัดการผู้ใช้ ในกฎความปลอดภัยของ Firebase Realtime Database และ Cloud Storage คุณสามารถรับรหัสผู้ใช้ที่ไม่ซ้ำกันของผู้ใช้ที่ลงชื่อเข้าใช้จากตัวแปร
authและใช้เพื่อควบคุมข้อมูลที่ผู้ใช้เข้าถึงได้
คุณสามารถอนุญาตให้ผู้ใช้ลงชื่อเข้าใช้แอปโดยใช้ผู้ให้บริการตรวจสอบสิทธิ์หลายรายได้ด้วยการลิงก์ข้อมูลเข้าสู่ระบบของผู้ให้บริการตรวจสอบสิทธิ์กับบัญชีผู้ใช้ที่มีอยู่
หากต้องการนำผู้ใช้ออกจากระบบ ให้เรียกใช้
signOut:
Swift
let firebaseAuth = Auth.auth() do { try firebaseAuth.signOut() } catch let signOutError as NSError { print("Error signing out: %@", signOutError) }
Objective-C
NSError *signOutError; BOOL status = [[FIRAuth auth] signOut:&signOutError]; if (!status) { NSLog(@"Error signing out: %@", signOutError); return; }
นอกจากนี้ คุณอาจต้องเพิ่มโค้ดการจัดการข้อผิดพลาดสำหรับข้อผิดพลาดในการตรวจสอบสิทธิ์ทั้งหมดด้วย ดูจัดการข้อผิดพลาด