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

Set include_granted_scopes=true in the auth request #70

Merged
merged 4 commits into from
Nov 16, 2021
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
12 changes: 9 additions & 3 deletions GoogleSignIn/Sources/GIDSignIn.m
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,13 @@
// The delay before the new sign-in flow can be presented after the existing one is cancelled.
static const NSTimeInterval kPresentationDelayAfterCancel = 1.0;

// Extra parameters for the token exchange endpoint.
// Parameters for the auth and token exchange endpoints.
static NSString *const kAudienceParameter = @"audience";
// See b/11669751 .
static NSString *const kOpenIDRealmParameter = @"openid.realm";
static NSString *const kIncludeGrantedScopesParameter = @"include_granted_scopes";
static NSString *const kLoginHintParameter = @"login_hint";
static NSString *const kHostedDomainParameter = @"hd";

// Minimum time to expiration for a restored access token.
static const NSTimeInterval kMinimumRestoredAccessTokenTimeToExpire = 600.0;
Expand Down Expand Up @@ -431,20 +434,23 @@ - (void)authenticateInteractivelyWithOptions:(GIDSignInInternalOptions *)options
[schemes clientIdentifierScheme],
kBrowserCallbackPath]];
NSString *emmSupport = [[self class] isOperatingSystemAtLeast9] ? kEMMVersion : nil;

NSMutableDictionary<NSString *, NSString *> *additionalParameters = [@{} mutableCopy];
additionalParameters[kIncludeGrantedScopesParameter] = @"true";
if (options.configuration.serverClientID) {
additionalParameters[kAudienceParameter] = options.configuration.serverClientID;
}
if (options.loginHint) {
additionalParameters[@"login_hint"] = options.loginHint;
additionalParameters[kLoginHintParameter] = options.loginHint;
}
if (options.configuration.hostedDomain) {
additionalParameters[@"hd"] = options.configuration.hostedDomain;
additionalParameters[kHostedDomainParameter] = options.configuration.hostedDomain;
}
[additionalParameters addEntriesFromDictionary:
[GIDAuthentication parametersWithParameters:options.extraParams
emmSupport:emmSupport
isPasscodeInfoRequired:NO]];

OIDAuthorizationRequest *request =
[[OIDAuthorizationRequest alloc] initWithConfiguration:_appAuthConfiguration
clientId:options.configuration.clientID
Expand Down
2 changes: 2 additions & 0 deletions GoogleSignIn/Tests/Unit/GIDSignInTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -1030,6 +1030,8 @@ - (void)OAuthLoginWithOptions:(GIDSignInInternalOptions *)options
[_authState verify];

XCTAssertNotNil(_savedAuthorizationRequest);
NSDictionary<NSString *, NSObject *> *params = _savedAuthorizationRequest.additionalParameters;
XCTAssertEqualObjects(params[@"include_granted_scopes"], @"true");
XCTAssertNotNil(_savedAuthorizationCallback);
XCTAssertEqual(_savedPresentingViewController, _presentingViewController);

Expand Down