authenticateWithOAuthBearer method

Future<GenericImapResult> authenticateWithOAuthBearer(
  1. String user,
  2. String accessToken, {
  3. String? host,
  4. int? port,
})

Logs in the user with the given user and accessToken via Oauth Bearer mechanism.

Optionally specify the host and port of the service, per default the current connection is used. Note that the capability 'AUTH=OAUTHBEARER' needs to be present. Compare https://tools.ietf.org/html/rfc7628 for details

Implementation

Future<GenericImapResult> authenticateWithOAuthBearer(
    String user, String accessToken,
    {String? host, int? port}) async {
  host ??= serverInfo.host;
  port ??= serverInfo.port;
  final authText =
      'n,u=$user,\u{0001}host=$host\u{0001}port=$port\u{0001}auth=Bearer $accessToken\u{0001}\u{0001}';
  final authBase64Text = base64.encode(utf8.encode(authText));
  final cmd = Command('AUTHENTICATE OAUTHBEARER $authBase64Text');
  cmd.logText = 'AUTHENTICATE OAUTHBEARER (base64 code scrambled)';
  final response = await sendCommand<GenericImapResult>(
      cmd, GenericParser(this, _selectedMailbox));
  isLoggedIn = true;
  return response;
}