Skip to content
This repository was archived by the owner on Apr 4, 2023. It is now read-only.

Commit eff2cde

Browse files
Add ability to add scopes for GoogleAuthProvider #1266
1 parent e40590d commit eff2cde

File tree

5 files changed

+35
-8
lines changed

5 files changed

+35
-8
lines changed

demo/app/main-view-model.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1146,7 +1146,13 @@ export class HelloWorldModel extends Observable {
11461146
public doLoginByGoogle(): void {
11471147
firebase.login({
11481148
// note that you need to enable Google auth in your firebase instance
1149-
type: firebase.LoginType.GOOGLE
1149+
type: firebase.LoginType.GOOGLE,
1150+
googleOptions: {
1151+
scopes: [
1152+
"https://www.googleapis.com/auth/contacts.readonly",
1153+
"https://www.googleapis.com/auth/user.birthday.read"
1154+
]
1155+
}
11501156
}).then(
11511157
result => {
11521158
console.log("Google login OK: " + JSON.stringify(result));

docs/AUTHENTICATION.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,7 @@ Then add the following lines to your code and check for setup instructions for y
534534
// Optional
535535
facebookOptions: {
536536
// defaults to ['public_profile', 'email']
537-
scope: ['public_profile', 'email']
537+
scopes: ['public_profile', 'email'] // note: this property was renamed from "scope" in 8.4.0
538538
}
539539
}).then(
540540
function (result) {
@@ -611,7 +611,10 @@ Then add the following lines to your code and check for setup instructions for y
611611
type: firebase.LoginType.GOOGLE,
612612
// Optional
613613
googleOptions: {
614-
hostedDomain: "mygsuitedomain.com"
614+
hostedDomain: "mygsuitedomain.com",
615+
// NOTE: no need to add 'profile' nor 'email', because they are always provided
616+
// NOTE 2: requesting scopes means you may access those properties, but they are not automatically fetched by the plugin
617+
scopes: ['https://www.googleapis.com/auth/user.birthday.read']
615618
}
616619
}).then(
617620
function (result) {

src/firebase.android.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1113,6 +1113,14 @@ firebase.login = arg => {
11131113
googleSignInOptionsBuilder.setHostedDomain(arg.googleOptions.hostedDomain);
11141114
}
11151115

1116+
if (arg.googleOptions && arg.googleOptions.scopes) {
1117+
const scopesArray = [];
1118+
if (arg.googleOptions.scopes.length > 1) {
1119+
arg.googleOptions.scopes.forEach(s => scopesArray.push(new com.google.android.gms.common.api.Scope(s)));
1120+
}
1121+
googleSignInOptionsBuilder.requestScopes(new com.google.android.gms.common.api.Scope(arg.googleOptions.scopes[0]), scopesArray);
1122+
}
1123+
11161124
const googleSignInOptions = googleSignInOptionsBuilder.build();
11171125

11181126
const onConnectionFailedListener = new com.google.android.gms.common.api.GoogleApiClient.OnConnectionFailedListener({

src/firebase.d.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,13 +267,19 @@ export interface FirebasePhoneLoginOptions {
267267

268268
export interface FirebaseGoogleLoginOptions {
269269
hostedDomain?: string;
270+
/**
271+
* You can add scopes like "https://www.googleapis.com/auth/contacts.readonly" and "https://www.googleapis.com/auth/user.birthday.read"
272+
*
273+
* Default: ["profile", "email"]
274+
*/
275+
scopes?: Array<string>;
270276
}
271277

272278
export interface FirebaseFacebookLoginOptions {
273279
/**
274280
* Default: ["public_profile", "email"]
275281
*/
276-
scope?: string[];
282+
scopes?: Array<string>;
277283
}
278284

279285
export interface FirebaseCustomLoginOptions {

src/firebase.ios.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -950,14 +950,14 @@ firebase.login = arg => {
950950
// this requires you to set the appid and customurlscheme in app_resources/.plist
951951
const fbSDKLoginManager = FBSDKLoginManager.new();
952952
// fbSDKLoginManager.loginBehavior = FBSDKLoginBehavior.Web;
953-
let scope: any = ["public_profile", "email"];
953+
let scopes: any = ["public_profile", "email"];
954954

955-
if (arg.facebookOptions && arg.facebookOptions.scope) {
956-
scope = arg.facebookOptions.scope;
955+
if (arg.facebookOptions && arg.facebookOptions.scopes) {
956+
scopes = arg.facebookOptions.scopes;
957957
}
958958

959959
fbSDKLoginManager.logInWithReadPermissionsFromViewControllerHandler(
960-
scope,
960+
scopes,
961961
null, // the viewcontroller param can be null since by default topmost is taken
962962
onFacebookCompletion);
963963

@@ -976,6 +976,10 @@ firebase.login = arg => {
976976
sIn.hostedDomain = arg.googleOptions.hostedDomain;
977977
}
978978

979+
if (arg.googleOptions && arg.googleOptions.scopes) {
980+
sIn.scopes = arg.googleOptions.scopes;
981+
}
982+
979983
let delegate = GIDSignInDelegateImpl.new().initWithCallback((user: GIDGoogleUser, error: NSError) => {
980984
if (error === null) {
981985
// Get a Google ID token and Google access token from the GIDAuthentication object and exchange them for a Firebase credential

0 commit comments

Comments
 (0)