简体   繁体   English

登录问题,userService,丢失的会话-Google App Angine

[英]Problem with login ,userService , lost session - google app angine

I'm creating my application and i want integrate it with google account and I have following problems: 我正在创建我的应用程序,我想将其与Google帐户集成,但遇到以下问题:

I want to authorize the user and get back to this pages and after share some data from google calendar. 我想授权用户并返回此页面,然后共享Google日历中的一些数据。 So this is my code snippet to create the login url (index.jsp) 所以这是我创建登录URL(index.jsp)的代码片段

boolean b= true;
UserService userService = UserServiceFactory.getUserService();
    User user = userService.getCurrentUser();

if(user!=null){
%>
              <p>Hello, <%= user.getNickname() %>  </p>
<%
                                }

  try
                {singleUseToken AuthSubUtil.getTokenFromReply(request.getQueryString());

                }catch (NullPointerException e)
                {

        String nextUrl = Settings.SERVER_ADDRESS;
        String scope ="http://www.google.com/calendar/feeds/";

        String login=AuthSubUtil.getRequestUrl(nextUrl, scope, false, true);

%>
  <p>"App needs access to your Google Calendar account to read your Calendar feed. To authorize MyApp to access your account
  <a href="<%=userService.createLoginURL(login)  %>">log in to your account</a>.)</p>
<%
b=false;
   }

   if (b== true){

        CalendarService myService=null;   
                try{    
                    sessionToken = AuthSubUtil.exchangeForSessionToken(URLDecoder.decode(singleUseToken, "UTF-8"), null);
                }
                catch(NullPointerException e)
                {

                %>
                        <p><%=e %> </p>
<%
                    }
CalendarService myService = new CalendarService("google-ExampleApp-v1.0");
                    myService.setAuthSubToken(sessionToken);
                    ...

And I create the authSubUrl and pass it to the UserService to create the second redirect, but UserService.getCurrentUser() returns null although I'm logged. 然后,我创建了authSubUrl并将其传递给UserService来创建第二个重定向,但是尽管已登录,但UserService.getCurrentUser()返回null。 The second problems it's lost session - when I go to the other .jsp pages I'm log out from my account. 第二个问题是会话丢失-当我转到其他.jsp页面时,我从帐户中注销。

Please help 请帮忙

Make sure you have configured the sessions-enabled property in your application's appengine-web.xml 确保已在应用程序的appengine-web.xml中配置了启用会话的属性

<appengine-web-app xmlns="http://appengine.google.com/ns/1.0">
   <application>myapp</application>
   <version>01</version>
   <ssl-enabled>true</ssl-enabled>  
   <sessions-enabled>true</sessions-enabled> <!- <<<<  Make sure you have this ->
</appengine-web-app>

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

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