aboutyou / dart_packages

Dart and Flutter plugins maintained and used by @ABOUTYOU
220 stars 149 forks source link

Sign in with Apple" Fails on Flutter Web #435

Closed AlmutawakelSukaina closed 1 week ago

AlmutawakelSukaina commented 1 week ago

error apple sign in

Description:

When attempting to use Sign in with Apple on my Flutter web app, I encounter the following error message:

Your request could not be completed because of an error. Please try again later.

The issue only occurs on the web platform. The implementation works as expected on Android and iOS devices.

Build Information:

Index.html Setup:

<!DOCTYPE html>
<html lang="en">
<head>
    <base href="/">
    <meta charset="UTF-8">
    <meta content="IE=Edge" http-equiv="X-UA-Compatible">

    <!-- iOS meta tags & icons -->
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-title" content="Azer">
    <link rel="apple-touch-icon" href="icons/Icon-192.png">

    <!-- Icons and Favicons -->
    <link rel="icon" type="image/png" href="favicon.png"/>
    <link rel="icon" type="image/png" sizes="32x32" href="favicon-32x32.png">

    <!-- Manifest -->
    <link rel="manifest" href="manifest.json">

    <!-- Preconnect and DNS Prefetch for External Resources -->
    <link rel="preconnect" href="https://appleid.cdn-apple.com" crossorigin>
    <link rel="dns-prefetch" href="https://appleid.cdn-apple.com">

    <!-- Apple sign-in script -->
    <script type="text/javascript" src="https://appleid.cdn-apple.com/appleauth/static/jsapi/appleid/1/en_US/appleid.auth.js" defer></script>
</head>

<body>
    <!-- Load the Flutter Bootstrap script -->
    <script src="./flutter_bootstrap.js" async></script>
</body>
</html>

Dart Code for Sign in with Apple:

final credential = await SignInWithApple.getAppleIDCredential(
  scopes: [
    AppleIDAuthorizationScopes.email,
    AppleIDAuthorizationScopes.fullName,
  ],
  webAuthenticationOptions: WebAuthenticationOptions(
    clientId: 'serviceId',
    redirectUri: Uri.parse('my url'),
  ),
);

Steps to Reproduce:

  1. Implement "Sign in with Apple" in the Flutter web app.
  2. Deploy the web app.
  3. Attempt to sign in using an Apple ID.

Expected Behavior:

Users should be able to successfully sign in with Apple on the web, just as they can on Android and iOS devices.

Actual Behavior:

An error is returned on web:

Your request could not be completed because of an error. Please try again later.

Additional Information:

AlmutawakelSukaina commented 1 week ago

The issue has been resolved by adjusting the redirect URI settings:

For web, the redirect URI needs to be the host of the current page.