Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[gsi_web] Do not initialize CodeClient if scopes are empty. #5537

Merged
merged 3 commits into from
Dec 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion packages/google_sign_in/google_sign_in_web/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
## 0.12.2
## 0.12.2+1

* Re-publishes `0.12.2` with a small fix to the CodeClient initialization.

## 0.12.2 (withdrawn)

* Adds server auth code retrieval to google_sign_in_web.
* Adds `web_only` library to access web-only methods more easily.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,15 @@ class GisSdkClient {
onError: _onTokenError,
);

_codeClient = _initializeCodeClient(
clientId,
hostedDomain: hostedDomain,
onResponse: _onCodeResponse,
onError: _onCodeError,
scopes: initialScopes,
);
if (initialScopes.isNotEmpty) {
_codeClient = _initializeCodeClient(
clientId,
hostedDomain: hostedDomain,
onResponse: _onCodeResponse,
onError: _onCodeError,
scopes: initialScopes,
);
}
}

void _logIfEnabled(String message, [List<Object?>? more]) {
Expand Down Expand Up @@ -291,7 +293,13 @@ class GisSdkClient {
/// Requests a server auth code per:
/// https://developers.google.com/identity/oauth2/web/guides/use-code-model#initialize_a_code_client
Future<String?> requestServerAuthCode() async {
_codeClient.requestCode();
// TODO(dit): Enable granular authorization, https://github.com/flutter/flutter/issues/139406
assert(_codeClient != null,
'CodeClient not initialized correctly. Ensure the `scopes` list passed to `init()` or `initWithParams()` is not empty!');
ditman marked this conversation as resolved.
Show resolved Hide resolved
if (_codeClient == null) {
return null;
}
_codeClient!.requestCode();
final CodeResponse response = await _codeResponses.stream.first;
return response.code;
}
Expand Down Expand Up @@ -461,7 +469,8 @@ class GisSdkClient {

// The Google Identity Services client for oauth requests.
late TokenClient _tokenClient;
late CodeClient _codeClient;
// CodeClient will not be created if `initialScopes` is empty.
CodeClient? _codeClient;

// Streams of credential and token responses.
late StreamController<CredentialResponse> _credentialResponses;
Expand Down
2 changes: 1 addition & 1 deletion packages/google_sign_in/google_sign_in_web/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description: Flutter plugin for Google Sign-In, a secure authentication system
for signing in with a Google account on Android, iOS and Web.
repository: https://github.com/flutter/packages/tree/main/packages/google_sign_in/google_sign_in_web
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+google_sign_in%22
version: 0.12.2
version: 0.12.2+1

environment:
sdk: ">=3.1.0 <4.0.0"
Expand Down