ตรวจสอบสิทธิ์โดยใช้ Apple

คุณอนุญาตให้ผู้ใช้ตรวจสอบสิทธิ์กับ Firebase โดยใช้ Apple ID ได้โดยทำดังนี้ โดยใช้ Firebase SDK เพื่อดำเนินการขั้นตอนการลงชื่อเข้าใช้ OAuth 2.0 แบบต้นทางถึงปลายทาง

ก่อนเริ่มต้น

หากต้องการลงชื่อเข้าใช้ให้ผู้ใช้ด้วย Apple ให้กำหนดค่าการลงชื่อเข้าใช้ด้วย Apple ก่อน ในเว็บไซต์ของนักพัฒนาซอฟต์แวร์ Apple จากนั้นให้ Apple เป็นผู้ให้บริการการลงชื่อเข้าใช้สำหรับ โปรเจ็กต์ Firebase

เข้าร่วมโปรแกรมนักพัฒนาซอฟต์แวร์ของ Apple

เฉพาะสมาชิกของนักพัฒนาซอฟต์แวร์ Apple เท่านั้นที่สามารถกำหนดค่าฟีเจอร์ลงชื่อเข้าใช้ด้วย Apple ได้ โปรแกรม

กำหนดค่าการลงชื่อเข้าใช้ด้วย Apple

  1. เปิดใช้การลงชื่อเข้าใช้ด้วย Apple สำหรับแอปของคุณใน ใบรับรอง ตัวระบุ และ โปรไฟล์ หน้าเว็บไซต์นักพัฒนาซอฟต์แวร์ของ Apple
  2. เชื่อมโยงเว็บไซต์กับแอปตามที่อธิบายไว้ในส่วนแรก ในหัวข้อกำหนดค่าการลงชื่อเข้าใช้ด้วย Apple สำหรับเว็บ เมื่อได้รับข้อความแจ้ง ให้ลงทะเบียน URL ต่อไปนี้เป็น URL ย้อนกลับ:
    https://YOUR_FIREBASE_PROJECT_ID.firebaseapp.com/__/auth/handler
    คุณสามารถรับรหัสโปรเจ็กต์ Firebase ได้ในหน้าการตั้งค่าคอนโซล Firebase เมื่อทำเสร็จแล้ว ให้จดรหัสบริการใหม่ที่ต้องใช้ หัวข้อถัดไป
  3. สร้าง ลงชื่อเข้าใช้ด้วยคีย์ส่วนตัวของ Apple คุณจะต้องมีคีย์ส่วนตัวและคีย์ส่วนตัวใหม่ รหัสในส่วนถัดไป
  4. หากใช้ฟีเจอร์การตรวจสอบสิทธิ์ Firebase ที่ส่งอีเมลถึงผู้ใช้ ซึ่งรวมถึงการลงชื่อเข้าใช้ลิงก์อีเมล, การยืนยันที่อยู่อีเมล, การเปลี่ยนแปลงบัญชี การเพิกถอน และ อื่นๆ ให้กำหนดค่าบริการส่งต่ออีเมลส่วนตัวของ Apple และลงทะเบียน noreply@YOUR_FIREBASE_PROJECT_ID.firebaseapp.com (หรือโดเมนเทมเพลตอีเมลที่กำหนดเอง) เพื่อให้ Apple ส่งต่ออีเมลที่ส่งได้ ผ่านการตรวจสอบสิทธิ์ Firebase ไปยังอีเมล Apple ที่ไม่ระบุตัวตน

เปิดใช้ Apple เป็นผู้ให้บริการการลงชื่อเข้าใช้

  1. เพิ่ม Firebase ลงในโปรเจ็กต์ Apple อย่าลืม ลงทะเบียนรหัสชุดของแอปเมื่อคุณตั้งค่าแอปใน คอนโซล Firebase
  2. ในคอนโซล Firebase ให้เปิดส่วนการตรวจสอบสิทธิ์ ในแท็บวิธีการลงชื่อเข้าใช้ เปิดใช้ผู้ให้บริการ Apple ระบุรหัสบริการที่คุณสร้างไว้ในส่วนก่อนหน้า นอกจากนี้ ใน ส่วนการกำหนดค่าขั้นตอนของรหัส OAuth ให้ระบุรหัสทีม Apple และ คีย์ส่วนตัวและรหัสคีย์ที่คุณสร้างไว้ในส่วนก่อนหน้านี้

ปฏิบัติตามข้อกำหนดด้านข้อมูลที่ไม่ระบุตัวบุคคลของ Apple

ฟีเจอร์ลงชื่อเข้าใช้ด้วย Apple ช่วยให้ผู้ใช้เลือกลบข้อมูลระบุตัวบุคคลได้ รวมถึงอีเมลเมื่อลงชื่อเข้าใช้ ผู้ใช้ที่เลือกตัวเลือกนี้ มีที่อยู่อีเมลในโดเมน privaterelay.appleid.com วันและเวลา หากใช้ฟีเจอร์ลงชื่อเข้าใช้ด้วย Apple ในแอป คุณจะต้องปฏิบัติตาม นโยบายหรือข้อกำหนดสำหรับนักพัฒนาซอฟต์แวร์จาก Apple เกี่ยวกับ Apple ที่มีการลบข้อมูลระบุตัวบุคคลเหล่านี้ รหัส

ซึ่งรวมถึงการได้รับความยินยอมที่จำเป็นจากผู้ใช้ก่อนคุณ เชื่อมโยงข้อมูลส่วนบุคคลที่ระบุตัวบุคคลนั้นได้โดยตรงกับ Apple ที่มีการลบข้อมูลระบุตัวบุคคล ID เมื่อใช้การตรวจสอบสิทธิ์ Firebase อาจรวมถึงสิ่งต่อไปนี้ การดำเนินการ:

  • ลิงก์อีเมลกับ Apple ID ที่ไม่ระบุตัวตนหรือในทางกลับกัน
  • ลิงก์หมายเลขโทรศัพท์กับ Apple ID ที่ไม่ระบุตัวตนหรือในทางกลับกัน
  • ลิงก์ข้อมูลเข้าสู่ระบบโซเชียลที่ระบุตัวบุคคลไม่ได้ (Facebook, Google ฯลฯ) กับ Apple ID ที่ไม่ระบุตัวตนหรือในทางกลับกัน

รายการด้านบนเป็นเพียงตัวอย่างบางส่วนเท่านั้น เข้าร่วมโปรแกรมนักพัฒนาซอฟต์แวร์ของ Apple ข้อตกลงการอนุญาตให้ใช้สิทธิในส่วนการเป็นสมาชิกของบัญชีนักพัฒนาแอป ให้แอปของคุณเป็นไปตามข้อกำหนดของ Apple

ลงชื่อเข้าใช้ด้วย Apple และตรวจสอบสิทธิ์ด้วย Firebase

หากต้องการตรวจสอบสิทธิ์ด้วยบัญชี Apple ให้ลงชื่อเข้าใช้ Apple ให้ผู้ใช้ก่อน โดยใช้เฟรมเวิร์ก AuthenticationServices ของ Apple แล้วใช้โทเค็นรหัสจากการตอบสนองของ Apple เพื่อสร้าง Firebase ออบเจ็กต์ AuthCredential รายการ:

  1. สร้างสตริงแบบสุ่มให้กับคำขอลงชื่อเข้าใช้ทุกรายการ "nonce" ซึ่งคุณจะใช้เพื่อตรวจสอบว่าโทเค็นรหัสที่ได้มา ที่ได้รับ ซึ่งเป็นการตอบสนองต่อคำขอการตรวจสอบสิทธิ์ของแอปโดยเฉพาะ ช่วงเวลานี้ เป็นสิ่งสำคัญในการป้องกันการโจมตีซ้ำ

    คุณสามารถสร้าง 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;
    }
        
  2. เริ่มขั้นตอนการลงชื่อเข้าใช้ของ 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];
    }
    
  3. จัดการคำตอบของ Apple ในการใช้งาน ASAuthorizationControllerDelegate. หากลงชื่อเข้าใช้สำเร็จ ให้ใช้รหัส โทเค็นจากการตอบสนองของ Apple ที่มีค่าที่ได้จากการแฮชที่ไม่ได้แฮชเพื่อตรวจสอบสิทธิ์ 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 ไม่เหมือนกับผู้ให้บริการรายอื่นๆ ที่ Firebase Auth รองรับ URL ของภาพถ่าย

นอกจากนี้ เมื่อผู้ใช้เลือกที่จะไม่แชร์อีเมลกับแอป 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" กับข้อมูลเข้าสู่ระบบอื่น ขั้นแรก คุณต้องพยายามเชื่อมโยงบัญชีโดยใช้การลงชื่อเข้าใช้ด้วยเวอร์ชันเก่า แล้วตรวจสอบข้อผิดพลาดที่ส่งคืนเพื่อหาข้อมูลเข้าสู่ระบบใหม่ ข้อมูลเข้าสู่ระบบใหม่จะอยู่ในพจนานุกรม 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 หลักเกณฑ์

โปรดทำตามขั้นตอนต่อไปนี้เพื่อให้เป็นไปตามข้อกำหนดนี้

  1. ตรวจสอบว่าได้กรอกรหัสบริการและการกำหนดค่าโฟลว์ของรหัส OAuth แล้ว ของการกำหนดค่าฟีเจอร์ลงชื่อเข้าใช้ด้วยผู้ให้บริการของ Apple ตามที่ระบุไว้ใน ส่วนกำหนดค่าการลงชื่อเข้าใช้ด้วย Apple

  2. เนื่องจาก Firebase จะไม่จัดเก็บโทเค็นผู้ใช้เมื่อมีการสร้างผู้ใช้ด้วย ลงชื่อเข้าใช้ด้วย Apple คุณต้องขอให้ผู้ใช้ลงชื่อเข้าใช้อีกครั้งก่อนเพิกถอน โทเค็นและการลบบัญชี

    Swift

    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)
      }
    }
    
    
  3. รับรหัสการให้สิทธิ์จาก ASAuthorizationAppleIDCredential และ ใช้เพื่อเรียก Auth.auth().revokeToken(withAuthorizationCode:) เพื่อเพิกถอน โทเค็นของผู้ใช้

    Swift

    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)
        }
      }
    }
    
    
  4. สุดท้าย ให้ลบบัญชีผู้ใช้ (และข้อมูลที่เกี่ยวข้องทั้งหมด)

ขั้นตอนถัดไป

หลังจากผู้ใช้ลงชื่อเข้าใช้เป็นครั้งแรก ระบบจะสร้างบัญชีผู้ใช้ใหม่ และ ซึ่งก็คือชื่อผู้ใช้และรหัสผ่าน โทรศัพท์ หมายเลข หรือข้อมูลของผู้ให้บริการตรวจสอบสิทธิ์ ซึ่งก็คือผู้ใช้ที่ลงชื่อเข้าใช้ ใหม่นี้ จัดเก็บเป็นส่วนหนึ่งของโปรเจ็กต์ Firebase และสามารถใช้เพื่อระบุ ผู้ใช้สำหรับทุกแอปในโปรเจ็กต์ของคุณ ไม่ว่าผู้ใช้จะลงชื่อเข้าใช้ด้วยวิธีใดก็ตาม

  • ในแอป คุณสามารถดูข้อมูลโปรไฟล์พื้นฐานของผู้ใช้ได้จาก User โปรดดูหัวข้อจัดการผู้ใช้

  • ในฐานข้อมูลเรียลไทม์และ Cloud Storage ของ Firebase กฎความปลอดภัย คุณสามารถทำสิ่งต่อไปนี้ รับรหัสผู้ใช้ที่ไม่ซ้ำของผู้ใช้ที่ลงชื่อเข้าใช้จากตัวแปร 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;
}

คุณอาจต้องเพิ่มโค้ดการจัดการข้อผิดพลาดสำหรับการตรวจสอบสิทธิ์ทั้งหมดด้วย โปรดดูหัวข้อจัดการข้อผิดพลาด