douyi2664 2016-06-21 22:21
浏览 23
已采纳

限制访问我的App Engine PHP应用程序以获取一组Google帐户?

Is there a way I can restrict access to my App Engine PHP app for only a certain set of Google account holders (who are logged in at the time of course)? The additional requirement is the PHP scripts on my site will be called via AJAX. It's fine for the users not to see a Google login prompt as they are internal users and will know that they are supposed to be already logged in.

Looking at the PHP app.yaml https://cloud.google.com/appengine/docs/php/config/appref#handlers_login and User auth info https://cloud.google.com/appengine/docs/php/users/#choosing_an_authentication_option I wasn't clear how this could be achieved (apart for Admin roles which are too permissive for these users)

Thanks, Alex

  • 写回答

2条回答 默认 最新

  • donglu9978 2016-06-22 10:38
    关注

    A very crude/simple solution would be implemented like this:

    In app.yaml, add something like this

    - url: .*
      script: main.php
      login: required
    

    Then in main.php, something like this

    $user = \google\appengine\api\users\UserService::getCurrentUser();
    if($user) {
        if(in_array($user->getEmail(), ['user1@domain.com', 'user2@domain.com'])) {
            // OK, user is allowed
        } else {
            // Logged in, but UNKNOWN user
        }
    } else {
        // User not logged in
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?
  • ¥15 乘性高斯噪声在深度学习网络中的应用