Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google API multiple scopes

I want to use multiple scopes in the Google API JavaScript. What I'm trying to do is to get the user Email & Name.

The Name i can get from the scope: https://www.googleapis.com/auth/plus.me

And the Email i can get from the scope: https://www.googleapis.com/auth/userinfo.email

But how I can use them both in the same application?

My code is:

scopes = 'https://www.googleapis.com/auth/plus.me https://www.googleapis.com/auth/userinfo.email';

    gapi.signin.render('StartGoogleBtn', {
      'callback': 'onSignInCallback',
      'clientid': clientId,
      'cookiepolicy': 'single_host_origin',
      'scope': scopes
    });

What scopes should be? Thanks :)

like image 600
roev Avatar asked Sep 21 '14 22:09

roev


2 Answers

Just guessing, but try space delimited with double-quotes surrounding it. That's what OAuth 2 calls for and when I wrote the code for the client I made it automatically deal with that scenario correctly. I assume it'd just get passed through by the command.That's work for me.

scopes = "https://www.googleapis.com/auth/userinfo.email  https://www.googleapis.com/auth/plus.me"
like image 75
aman kumar Avatar answered Oct 23 '22 13:10

aman kumar


I'll preface my answer by saying that I haven't used the Javascript version. I'm using the Java library, which lets me set the scopes by passing a list of strings containing the scopes I want.

List<String> SCOPES = Arrays.asList(
        DirectoryScopes.ADMIN_DIRECTORY_GROUP, //https://www.googleapis.com/auth/admin.directory.group
        DirectoryScopes.ADMIN_DIRECTORY_USER,  //https://www.googleapis.com/auth/admin.directory.user
        DriveScopes.DRIVE                      //https://www.googleapis.com/auth/drive
        );

credential = new GoogleCredential.Builder()
                .setTransport(httpTransport).setJsonFactory(jsonFactory)
                .setServiceAccountId(serviceAccountId)
                .setServiceAccountScopes(SCOPES)
                .setServiceAccountPrivateKeyFromP12File(p12File)
                .setServiceAccountUser(adminUser).build();

Assuming the Javascript library works similarly to the Java one, you should be able to add multiple scopes by making your scopes variable an array of Strings.

like image 33
Dan Ambrogio Avatar answered Oct 23 '22 12:10

Dan Ambrogio