Search code examples
fluttersupabaseapple-sign-in

Unable to Sign in with Apple from the iOS app and Supabase Authentication


I'm unable to sign in with Apple and Supabase Authentication from my iOS app.

  • Created an app with co.xx.mobile as app bundle ID (xx is used here to hide the app name)
  • Added "Sign with Apple" in signing and capabilities
  • Created "Services ID" and configured URLs for supabase : domain: https://xx.supabase.co and redirect url: https://xx.supabase.co/auth/v1/callback
  • Created the key with "Sign in with Apple" selected.
  • Generated the secret key using secret_gen.rb scriptenter image description here credential.authorizationCode and credential.identityToken are not empty I got this error: flutter: ----------------FIREBASE CRASHLYTICS---------------- flutter: AuthException(message: Bad ID token, statusCode: 400) Any idea how to fix this?
Future<AuthResponse> _signInWithApple() async {
    final rawNonce = supabase.auth.generateRawNonce();
    final hashedNonce = sha256.convert(utf8.encode(rawNonce)).toString();
    final credential = await SignInWithApple.getAppleIDCredential(
      scopes: [
        AppleIDAuthorizationScopes.email,
        AppleIDAuthorizationScopes.fullName,
      ],
      nonce: hashedNonce,
    );
    final idToken = credential.identityToken!;
    if (idToken == null) {
      throw const AuthException('Could not find ID Token from generated credential.');
    }
    try {
      return supabase.auth.signInWithIdToken(
        provider: OAuthProvider.apple,
        idToken: idToken,
        nonce: rawNonce,
      );
    } catch (e) {
      throw AuthException(e.toString());
    }
  }

Solution

  • There was an change made on the Apple API, and older versions of Gotrue (Supabase Auth server) will throw this error. You can update the gotrue version manually, or wait until the new version is rolled out.