authenticateWithToken method

Future<CarpUser> authenticateWithToken({
  1. required String username,
  2. required OAuthToken token,
})

Authenticate to this CARP web service using username and a previously stored OAuthToken access token.

This method can be used to re-authenticate a user if the token (and username) is known locally on the phone. Useful for keeping the token locally on the phone between starting/stopping the app.

Return the signed in user (with an OAuthToken access token), if successful. Throws a CarpServiceException if not successful.

Implementation

Future<CarpUser> authenticateWithToken({
  required String username,
  required OAuthToken token,
}) async {
  _currentUser = CarpUser(username: username)..authenticated(token);

  // refresh the token - it might have expired since it was saved.
  await refresh();

  await getCurrentUserProfile();
  _authEventController.add(AuthEvent.authenticated);
  return _currentUser!;
}