GAE User API with OAuth2

怎甘沉沦 提交于 2019-12-08 05:02:37

问题


Inside my servlets, this is how I authenticate user

    UserService userservice=UserServiceFactory.getUserService();
    User user = userservice.getCurrentUser();

    if(user == null){
       response.redirect(userservice.createLoginURL("../userhome"));
    }

More recently, in the same project I used Google Cloud Endpoints with authentication to access data using a JS client. The JS client authorizes using Oauth

gapi.auth.authorize(...);

Although they belong to the same App Engine Project and share the same credentials, the servlet and JS client ask the user to sign in independent of each other - as if they were two different applications.

I want a single sign in for the whole application. How do I do this?


回答1:


Here are some points:

  1. It is important that you have authentication at both the levels. This is a good practice and does not leave your functionality open for execution without any authentication mechanism.

  2. When you are doing the authentication on the client side, the whole authentication layer passes this User object to your Google Cloud Endpoints code. So, it is good if you could inject the User object in your Cloud Endpoints method to extract out the information of the user and do your own authorization if needed.

  3. In summary, you are not really doing an authentication again at the Server side if you notice. You are only checking if the authentication is done or not and then proceeding forward.



来源:https://stackoverflow.com/questions/25211395/gae-user-api-with-oauth2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!