This repository was archived by the owner on Feb 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9.8k
[google_sign_in] Add serverClientId option to return serverAuthCode #879
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -66,7 +66,8 @@ public void onMethodCall(MethodCall call, Result result) { | |
String signInOption = call.argument("signInOption"); | ||
List<String> requestedScopes = call.argument("scopes"); | ||
String hostedDomain = call.argument("hostedDomain"); | ||
delegate.init(result, signInOption, requestedScopes, hostedDomain); | ||
String serverClientId = call.argument("serverClientId"); | ||
delegate.init(result, signInOption, requestedScopes, hostedDomain, serverClientId); | ||
break; | ||
|
||
case METHOD_SIGN_IN_SILENTLY: | ||
|
@@ -113,7 +114,11 @@ public void onMethodCall(MethodCall call, Result result) { | |
public interface IDelegate { | ||
/** Initializes this delegate so that it is ready to perform other operations. */ | ||
public void init( | ||
Result result, String signInOption, List<String> requestedScopes, String hostedDomain); | ||
Result result, | ||
String signInOption, | ||
List<String> requestedScopes, | ||
String hostedDomain, | ||
String serverClientId); | ||
|
||
/** | ||
* Returns the account information for the user who is signed in to this app. If no user is | ||
|
@@ -210,7 +215,11 @@ private void checkAndSetPendingOperation(String method, Result result, Object da | |
*/ | ||
@Override | ||
public void init( | ||
Result result, String signInOption, List<String> requestedScopes, String hostedDomain) { | ||
Result result, | ||
String signInOption, | ||
List<String> requestedScopes, | ||
String hostedDomain, | ||
String serverClientId) { | ||
try { | ||
GoogleSignInOptions.Builder optionsBuilder; | ||
|
||
|
@@ -246,6 +255,10 @@ public void init( | |
if (!Strings.isNullOrEmpty(hostedDomain)) { | ||
optionsBuilder.setHostedDomain(hostedDomain); | ||
} | ||
if (!Strings.isNullOrEmpty(serverClientId)) { | ||
optionsBuilder.requestServerAuthCode(serverClientId, true); | ||
optionsBuilder.requestIdToken(serverClientId); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this required? Why do we not have the same on iOS? What happens if this block also calls if (clientIdIdentifier != 0) {
optionsBuilder.requestIdToken(registrar.context().getString(clientIdIdentifier));
} |
||
} | ||
|
||
this.requestedScopes = requestedScopes; | ||
signInClient = GoogleSignIn.getClient(registrar.context(), optionsBuilder.build()); | ||
|
@@ -361,6 +374,7 @@ private void onSignInAccount(GoogleSignInAccount account) { | |
response.put("id", account.getId()); | ||
response.put("idToken", account.getIdToken()); | ||
response.put("displayName", account.getDisplayName()); | ||
response.put("serverAuthCode", account.getServerAuthCode()); | ||
if (account.getPhotoUrl() != null) { | ||
response.put("photoUrl", account.getPhotoUrl().toString()); | ||
} | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -75,6 +75,9 @@ - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result | |||||
[GIDSignIn sharedInstance].clientID = plist[kClientIdKey]; | ||||||
[GIDSignIn sharedInstance].scopes = call.arguments[@"scopes"]; | ||||||
[GIDSignIn sharedInstance].hostedDomain = call.arguments[@"hostedDomain"]; | ||||||
if (![call.arguments[@"serverClientId"] isEqual:[NSNull null]]) { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit:
Suggested change
|
||||||
[GIDSignIn sharedInstance].serverClientID = call.arguments[@"serverClientId"]; | ||||||
} | ||||||
result(nil); | ||||||
} else { | ||||||
result([FlutterError errorWithCode:@"missing-config" | ||||||
|
@@ -173,6 +176,7 @@ - (void)signIn:(GIDSignIn *)signIn | |||||
@"email" : user.profile.email ?: [NSNull null], | ||||||
@"id" : user.userID ?: [NSNull null], | ||||||
@"photoUrl" : [photoUrl absoluteString] ?: [NSNull null], | ||||||
@"serverAuthCode" : user.serverAuthCode ?: [NSNull null] | ||||||
} | ||||||
error:nil]; | ||||||
} | ||||||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,7 +36,8 @@ class GoogleSignInAccount implements GoogleIdentity { | |
email = data['email'], | ||
id = data['id'], | ||
photoUrl = data['photoUrl'], | ||
_idToken = data['idToken'] { | ||
_idToken = data['idToken'], | ||
serverAuthCode = data['serverAuthCode'] { | ||
assert(id != null); | ||
} | ||
|
||
|
@@ -62,6 +63,7 @@ class GoogleSignInAccount implements GoogleIdentity { | |
|
||
final String _idToken; | ||
final GoogleSignIn _googleSignIn; | ||
final String serverAuthCode; | ||
|
||
/// Retrieve [GoogleSignInAuthentication] for this account. | ||
/// | ||
|
@@ -163,14 +165,17 @@ class GoogleSignIn { | |
/// The [hostedDomain] argument specifies a hosted domain restriction. By | ||
/// setting this, sign in will be restricted to accounts of the user in the | ||
/// specified domain. By default, the list of accounts will not be restricted. | ||
GoogleSignIn({this.signInOption, this.scopes, this.hostedDomain}); | ||
GoogleSignIn( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Needs dart doc for |
||
{this.signInOption, this.scopes, this.hostedDomain, this.serverClientId}); | ||
|
||
/// Factory for creating default sign in user experience. | ||
factory GoogleSignIn.standard({List<String> scopes, String hostedDomain}) { | ||
factory GoogleSignIn.standard( | ||
{List<String> scopes, String hostedDomain, String serverClientId}) { | ||
return GoogleSignIn( | ||
signInOption: SignInOption.standard, | ||
scopes: scopes, | ||
hostedDomain: hostedDomain); | ||
hostedDomain: hostedDomain, | ||
serverClientId: serverClientId); | ||
} | ||
|
||
/// Factory for creating sign in suitable for games. This option must not be | ||
|
@@ -207,6 +212,8 @@ class GoogleSignIn { | |
/// Domain to restrict sign-in to. | ||
final String hostedDomain; | ||
|
||
final String serverClientId; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Needs dart doc |
||
|
||
StreamController<GoogleSignInAccount> _currentUserController = | ||
StreamController<GoogleSignInAccount>.broadcast(); | ||
|
||
|
@@ -246,6 +253,7 @@ class GoogleSignIn { | |
'signInOption': (signInOption ?? SignInOption.standard).toString(), | ||
'scopes': scopes ?? <String>[], | ||
'hostedDomain': hostedDomain, | ||
'serverClientId': serverClientId, | ||
}) | ||
..catchError((dynamic _) { | ||
// Invalidate initialization if it errored out. | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we need to expose this API, let's also expose the boolean parameter
forceCodeForRefreshToken
to the public API and make itfalse
by default.