简体   繁体   中英

PHP, Google Drive API - Getting Logged in User ID

I have a site that uses hybridauth (a library for allowing google/facebook/... authentication) that authenticates a google account and allows the user to login to our site. I'm adding a component to the site that allows the user access to certain google-drive docs (like excel sheets embedded in html). Depending on who is logged in certain permissions would be set (using google drive api) whether they can view or edit or no access to the files.

Problem is sometimes a machine can have multiple google accounts associated with it...and what can happen is a person can login to our site with one google account, go to google home page (in a new tab) and sign-out/sign-in with another account. Then if they try to access the google docs it uses this new login's permission settings (instead of the google account they used on hybridauth to get into our site). Our user's are not very technical and when they start seeing "Request Access" screens they don't know what to do. I want to be able to detect if the google account they are using to access our google-drive files is the same as the one they are logged in to our site with, and if not I'll post a note on the site telling them what to do. Is there anyway I can do that? Does google-drive api have some way of determining which google-account is trying to access a file, and then in PHP I can see if that is the same as the username in session?

Please let me know if this is doable and if so give me some sample code. Let me know if I need to clarify anything.

You need to create and keep your NEW token in your database after user authentication via the some API AUTH. And you have to use this token to work with your site. When user is logged, for example through Google OAuth and it will save in the auth system of your site. After that you can forget about the authorization to Google. You will use own token. And if user have a few Coogle accounts he will work with one of them for all the time.

The token should be stored in a cookie on the user side. And remove it only after logout in your site or expire.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM