SignIn with apple on web fails - Authentication failed with UNKNOWN_SIWA_ERROR
Closed this issue · 4 comments
I am using sign_in_with_apple: ^4.2.0 and flutter version 3.3.10
Sign-in with Apple just throws this error Authentication failed with UNKNOWN_SIWA_ERROR
On further debugging, I see it fails with the following exception
JSNoSuchMethodError (TypeError: Cannot read properties of undefined (reading 'auth'))
"Error: SignInWithAppleCredentialsException(Authentication failed with UNKNOWN_SIWA_ERROR)
dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/errors.dart 266:49 throw_
packages/sign_in_with_apple_web/sign_in_with_apple_web.dart 66:7 getAppleIDCredential
dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 84:54 runBody
dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 123:5 _async
packages/sign_in_with_apple_web/sign_in_with_apple_web.dart 26:62 getAppleIDCredential
packages/sign_in_with_apple/src/sign_in_with_apple.dart 74:45 getAppleIDCredential
dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 84:54 runBody
dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 123:5 _async
packages/sign_in_with_apple/src/sign_in_with_apple.dart 54:69 getAppleIDCredential
packages/accounts_library/data/auth_repository_impl.dart 174:51 _getAppleCredentials
dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 84:54 runBody
dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 123:5 _async
packages/accounts_library/data/auth_repository_impl.dart 169:51 [_getAppleCredentials]
packages/accounts_library/data/auth_repository_impl.dart 58:13 <fn>
packages/accounts_library/data/auth_repository_impl.dart 217:36 _handleAuthOperation
dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 84:54 runBody
dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 123:5 _async
packages/accounts_library/data/auth_repository_impl.dart 213:60 [_handleAuthOperation]
packages/accounts_library/data/auth_repository_impl.dart 57:12 signInWithApple
dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 84:54 runBody
dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 123:5 _async
packages/accounts_library/data/auth_repository_impl.dart 56:50 signInWithApple
packages/tutoring_app/src/features/onboarding/domain/usecases/social_login.dart 40:33 resolve
dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 84:54 runBody
dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 123:5 _async
packages/tutoring_app/src/features/onboarding/domain/usecases/social_login.dart 38:36 resolve
packages/pearl/src/usecase/usecase.dart 196:28 observableResolve
packages/pearl/src/usecase/usecase.dart 313:12 call
packages/tutoring_app/src/features/onboarding/presentation/widgets/login_form.dart 199:42 loginWithApple
dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 45:50 <fn>
dart-sdk/lib/async/zone.dart 1653:54 runUnary
dart-sdk/lib/async/future_impl.dart 147:18 handleValue
dart-sdk/lib/async/future_impl.dart 766:44 handleValueCallback
dart-sdk/lib/async/future_impl.dart 795:13 _propagateToListeners
dart-sdk/lib/async/future_impl.dart 566:5 [_completeWithValue]
dart-sdk/lib/async/future_impl.dart 505:11 <fn>
dart-sdk/lib/async/zone.dart 1653:54 runUnary
dart-sdk/lib/async/future_impl.dart 147:18 handleValue
dart-sdk/lib/async/future_impl.dart 766:44 handleValueCallback
dart-sdk/lib/async/future_impl.dart 795:13 _propagateToListeners
dart-sdk/lib/async/future_impl.dart 566:5 [_completeWithValue]
dart-sdk/lib/async/future_impl.dart 639:7 callback
dart-sdk/lib/async/schedule_microtask.dart 40:11 _microtaskLoop
dart-sdk/lib/async/schedule_microtask.dart 49:5 _startMicrotaskLoop
dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 166:15 <fn>
"
final appleAuthCred = await SignInWithApple.getAppleIDCredential(
webAuthenticationOptions: kIsWeb
? WebAuthenticationOptions(
clientId: "my-client-id"',
redirectUri: Uri(host: Uri.base.host, scheme: Uri.base.scheme, path: '/login'),
)
: null,
scopes: [
AppleIDAuthorizationScopes.fullName,
AppleIDAuthorizationScopes.email,
],
nonce: nonce,
);
Any leads would be really helpful. Thanks.
Never mind I was missing the script tag in index.html
<script type="text/javascript" src="https://appleid.cdn-apple.com/appleauth/static/jsapi/appleid/1/en_US/appleid.auth.js"></script>
Never mind I was missing the script tag in index.html
<script type="text/javascript" src="https://appleid.cdn-apple.com/appleauth/static/jsapi/appleid/1/en_US/appleid.auth.js"></script>
How did you find this solution? Is this documented somewhere?
Its on plugin page, look under web section
https://pub.dev/packages/sign_in_with_apple
Thanks. One more question if could help out with, since apple doesn't allow local host testing, is it safe to assume that my flutter web page domain should be set to the redirect uri?
For example, the web page has this URL: https://www.myflutterapp.com/#/sigin
In this case redirect URI can be set to https://www.myflutterapp.com and the control will still land on the line where we print the credentials? So far it worked for mobile app but I can not test it on localhost so have to deploy assuming that possibility.