UserService.getCurrentUser () returns null

I have implemented tripartite OAuth using the Google OAuth API in Java.

My application is registered with GAE. And I also successfully get an access token. But now, when I create a UserService object, even if I am registered in Gmail, as well as in my personal mail, it returns null when calling getCurrentUser ()!

My code is:

import com.google.appengine.api.users.UserService;
import com.google.appengine.api.users.UserServiceFactory;

    oauthParameters.setOAuthConsumerKey(CONSUMER_KEY);
    oauthParameters.setOAuthConsumerSecret(CONSUMER_SECRET);
    oauthParameters.setScope("https://spreadsheets.google.com/feeds/");
    oauthParameters.setOAuthType(OAuthParameters.OAuthType.THREE_LEGGED_OAUTH);
    oauthParameters.setOAuthToken(request.getSession().getAttribute("oauth_token").toString());
    oauthParameters.setOAuthTokenSecret(request.getSession().getAttribute("oauth_token_secret").toString());

UserService userService = UserServiceFactory.getUserService();
out.println("<br/>Get Current User : " + userService.getCurrentUser());

There is no need to specifically add a jar when using User Service. Then what is the problem?

Also, when I try to do this:

out.println(userService.isUserLoggedIn() ? "User is Logged In" : "User is Log Off");

It outputs:

User is disconnected

while I enter my personal domain and gmail like! I think this should probably redirect me to the login page in case I sign up. But this is not so!

, systempuntout , :

OAuthService oauth = OAuthServiceFactory.getOAuthService();
User user = oauth.getCurrentUser();
out.println("<br/>Get Current User : " + user.getNickname());

, !: (

Google App Engine :

Oauth.requestServlet doGet: null
com.google.appengine.api.oauth.InvalidOAuthParametersException: Unknown
    at com.google.appengine.api.oauth.OAuthServiceImpl.makeSyncCall(OAuthServiceImpl.java:73)
    at com.google.appengine.api.oauth.OAuthServiceImpl.getGetOAuthUserResponse(OAuthServiceImpl.java:53)
    at com.google.appengine.api.oauth.OAuthServiceImpl.getCurrentUser(OAuthServiceImpl.java:28)
    at Oauth.accessFeeds.access(accessFeeds.java:60)
    at Oauth.requestServlet.processRequest(requestServlet.java:129)
    at Oauth.requestServlet.doGet(requestServlet.java:199)

: API: com.google.appengine.api.oauth, com.google.appengine.api.users

( ) Google OAuth?

+3
2

URL- :

response.sendRedirect(userService.createLoginURL(request.getRequestURI()));

google, !

+1

, - .

, POST mime- application/x-www-form-urlencoded.

OAuthParameters , , . .

HTTP URL- .

:

, , .

, HTTP ( "application/x-www-form-urlencoded" ) 9.1.1. .

OAuthParameters "computeSignature()" ( 137). , 157 :

for (Object repeatedValue : (Collection<?>) value) {
    putParameter(parameters, name, repeatedValue);
}

?

2:

1: https://code.google.com/p/google-oauth-java-client/issues/detail?id=1. . javadocs: http://javadoc.google-api-java-client.googlecode.com/hg/1.2.2-alpha/com/google/api/client/auth/oauth/package-summary.html .

: Google API Java Client Android, POST, , Google App Engine OAuth

0

Source: https://habr.com/ru/post/1790445/


All Articles