5

What I am doing:

I am integrating Google Picker on my page. This will allow users to select files from their Google Drive to be used in the web app. In the app, people in a group share a common google drive (i.e. they all can select files from account example@email.com) which was created by group admin by his email address. When the admin signs-up for the account we do OAuth and get access_token with refresh_token against our app on google (with offline access enabled). I plan to use the access_token and refresh-token of the admin, on other group user's account when they try to use picker to select files.

What I have done:

I have integrated the Google Picker successfully in my app using the basic code provided in docs. Then to achieve what I wanted, I removed following code from the example code:

gapi.load('auth', {'callback': onAuthApiLoad});

and

function onAuthApiLoad() {
  window.gapi.auth.authorize(
    {
      'client_id': clientId,
      'scope': scope,
      'immediate': false
    },
    handleAuthResult);
}

and

function handleAuthResult(authResult) {
  if (authResult && !authResult.error) {
    oauthToken = authResult.access_token;
    createPicker();
  }
}

and instead of .setOAuthToken(oauthToken) I pass refreshed access_token directly as string (I get that from my server with an ajax call).

.setOAuthToken("<access_token>")

But every time I call picker.setVisible(true); I get a screen in an iframe saying In order to select an item from your online storage, please sign in.

enter image description here

Problem:

Jehanzeb.Malik
  • 3,332
  • 4
  • 25
  • 41
  • Did you find any solution to this? – ot954 Jan 03 '20 at 11:02
  • @ot954 I did, but that was 3 years ago. I'll dig into my repository to see if I still have that code. – Jehanzeb.Malik Jan 07 '20 at 18:58
  • The only way I could find out is by using App script. But still I am not pretty much sure how to serve html from google app script. In my case I have integrated user's drive with my application. Once integration is done, google picker should never show this sign in. – ot954 Jan 08 '20 at 03:37
  • @ot954 did you get anywhere with this? Getting same issue – aalimovs Dec 07 '20 at 16:12

1 Answers1

1

Try to add sign in listener. Listeners provide a way to automatically respond to changes in the current user's Sign-In session. For example, after your startup method initializes the Google Sign-In auth2 object, you can set up listeners to respond to events like auth2.isSignedIn state changes, or changes in auth2.currentUser.

Validating the token might be a possibility before using the token each time but that might add a lot of extra overhead for a rare use-case each time we load the picker and when calling the API endpoints with a token after the re-authentication issue, there was no key about the token being invalid. You can validate a token by making a web service request to an endpoint on the Google Authorization Server and performing a string match on the results of that web service request.

Android Enthusiast
  • 4,826
  • 2
  • 15
  • 30