Search code examples
iosobjective-cgoogle-signinmailcore2gidsignin

Error Domain=MCOErrorDomain Code=5 "Unable to authenticate with the current session's credentials."


I am getting this error while calling the checkAccountOperation method for imapSession

Error Domain=MCOErrorDomain Code=5 "Unable to authenticate with the current session's credentials." UserInfo={NSLocalizedDescription=Unable to authenticate with the current session's credentials.}

Here is my code:

MCOIMAPSession *session = [[MCOIMAPSession alloc] init];
session.dispatchQueue = self.imapQueue;
session.hostname = @"imap.gmail.com";
session.port = 993;
session.maximumConnections = 2;
session.username = emailAddress; //email address with which I logged in
session.password = nil;
session.OAuth2Token = accessToken; // access Token got in success response of google sign in
session.authType = MCOAuthTypeXOAuth2;
session.connectionType = MCOConnectionTypeTLS;
dispatch_async(self.imapQueue, ^{
    MCOIMAPOperation *imapCheckOp = [session checkAccountOperation];

    [imapCheckOp start:^(NSError *errorResults)
     {
         NSLog(@"%@",errorResults);
     }];
});

I am using google sign in SDK to log in to the google account

self.googleSignIn = [GIDSignIn sharedInstance];
self.googleSignIn.delegate = self;
self.googleSignIn.uiDelegate = self;
NSString *path = [[NSBundle mainBundle] pathForResource: @"GoogleService-Info" ofType: @"plist"];
NSMutableDictionary *googleDictplist =[[NSMutableDictionary alloc] initWithContentsOfFile:path];
NSString *googleClientId = [NSString stringWithFormat:@"%@",[googleDictplist objectForKey:@"CLIENT_ID"]];
self.googleSignIn.clientID = googleClientId;
[self.googleSignIn signIn];

I have tried almost all the possible solutions which I got from the web for the same issue. I have all the needed APIs enabled for my project under Google Developer console. This issue is still there even if I give my password while creating the imapSession. Started facing this issue after I updated the sign in into the way which uses latest google sign in SDK.


Solution

  • You haven’t given any scope for the google sign in instance. Try adding scopes for the same

    self.googleSignIn.scopes = [NSArray arrayWithObjects:@"https://www.googleapis.com/auth/userinfo.profile" ,@"https://www.googleapis.com/auth/userinfo.email", @"https://mail.google.com",@"https://www.google.com/m8/feeds/", nil];