handleAuthorizationCode method Null safety

Future<Client> handleAuthorizationCode(
  1. String authorizationCode

Processes an authorization code directly.

Usually handleAuthorizationResponse is preferable to this method, since it validates all of the query parameters. However, some authorization servers allow the user to copy and paste an authorization code into a command-line application, in which case this method must be used.

It is a StateError to call this more than once, to call it before getAuthorizationUrl is called, or to call it after handleAuthorizationCode is called.

Throws FormatException if the authorization server provides invalid responses while retrieving credentials.

Throws AuthorizationException if the authorization fails.


Future<Client> handleAuthorizationCode(String authorizationCode) async {
  if (_state == _State.initial) {
    throw StateError('The authorization URL has not yet been generated.');
  } else if (_state == _State.finished) {
    throw StateError('The authorization code has already been received.');
  _state = _State.finished;

  return _handleAuthorizationCode(authorizationCode);