firebase / firebase-ios-sdk

Firebase SDK for Apple App Development
https://firebase.google.com
Apache License 2.0
5.66k stars 1.49k forks source link

SP: Firebase not check SIGN WITH APPLE current status at launch time #9996

Open jesus-mg-ios opened 2 years ago

jesus-mg-ios commented 2 years ago

[REQUIRED] Step 1: Describe your environment

[REQUIRED] Step 2: Describe the problem

SIGN WITH APPLE

We notice that firebase not check the current token. I mean in this flow the user still be logged in:

Steps to reproduce:

Relevant Code:

We double check the firebase documentation and there's nothing related to it. Apple says that you should check the status at launch time.

https://developer.apple.com/app-store/review/guidelines/#sign-in-with-apple

Thanks in advance

rizafran commented 2 years ago

Thanks for reporting, @jesus-mg-ios. It looks like your issue is related to #9906.

jesus-mg-ios commented 2 years ago

@rizafran, thanks for your response. I think that is not related to this issue, because it is about account deletion and this issue is about remove Sign In with Apple from settings

peterfriese commented 2 years ago

Hi @jesus-mg-ios - that's right, you need to monitor the authorisation state yourself. This is because the user might be authenticated using more than just one provider (e.g. Sign in with Apple, and Email/Link or Email/Password), and it is up to the app developer to decide when to sign them out.

To monitor auth state, here are two snippets you might find useful:

Monitor authentication state while the app is running:

someSwiftUIView
  .onReceive(NotificationCenter.default.publisher(for: ASAuthorizationAppleIDProvider.credentialRevokedNotification)) { event in
    do {
      try Auth.auth().signOut()
    }
    catch {
      print(error)
    }
  }
}

Check User Credentials at Launch

Call this from your app entry point:

  func verifySignInWithAppleAuthenticationState() {
    let appleIDProvider = ASAuthorizationAppleIDProvider()
    let providerData = Auth.auth().currentUser?.providerData
    if let appleProviderData = providerData?.first(where: { $0.providerID == "apple.com" }) {
      Task {
        do {
          let credentialState = try await appleIDProvider.credentialState(forUserID: appleProviderData.uid)
          switch credentialState {
          case .authorized:
            break // The Apple ID credential is valid.
          case .revoked, .notFound:
            // The Apple ID credential is either revoked or was not found, so show the sign-in UI.
            self.signOut()
          default:
            break
          }
        }
        catch {
        }
      }
    }
  }
jesus-mg-ios commented 1 year ago

Would be great, if Firebase would provide a method with your snippet under the hood. @peterfriese

jesus-mg-ios commented 5 months ago

@ncooke3 is there any plan to provide a firebase method to automatically or opt-in check this without all teams using this kinda sign-in sign-up copy and pasting the snippet provided by @peterfriese?