enough_mail_app icon indicating copy to clipboard operation
enough_mail_app copied to clipboard

Yahoo authentication error, server error please try later, this error is throwing every time, i try to authenticate the user using oauth, i am able to receive the accesstoken, but when i pass this token yahoo authentication fails.

Open Shadman12345 opened this issue 4 years ago • 1 comments


Future<OauthToken?> yahooSignin(String email) async {
    const clientId =
        "dj0yJmk9Z2NLU1hNY2VWUXZaJmQ9WVdrOVYyUlFZekJhZEd3bWNHbzlNQT09JnM9Y29uc3VtZXJzZWNyZXQmc3Y9MCZ4PTdk";
    const clientSecret = "a7d02a453b74888e772cf2244d1d51a35c2c675e";
    const callbackUrlScheme = 'emaily://oauth';

    if (await _storage.isLoggedin()) {
      final String mailClient = (await _storage.client())!;
      final String refreshToken = (await _storage.getToken())!;
      final token = await getRefreshToken(mailClient, refreshToken);

      return token;
    } else {
      final url = Uri.https('api.login.yahoo.com', '/oauth2/request_auth', {
        'client_id': clientId,
        'client_secret': clientSecret,
        'response_type': 'code',
        'redirect_uri': callbackUrlScheme,
        'scope': "mail-r",
      });

      log(url.toString());

      final result = await FlutterWebAuth.authenticate(
          url: url.toString(), callbackUrlScheme: "emaily");

      final code = Uri.parse(result).queryParameters['code']!;

      final response = await http.post(
        Uri.parse('https://api.login.yahoo.com/oauth2/get_token'),
        body: {
          'client_id': clientId,
          'client_secret': clientSecret,
          'redirect_uri': callbackUrlScheme,
          'grant_type': 'authorization_code',
          'code': code,
        },
      );
      final OauthToken token =
          Get.put(OauthToken.fromText(response.body), tag: "token");

      log(token.toString());

      await _storage.setToken(token.refreshToken);

      return token;
    }
  }

Future<MailAccount> yahooMailAccount(
      String userName, OauthToken? token) async {
    MailAccount mailAccount = MailAccount.fromManualSettingsWithAuth(
      "yahoo.com",
      userName,
      "imap.mail.yahoo.com",
      "smtp.mail.yahoo.com",
      OauthAuthentication(userName, token),
    );

    return mailAccount;
  }


final ImapClient client = ImapClient(isLogEnabled: true);
late final MailClient mailClient;

final token = await _oauth.yahooSignin(userName);
await client.connectToServer("imap.mail.yahoo.com", 993, isSecure: true);
await client.authenticateWithOAuth2(userName, token!.accessToken);
mailAccount = await _accountClient.yahooMailAccount(userName, token);

mailClient = MailClient(mailAccount, logName: mailAccount.name, refresh: refresh);

await mailClient.connect();
      

Shadman12345 avatar Nov 10 '21 12:11 Shadman12345

I/flutter (13144): A: connecting to server imap.mail.yahoo.com:993 - secure: true I/flutter (13144): S: * OK [CAPABILITY IMAP4rev1 SASL-IR AUTH=PLAIN AUTH=XOAUTH2 AUTH=OAUTHBEARER ID MOVE NAMESPACE XYMHIGHESTMODSEQ UIDPLUS LITERAL+ CHILDREN X-MSG-EXT OBJECTID] IMAP4rev1 Hello I/flutter (13144): C: a0 AUTHENTICATE XOAUTH2 (base64 code scrambled) I/flutter (13144): S: a0 NO [AUTHENTICATIONFAILED] AUTHENTICATE Server error - Please try again later D/CompatibilityChangeReporter(13144): Compat change id reported: 147798919; UID 10161; state: ENABLED

Shadman12345 avatar Nov 10 '21 12:11 Shadman12345