getAuthUrl method

Future<String> getAuthUrl({
  1. List<Oauth2Scopes>? scopes,
  2. String? state,
})

Gets the auth url for a user to connect to your app with Quickbooks. The connection with this url will provide an authorization code to get the Oauth2 tokens.

The scopes you give represents the data you ask authorization to see. If you don't specify it, the link will ask all scopes

The state you give is a verification String for quickbooks to verify if the connection has been successfull. Can be anything. It overrides the state given in the constructor.

Implementation

Future<String> getAuthUrl({List<Oauth2Scopes>? scopes, String? state}) async {
  // Gets the configuration for the current use.
  var config =
      await _configService.getConfiguration(isProduction: _isProduction);

  // Gets the oauth2 client
  var grant = oauth2.AuthorizationCodeGrant(
      _clientId,
      Uri.parse(config.authorizationEndpoint),
      Uri.parse(config.tokenEndpoint),
      secret: _clientSecret);

  // Defines the scopes to ask
  scopes ??= [
    Oauth2Scopes.accounting,
    Oauth2Scopes.openid,
    Oauth2Scopes.profile,
    Oauth2Scopes.email,
    Oauth2Scopes.phone,
    Oauth2Scopes.address,
  ];
  var scopesStrings =
      Oauth2ScopesConvertExtension.generateScopeStrings(scopes: scopes);

  //Gets the autorization url
  var authorizationUrl = grant.getAuthorizationUrl(Uri.parse(_redirectUrl),
      scopes: scopesStrings, state: state ?? _state);

  //Returns the authorization url string
  var urlString = authorizationUrl.toString();

  return urlString;
}