-
Notifications
You must be signed in to change notification settings - Fork 29.2k
Closed
flutter/packages
#10021Labels
P1High-priority issues at the top of the work listHigh-priority issues at the top of the work listp: google_sign_inThe Google Sign-In pluginThe Google Sign-In pluginpackageflutter/packages repository. See also p: labels.flutter/packages repository. See also p: labels.platform-iosiOS applications specificallyiOS applications specificallyteam-ecosystemOwned by Ecosystem teamOwned by Ecosystem teamtriaged-ecosystemTriaged by Ecosystem teamTriaged by Ecosystem team
Description
When I request server code on google_sign_in for iOS I don't get it, and I debug the issue and found that I get access token instead of it
After several hours I found that the root cause is that I have to call the get server code first before authorize
so userId == null and the flow works
Future<({String? accessToken, String? serverAuthCode})>
_getAuthorizationTokens(AuthorizationRequestDetails request) async {
String? userId = request.userId;
// The Google Sign In SDK requires authentication before authorization, so
// if the authentication isn't associated with an existing sign-in user
// run the authentication flow first.
if (userId == null) {
SignInResult result = await _api.restorePreviousSignIn();
Here is my flow
// I get server token first as _api.restorePreviousSignIn() in
// google sign ios will return the server code only for non-logged in users
// otherwise it will get the access token which we don't want
final GoogleSignInServerAuthorization? googleServerAuthorization =
await GoogleSignIn.instance.authorizationClient.authorizeServer(
scopes,
);
if (googleServerAuthorization == null) {
throw generateGoogleCancelledException();
}
if (googleServerAuthorization.serverAuthCode.isEmptyOrNull()) {
throw Exception('Error signing in with Google');
}
final GoogleSignInAccount? googleSignInAccount = await GoogleSignIn.instance
.attemptLightweightAuthentication(
reportAllExceptions: true,
);
I open the issue as a documentation issue as I am not sure if it is a missing documentation or a bug
Yoann-LeBreton
Metadata
Metadata
Assignees
Labels
P1High-priority issues at the top of the work listHigh-priority issues at the top of the work listp: google_sign_inThe Google Sign-In pluginThe Google Sign-In pluginpackageflutter/packages repository. See also p: labels.flutter/packages repository. See also p: labels.platform-iosiOS applications specificallyiOS applications specificallyteam-ecosystemOwned by Ecosystem teamOwned by Ecosystem teamtriaged-ecosystemTriaged by Ecosystem teamTriaged by Ecosystem team