Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Add scope handling methods to google_sign_in_web.
  • Loading branch information
emerssso committed Mar 19, 2020
commit 3a2932e7b2b2d102a8b98f003e18727d2b0c6e5b
Original file line number Diff line number Diff line change
Expand Up @@ -176,4 +176,29 @@ class GoogleSignInPlugin extends GoogleSignInPlatform {

return auth2.getAuthInstance().disconnect();
}

@override
Future<bool> hasGrantedScope(String scope) async {
await initialized;

return auth2
.getAuthInstance()
?.currentUser
?.get()
?.getGrantedScopes()
?.contains(scope) ??
false;
}

@override
Future<bool> requestScope(String scope) async {
await initialized;

return auth2
.getAuthInstance()
?.currentUser
?.get()
?.grant(auth2.SigninOptions(scope: scope)) ??
false;
}
}
12 changes: 12 additions & 0 deletions packages/google_sign_in/google_sign_in_web/test/auth2_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -73,5 +73,17 @@ void main() {

expect(actualToken, expectedTokenData);
});

test('hasGrantedScope', () async {
bool hasScope = await plugin.hasGrantedScope('scope');

expect(hasScope, isTrue);
});

test('requestScope', () async {
bool scopeGranted = await plugin.requestScope('newScope');

expect(scopeGranted, isTrue);
});
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,7 @@ String googleUser(GoogleSignInUserData data) => '''
access_token: 'access_${data.idToken}',
}
},
getGrantedScopes: () => 'some scope',
grant: () => true,
}
''';