简体   繁体   中英

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:

I want to authorize the user and get back to this pages and after share some data from google calendar. So this is my code snippet to create the login 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. The second problems it's lost session - when I go to the other .jsp pages I'm log out from my account.

Please help

Make sure you have configured the sessions-enabled property in your application's 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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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