authenticateWithOAuth2 method

Future<List<Capability>> authenticateWithOAuth2(
  1. String user,
  2. String accessToken
)

Logs in the user with the given user and accessToken via Oauth 2.0.

Note that the capability 'AUTH=XOAUTH2' needs to be present.

Implementation

Future<List<Capability>> authenticateWithOAuth2(
  String user,
  String accessToken,
) async {
  final authText =
      'user=$user\u{0001}auth=Bearer $accessToken\u{0001}\u{0001}';
  final authBase64Text = base64.encode(utf8.encode(authText));
  // the empty client response to a challenge yields the actual server
  // error message response
  final cmd = Command.withContinuation(
    ['AUTHENTICATE XOAUTH2 $authBase64Text', ''],
    logText: 'AUTHENTICATE XOAUTH2 (base64 code scrambled)',
    writeTimeout: defaultWriteTimeout,
    responseTimeout: defaultResponseTimeout,
  );
  final response =
      await sendCommand<List<Capability>>(cmd, CapabilityParser(serverInfo));
  isLoggedIn = true;

  return response;
}