dart-archive / googleapis_auth

Obtain OAuth 2.0 credentials to access Google APIs
https://pub.dev/packages/googleapis_auth
BSD 3-Clause "New" or "Revised" License
38 stars 26 forks source link

Throw a better error when a serviceAccount ClientId is used with obtainAccessCredentialsViaUserConsentManual #17

Open kevmoo opened 9 years ago

kevmoo commented 9 years ago

The URL encoding fails with a an unhelpful error because the ClientId has a null secret.

The null object does not have a getter 'length'.

NoSuchMethodError: method not found: 'length'
Receiver: null
Arguments: []
dart:core                                                       Uri.encodeQueryComponent
package:googleapis_auth/src/oauth2_flows/auth_code.dart 54:28   obtainAccessCredentialsUsingCode
package:googleapis_auth/src/oauth2_flows/auth_code.dart 123:12  AuthorizationCodeGrantAbstractFlow._obtainAccessCredentialsUsingCode
package:googleapis_auth/src/oauth2_flows/auth_code.dart 260:14  AuthorizationCodeGrantManualFlow.run.<fn>
Pacane commented 9 years ago

Shouldn't this not throw an error at all? I thought we didn't need to provide a secret when using a serviceAccount, am I wrong?

I feel like

Future<AccessCredentials> obtainAccessCredentialsUsingCode(
    ClientId clientId, String code, String redirectUrl, http.Client client,
    [List<String> scopes]) {
  var uri = Uri.parse('https://accounts.google.com/o/oauth2/token');
  var formValues = [
      'grant_type=authorization_code',
      'code=${Uri.encodeQueryComponent(code)}',
      'redirect_uri=${Uri.encodeQueryComponent(redirectUrl)}',
      'client_id=${Uri.encodeQueryComponent(clientId.identifier)}',
      'client_secret=${Uri.encodeQueryComponent(clientId.secret)}',
  ];
// ....

should do a null check for clientId.secret before encoding it.