Google auth2 authorization configures a scope without openid
I want to set up the scope to only allow "email" and "profile", no "openid"
because I would only ask for access to email and base profile information.
I tried to do it with meta:
<meta name="google-signin-scope" content="email profile">
or js:
gapi.auth2.init({
client_id: 'xxxxxxxxx.apps.googleusercontent.com',
scope: 'email profile'
});
But that won't work: there is always an "openid" scope in the generated URL ...
How can I "reset" the scope and only allow what I want?
BasicProfile requires openid email profile scopes.
You can disable the base profile and only require the email profile scope:
<meta name="google-signin-fetch_basic_profile" content="false">
<meta name="google-signin-scope" content="profile email">
Note that in this case GoogleUser.getBasicProfile () returns null. You need to manually retrieve the "profile" and "email" data.
Fully working example (you should replace YOUR_CLIENT_ID with your actual client_id):
<html>
<head>
<meta name="google-signin-client_id" content="YOUR_CLIENT_ID">
<meta name="google-signin-fetch_basic_profile" content="false">
<meta name="google-signin-scope" content="profile email">
</head>
<body>
<script>
function requestEmailData() {
gapi.client.load('oauth2', 'v2', function() {
gapi.client.oauth2.userinfo.get().execute(function(resp) {
// Shows user email
console.log(resp.email);
})
});
}
function requestProfileData() {
gapi.client.load('plus', 'v1', function() {
gapi.client.plus.people.get( {'userId' : 'me'} ).execute(function(resp) {
// Shows profile information
console.log(resp);
})
});
}
function onSuccess() {
gapi.load('client', function() {
// based on http://stackoverflow.com/a/15384981
requestEmailData();
requestProfileData();
});
}
</script>
<div class="g-signin2" data-onsuccess="onSuccess"></div>
<script src="https://apis.google.com/js/platform.js?onload=onLoad" async defer></script>
</body>
</html>
Please note that you need to enable the Google+ API in the Developer Console to request your profile information. For this
- go to https://console.developers.google.com/
- select a project
- go to APIs and APIs auth>
- find and enable the Google+ API.