问题
I have integrated my Google drive using Oauth2 in server side and stored credentials like access token and refresh token in data base.
const clientId = `${process.env.GOOGLE_DRIVE_CLIENT_ID}`;
const clientSecret = `${process.env.GOOGLE_DRIVE_CLIENT_SECRET}`;
const redirectURI = `${process.env.SERVERHOST}/connect/gdrive`;
const oAuth2Client = new google.auth.OAuth2(
clientId,
clientSecret,
redirectURI,
);
const authUrl = oAuth2Client.generateAuthUrl({
access_type: "offline",
scope: SCOPE,
});
return res.send({ url: authUrl });
Once user authorises the app, next time when ever user loads google picker, it should be open directly without auth screen. To achieve this I am retrieving access token from my db(if it is expired I am generating new token from refresh token) and passing it on to google picker
createPicker(accessToken) {
const { gdriveOAuth2Token } = this.props.userInfo;
const appId = '';
console.log('acc : ', accessToken);
const uploadView = new google.picker.DocsUploadView();
var picker = new google.picker.PickerBuilder().
addViewGroup(
new google.picker.ViewGroup(google.picker.ViewId.DOCS).
addView(google.picker.ViewId.DOCUMENTS).
addView(google.picker.ViewId.PRESENTATIONS)).
addView(uploadView).
setAppId(appId).
setOAuthToken(accessToken).
setDeveloperKey(developerKey).
setCallback(this.pickerCallback).
build();
picker.setVisible(true);
}
It works fine for a particular session. However, for new sessions it asks for user name and password again. I don't want user to go through authentication screen once he has integrated his drive.
来源:https://stackoverflow.com/questions/59609728/is-it-possible-to-open-google-picker-with-access-token-which-is-fetched-from-ser