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

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. #61

Open
Shadman12345 opened this issue Nov 10, 2021 · 1 comment

Comments

@Shadman12345
Copy link

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 Shadman12345 changed the title Hi, I am able yahoo mail accesstoken, but when i passed the token to the OAuth 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. Nov 10, 2021
@Shadman12345
Copy link
Author

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

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

1 participant