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

Credentials using Oauth 2 #195

Open
thirtyninetythree opened this issue Jun 17, 2022 · 1 comment
Open

Credentials using Oauth 2 #195

thirtyninetythree opened this issue Jun 17, 2022 · 1 comment
Labels
documentation Improvements or additions to documentation

Comments

@thirtyninetythree
Copy link

How to use google sign in and enough mail to get emails from gmail without the user having to sign in with their raw credentials.

@robert-virkus robert-virkus added the documentation Improvements or additions to documentation label Jun 30, 2022
@robert-virkus
Copy link
Member

Assuming you have a valid OAuth token, you can sign in with that token.
Example for low level API:

String accessToken = await _retrieveAndRefreshAccessToken();
await imapClient.authenticateWithOAuth2(email, accessToken);

Example for high level API:

final OauthToken token = await _retrieveOauthToken();
final account = MailAccount.fromDiscoveredSettingsWithAuth(
  'acccount name',
  email, 
  OauthAuthentication(email, token), 
  discoveredClientConfig,
);
final mailClient = MailClient(
  account, 
  refresh: (mailClient, expiredToken) async {
     // TODO refresh token
     return expiredToken;
  }
}

With the above high level code you only need to fill in the google specific ways to get your token and then refresh your expired token. You can learn about gmail specific details here: https://developers.google.com/gmail/imap/xoauth2-protocol

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

No branches or pull requests

2 participants