googleapis_auth
googleapis_auth copied to clipboard
Throw a better error when a serviceAccount ClientId is used with obtainAccessCredentialsViaUserConsentManual
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>
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.