简体   繁体   English

Google Cloud Endpoints和用户身份验证

[英]Google Cloud Endpoints and user's authentication

I'm currently new into the AppEngine world, and wanting to create a backend using Cloud Endpoints for a mobile application that I'm developing. 我目前刚进入AppEngine世界,并希望使用Cloud Endpoints为我正在开发的移动应用程序创建后端。

One of my problem right now is about the user's authentication. 我现在的一个问题是关于用户的身份验证。 I've been following the Udacity's MOOC on App Engine, and they taught us how to authenticate the user for API request using a Google Accounts. 我一直在关注App Engine上的Udacity的MOOC,他们教我们如何使用Google帐户验证用户的API请求。 On the backend side, we simply have to add a User parameter to our method, and check if the user is signed in. As far as I know, this user parameter is generated by App Engine, based on the Authorization header of our request. 在后端,我们只需要在我们的方法中添加一个User参数,并检查用户是否已登录。据我所知,此用户参数由App Engine根据我们的请求的Authorization标头生成。 ( might need some confirmation there ) 可能需要一些确认

Now, there's a bunch of stuff I'm not sure to understand and that weren't that well explained on this MOOC. 现在,有一些我不确定理解的东西,并没有在这个MOOC上得到很好的解释。

Now, I'd like to know if this is compatible with other OAuth schemes, beside Google? 现在,我想知道这是否与Google之外的其他OAuth方案兼容? So, if I want to implement Facebook authentication, will I simply pass the facebook access token? 那么,如果我想实现Facebook身份验证,我会简单地传递facebook访问令牌吗?

From what I searched, using the Facebook SDK on Android would lead me to be able to generate a User Access Token, which identifies my user to facebook . 根据我搜索的内容,在Android上使用Facebook SDK会让我能够生成一个用户访问令牌,用于识别我的用户到Facebook After sending it to my backend, I would want to check it's validity with Facebook, and if it's valid, create a new user to my application. 将它发送到我的后端后,我想检查它与Facebook的有效性,如果它有效,请为我的应用程序创建一个新用户。 Now, I'd also want to generate a new token that identify the user to my app . 现在,我还想生成一个新标记,用于标识我的应用程序的用户。 What would I need to do to do so? 我需要做什么?

You can supply your own authenticator to Endpoints and the injected User will be obtained with your authenticator https://developers.google.com/appengine/docs/java/endpoints/javadoc/com/google/api/server/spi/config/Authenticator.html . 您可以为端点提供自己的身份验证器,注册用户将通过身份验证器获取https://developers.google.com/appengine/docs/java/endpoints/javadoc/com/google/api/server/spi/config/ Authenticator.html

The Facebook credentials can be sent via a header, eg Authorization header and it can be accessed from backend via HttpServletRequest, which you can handle inside Authenticator.authenticate method. Facebook凭证可以通过标头发送,例如Authorization标头,它可以通过HttpServletRequest从后端访问,您可以在Authenticator.authenticate方法中处理。

For example. 例如。

// Custom Authenticator class
public class MyAuthenticator implements Authenticator {
  @Override
  public User authenticate(HttpServletRequest request) {
    String token = request.getHeader("Authorization");
    if (token != null) {
      String user = authenticateFacebook(token);  // apply your Facebook auth.
      if (user != null) {
        return new User(user);
      }
    }
    return null;
  }
}

// Endpoints class.
@Api(name = "example", authenticators = {MyAuthenticator.class})
public class MyEndpoints {
  public Container getThing(User user) {
    Container c = new Container();
    if (user != null) {
      c.email = user.getEmail();
    }
    return c;
  }

  public class Container {
    public String email;
    public String extraData;
  }
}

When I try your example I always get an: java.lang.NullPointerException: authDomain must be specified. 当我尝试你的例子时,我总是得到一个:java.lang.NullPointerException:必须指定authDomain。 But I cannot set an authDomain on the User object. 但是我无法在User对象上设置authDomain。 Any ideas? 有任何想法吗?

UPDATE: This is connected to this Bug https://code.google.com/p/googleappengine/issues/detail?id=12060&q=endpoints&colspec=ID%20Type%20Component%20Status%20Stars%20Summary%20Language%20Priority%20Owner%20Log 更新:已连接到此错误https://code.google.com/p/googleappengine/issues/detail?id=12060&q=endpoints&colspec=ID%20Type%20Component%20Status%20Stars%20Summary%20Language%20Priority%20Owner% 20Log

in version 1.9.22 在版本1.9.22中

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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