2
votes

Using gapi.client.request, I can successfully retrieve from Drive.

However, if I invalidate the access token and try again, I get a 401 as expected, followed by a call to https://accounts.google.com/o/oauth2/auth?scope=&immediate=true&proxy=oauth2relay530384583&redirect_uri=postmessage&origin=http%3A%2F%2Fdev.myapp.co%3A9000&response_type=token&state=780297101%7C0.3257751071&authuser=0

which fails 400 "Missing required parameter: scope"

Looking at the URL, the scope is indeed empty, but why?

At the beginning of the authentication, I'm setting my scopes using an array thus ...

var scopes = [ 'https://www.googleapis.com/auth/drive', 'https://www.googleapis.com/auth/drive.file', 'https://www.googleapis.com/auth/userinfo.email',
                'https://www.googleapis.com/auth/userinfo.profile', "https://docs.googleusercontent.com/", "https://docs.google.com/feeds/",
                "https://www.googleapis.com/auth/drive.install","https://www.googleapis.com/auth/tasks" ];

The code itself is ...

var request = gapi.client.request({
 'path': '/drive/v2/files/'+qObject.id,
 'method': 'GET',
 'params': {'maxResults': '1'}
});
request.execute(function(resp) {
  console.log(resp);    // this get works as expected
});

// now invalidate the access token
var token=gapi.auth.getToken();
token.access_token = "foo";
gapi.auth.setToken(token);

request = gapi.client.request({
 'path': '/drive/v2/files/'+qObject.id,
 'method': 'GET',
 'params': {'maxResults': '1'}
});
request.execute(function(resp) {
 console.log(resp);   // this fails with a 401 as expected, but fails to get a new token
});
1
Where is the code where you build the url and send it off? I'm guessing there's some reason why the scopes are missing. - John Woodruff
The code is in the question. "var request = gapi.client.request(...);request.execute(...)" . Remember my Drive call is working. The bit that isn't is the way the gapi client library is responding to a 401 response if the access token expires. So the complete flow is:- - get an access token Works OK - get an item from Drive Works OK - Invalidate the access token to simulate expiry after 3600 seconds - get an item from Drive Returns 401 as expected which is OK -- the gapi library automatically attempts an auth but with a flawed URL which then fails 400 - pinoyyid

1 Answers

2
votes

According to the documentation, scope parameter should be "space delimited set of permissions", not array of permissions.