Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getCredentialState returned an error: The operation couldn’t be completed. (com.apple.AuthenticationServices.AuthorizationError error 1000.) #7

Closed
pedro371 opened this issue Oct 28, 2019 · 25 comments

Comments

@pedro371
Copy link

pedro371 commented Oct 28, 2019

Hello guys,

when I sign in into the example, close the App and restart it, I always getting this error code:

2019-10-30 20:02:45.012873+0100 Runner[76206:1907400] [core] Credential State request returned with error: Error Domain=AKAuthenticationError Code=-7001 "(null)"
2019-10-30 20:02:45.107926+0100 Runner[76206:1907406] flutter: getCredentialState returned an error: The operation couldn’t be completed. (com.apple.AuthenticationServices.AuthorizationError error 1000.)

`[✓] Flutter (Channel master, v1.10.15-pre.285, on Mac OS X 10.15 19A602, locale de-DE)
• Flutter version 1.10.15-pre.285 at /Users/pedrolopes/Documents/workspace/flutter
• Framework revision 38f2d27685 (2 hours ago), 2019-10-28 11:28:09 -0700
• Engine revision 869b74eb4e
• Dart version 2.6.0 (build 2.6.0-dev.8.2 5b7c981086)

[✓] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
• Android SDK at /Users/pedrolopes/Library/Android/sdk
• Android NDK location not configured (optional; useful for native profiling support)
• Platform android-28, build-tools 28.0.3
• Java binary at: /Applications/Android
Studio.app/Contents/jre/jdk/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1136-b06)
• All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 11.0)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Xcode 11.0, Build version 11A420a
• CocoaPods version 1.8.3

[✓] Chrome - develop for the web
• Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 3.2)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin version 31.3.1
• Dart plugin version 181.5656
• Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1136-b06)

[✓] VS Code (version 1.39.2)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.5.1
`

@tomgilder Do you have any idea?

@wbmartin
Copy link

@pedro371, I had the same problem. The Example Project in the code ran fine which pointed me to to my xcode config. My mistake was not adding the "Sign In with Apple" Capability to all the target outputs. i.e. I added the capability to "Profile" but not the "Debug" output.

@pedro371
Copy link
Author

@wbmartin Thank your for your answer, but I added the capability...

Bildschirmfoto 2019-10-29 um 17 02 39

@kasbst
Copy link

kasbst commented Nov 8, 2019

@wbmartin Thank your for your answer, but I added the capability...

Bildschirmfoto 2019-10-29 um 17 02 39

Did you find a solution? I have exactly the same problem when trying to implement it. First time I was able to sign in successfully - then I logged out and it doesn't work anymore when I'm trying to sign in again.

EDIT: Correction - repeated login authorization works fine. My code was crashing because I'm saving givenName and familyName. The issue is that fields contained data only during my first login. Now it always returns NULL. It returns only credential.user "token" after successful authorization. I'm not sure why fullName fields are empty...

{
    credential =     {
        authorizationCode = "<FlutterStandardTypedData: 0x28071c3a0>";
        authorizedScopes =         (
        );
        email = "<null>";
        fullName =         {
            familyName = "<null>";
            givenName = "<null>";
            middleName = "<null>";
            namePrefix = "<null>";
            nameSuffix = "<null>";
            nickname = "<null>";
        };
        identityToken = "<FlutterStandardTypedData: 0x28071d540>";
        realUserStatus = 1;
        state = "<null>";
        user = "xxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxx";
    };
    credentialType = ASAuthorizationAppleIDCredential;
    status = authorized;
}

@pedro371
Copy link
Author

@kasbst

Hello, thank you for your answer. Im using the code of the example in my app and the example just saves the userID. Can you run the example without errors?

@kasbst
Copy link

kasbst commented Nov 11, 2019

@pedro371

Yes, the example code works fine. I receive the mentioned error:

2019-10-30 20:02:45.107926+0100 Runner[76206:1907406] flutter: getCredentialState returned an error: The operation couldn’t be completed. (com.apple.AuthenticationServices.AuthorizationError error 1000.)

only when running in Simulator. When running on physical device it works fine. Tested on iPad Pro 11" and iPhone 11 Pro Max.

@KaungKhantHtun
Copy link

KaungKhantHtun commented Nov 29, 2019

We need to add "Signin with Apple" in "Debug" tag. After adding there, it work fine.

Screen Shot 2019-11-29 at 1 27 11 PM

@souqgate
Copy link

souqgate commented Dec 12, 2019

hey guys did you solving for this problem cuz it happened to me

@muhmmedAbdelkhalik
Copy link

2019-12-12 at 11 39 PM
how can get data when run on physical device

@sarbjeetromanadhaliwal
Copy link

me also face this issue and remove checkLoggedInState() method now it is working fine

I use this only ::::

Future appleLogIn() async {
if(await AppleSignIn.isAvailable()) {
final AuthorizationResult result = await AppleSignIn.performRequests([
AppleIdRequest(requestedScopes: [Scope.email, Scope.fullName])
]);
switch (result.status) {
case AuthorizationStatus.authorized:
print("status=${result.status}");
print("email=${result.credential.email}");
print("fullname=${result.credential.fullName.familyName}");
print("fullname=${result.credential.fullName.givenName}");
print("user=${result.credential.user}");
print("realuserstatus=${result.credential.realUserStatus}");
break;//All the required credentials
case AuthorizationStatus.error:
print("Sign in failed: ${result.error.localizedDescription}");
break;
case AuthorizationStatus.cancelled:
print('User cancelled');
break;
}
}else{
print('Apple SignIn is not available for your device');
}
}

and no use this
void checkLoggedInState(String userId) async {
if (userId == null) {
print("No stored user ID");
return;
}
final credentialState = await AppleSignIn.getCredentialState(userId);
switch (credentialState.status) {
case CredentialStatus.authorized:
print("getCredentialState returned authorized");
break;

  case CredentialStatus.error:
    print(
        "getCredentialState returned an error: ${credentialState.error.localizedDescription}");
    break;

  case CredentialStatus.revoked:
    print("getCredentialState returned revoked");
    break;

  case CredentialStatus.notFound:
    print("getCredentialState returned not found");
    break;

  case CredentialStatus.transferred:
    print("getCredentialState returned not transferred");
    break;
}

}

Future appleLogIn() async {
if (await AppleSignIn.isAvailable()) {
final AuthorizationResult result = await AppleSignIn.performRequests([
AppleIdRequest(requestedScopes: [Scope.email, Scope.fullName])
]);
switch (result.status) {
case AuthorizationStatus.authorized:
print("status=${result.status}");
checkLoggedInState(result.credential.user);
break; //All the required credentials
case AuthorizationStatus.error:
print("Sign in failed: ${result.error.localizedDescription}");
break;
case AuthorizationStatus.cancelled:
print('User cancelled');
break;
}
} else {
print('Apple SignIn is not available for your device');
}
}

@muhmmedAbdelkhalik
Copy link

sarbjeetromanadhaliwal
not working also
2019-12-23 at 4 34 PM
it work on simulator but while test on real device not working

@muhmmedAbdelkhalik
Copy link

muhmmedAbdelkhalik commented Dec 23, 2019 via email

@sarbjeetromanadhaliwal
Copy link

sarbjeetromanadhaliwal commented Dec 24, 2019

you did apple sign in enable in xcode in Runner?

i did from this link

https://medium.com/smartters-studio/flutter-login-with-apple-3a98582f53a1

@muhmmedAbdelkhalik
Copy link

muhmmedAbdelkhalik commented Dec 24, 2019 via email

@sarbjeetromanadhaliwal
Copy link

sarbjeetromanadhaliwal commented Dec 24, 2019

muhmmedAbdelkhalik can you share your code? then i do something..
and also try with another apple login account

@muhmmedAbdelkhalik
Copy link

Here is my code @sarbjeetromanadhaliwal , and i tried with another account apple and it same
it only work on simulator on same account which i don't understand why not working on real device

import 'package:apple_sign_in/apple_sign_in.dart';
import 'package:flutter/material.dart';
import 'package:flutter_spinkit/flutter_spinkit.dart';

// Widget External
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'dart:async';

class AppleButton extends StatefulWidget {
  final text;
  final int keyButton;
  final GlobalKey<ScaffoldState> scaffoldKey3;

  AppleButton({this.text, this.keyButton, this.scaffoldKey3});

  @override
  _AppleButtonState createState() => _AppleButtonState();
}

class _AppleButtonState extends State<AppleButton> {
  String _message = '';
  bool isLoading = false;
  final Future<bool> _isAvailableFuture = AppleSignIn.isAvailable();
  String errorMessage;
  
  Future appleLogIn() async {
    if(await AppleSignIn.isAvailable()) {
      final AuthorizationResult result = await AppleSignIn.performRequests([
        AppleIdRequest(requestedScopes: [Scope.email, Scope.fullName])
      ]);
      switch (result.status) {
        case AuthorizationStatus.authorized:
          print("status=${result.status}");
          print("email=${result.credential.email}");
          print("fullname=${result.credential.fullName.familyName}");
          print("fullname=${result.credential.fullName.givenName}");
          print("user=${result.credential.user}");
          print("realuserstatus=${result.credential.realUserStatus}");
          break;//All the required credentials
        case AuthorizationStatus.error:
          print("Sign in failed: ${result.error.localizedDescription}");
          break;
        case AuthorizationStatus.cancelled:
          print('User cancelled');
          break;
      }
    }else{
      print('Apple SignIn is not available for your device');
    }
  }
  @override
  Widget build(BuildContext context) {
    return Column(
      children: <Widget>[
        isLoading == true
            ? SizedBox(
                child: SpinKitCircle(
                  color: Theme.of(context).primaryColor,
                  size: 30.0,
                ),
                width: 40,
                height: 40,
              )
            : new FutureBuilder<bool>(
                future: _isAvailableFuture,
                builder: (context, isAvailableSnapshot) {
                  if (!isAvailableSnapshot.hasData) {
                    return Container(child: Text('Loading...'));
                  }
                  if (isAvailableSnapshot.data) {
                    return Column(
                        mainAxisAlignment: MainAxisAlignment.center,
                        crossAxisAlignment: CrossAxisAlignment.center,
                        children: [
                          Container(
                            child: new IconButton(
                              icon: Icon(
                                FontAwesomeIcons.apple,
                                color: Colors.white,
                              ),
                              onPressed: appleLogIn,
                            ),
                            decoration: BoxDecoration(
                                color: Colors.black,
                                borderRadius: BorderRadius.circular(100)),
                          ),
                          if (errorMessage != null) Text(errorMessage)
                        ]);
                  } else {
                    return Text(
                        'Sign in With Apple not available. Must be run on iOS 13+');
                  }
                },
              )
      ],
    );
  }
}

@sarbjeetromanadhaliwal
Copy link

sarbjeetromanadhaliwal commented Jan 22, 2020

@muhmmedAbdelkhalik
its working only 13 version and it is give you apple login detail for only once and after that you given user id of that apple login

you can get the detail from your server where your register the data using result.credential.user
when apple login again

@0x07dc
Copy link

0x07dc commented Apr 28, 2020

I'm having this same issue, with the simulator (haven't had a chance to test it on a device yet).

Signing in works fine, and I get a user id just fine, but when I check the credentialState with final credentialState = await AppleSignIn.getCredentialState(userId); (to see if the user has logged out of their phone), I get the errors:

(from CredentialStatus.error)
localizedDescription:
The operation couldn’t be completed. (com.apple.AuthenticationServices.AuthorizationError error 1000.)
localizedFailureReason:
null
localizedRecoverySuggestion:
null

(Also mentioned in the console):

if I'm logged in to the phone, I get this error:
[core] Credential State request returned with error: Error Domain=AKAuthenticationError Code=-7073 "(null)"

if I'm logged out of the phone, I get this error:
[core] Credential State request returned with error: Error Domain=AKAuthenticationError Code=-7022 "(null)"

It's almost enough information to make my decision to log the user out or not based on whether the error code is 7073 or 7022, but I'm not sure if that would be reliable.

The capability is added in release, debug, and profile (logging in does work, just not checking if the user is still logged in to Apple on their phone).

I don't know what the error codes 7073 and 7022 mean and I can't find any information on it.

EDIT
I tried this on a device and I have new results.

The AppleSignIn.onCredentialRevoked listener gets called when I sign in to the app. It does not get called when I sign out of the phone, but it does get called when I sign into the phone. These credential state functions kind of seem pointless to me considering their behavior. I do wonder why the strange behavior, though.

@jrzerado
Copy link

muhmmedAbdelkhalik do you solve the problem?

@muhmmedAbdelkhalik
Copy link

muhmmedAbdelkhalik do you solve the problem?

it's n't problem because i have login before and it save automatic

@pojoba02
Copy link

@muhmmedAbdelkhalik i have a question pertaining to this issue

  1. Do you now get data after the authentication.
  2. Are you able to navigate to the next page.

@praharshbhatt
Copy link

I am having this issue after I upgraded flutter to 1.20.1 (Not sure if this is causing the issue).
It was working fine in all the previous versions.

@NarHakobyan
Copy link

please reopen this issue

@mbartn
Copy link

mbartn commented Oct 17, 2020

I was dealing with exactly this issue for an hour because... i didn't have the internet connection! I didn't get descriptive error for something that simple...

@Joseph-Nathan
Copy link

any news ?

@Vardiak
Copy link

Vardiak commented Dec 20, 2021

I currently face this issue... In production and only for new users. That's very strange since it worked perfectly for the past year. Any idea?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests