dongping9475 2015-03-25 17:44
浏览 116

使用oAuth处理多个Google登录用户

I have this app that uses data from gmail accounts. I have been able to create a php site that retrieves the oAuth tokens (online and offline) and later the necessary user information from the mailbox, all using the Google php api. Now to my problem:

When a secondary user logs into gmail in a browser that was previously used by an authorized user, the credentials seems to "stay". So the 2nd (or 3rd or nth user) can see data non-related to them, which is also a security hole. But most important: every loged in user into gmail is seeing only the data of the 1st logged in user.

The question: Is there a way I can use Google PHP API or Google JavaScript API to retrieve the user name of the current gmail session?

This is the current php piece of code I've been using to retrieve the user data:

use google\appengine\api\users\User;
use google\appengine\api\users\UserService;

session_start(); 

$user = UserService::getCurrentUser();
$userEmail = htmlspecialchars($user->getEmail());

The idea is that the app uses the current gmail user information to query a database and then retrieve the data for that specific user - and only that logged in user. If the user is not authorized, then prompt for the authorization window and ask for permission.

Any ideas or suggestions are welcome.

UPDATE (Sept 7, 2015):

I have made a change in the app.yaml so every logged in user in gmail gets served a different uri from my app. That works just fine. Now I face a new issue: how can I make the PHPSESSID and SACSID cookies to use an specific path instead of the whole domain? That way - theoretically - I can have several logged in users each and every one connecting to a different subfolder.

I've read the whole documentation about the UserService but it seems all I can do is redirect to this:

UserService::createLoginURL($_SERVER['REQUEST_URI']);

And that takes care of the authentication.

The question: How can I restringe the scope so the cookies gets the appropriate folder path?

  • 写回答

1条回答

  • dqdpz60048 2015-03-26 11:27
    关注

    The main issue is that once you log in to App Engine (via the UserService), that a user session has now been created in your App Engine application, and therefore it doesn't really matter what you do in GMail or any other Google application, as the session has already been created, and persists within your application.

    The App Engine UserService was available way before secondary logins were even possible, and it hasn't been updated since. So this use case probably wasn't a consideration when the API as developed.

    评论

报告相同问题?

悬赏问题

  • ¥20 搭建pt1000三线制高精度测温电路
  • ¥15 使用Jdk8自带的算法,和Jdk11自带的加密结果会一样吗,不一样的话有什么解决方案,Jdk不能升级的情况
  • ¥15 画两个图 python或R
  • ¥15 在线请求openmv与pixhawk 实现实时目标跟踪的具体通讯方法
  • ¥15 八路抢答器设计出现故障
  • ¥15 opencv 无法读取视频
  • ¥15 用matlab 实现通信仿真
  • ¥15 按键修改电子时钟,C51单片机
  • ¥60 Java中实现如何实现张量类,并用于图像处理(不运用其他科学计算库和图像处理库))
  • ¥20 5037端口被adb自己占了