2015-01-26 2 views
1

상황을 충돌합니다. 지금까지 (훨씬 더 간단한) openId APi를 사용하여 사용자를 인증했지만 지금은 제거 될 것으로 보이며 oAuth2는 "새로운"것입니다.OAuth2를 OAuthServiceFactory.getOAuthService() getCurrentUser는()

질문 :

나는이 내 사용자를 인증하는 apacha oltu를 사용하는 다음 코드를

@GET 
    public Response step1() 
     throws ServletException, IOException, URISyntaxException, OAuthSystemException { 

    OAuthClientRequest request = OAuthClientRequest 
    .authorizationProvider(OAuthProviderType.GOOGLE) 
    .setClientId(CLIENT_ID) 
      .setScope("https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email") 
    .setRedirectURI(REDIRECT_URI) 
    .setResponseType("code") 
    .buildQueryMessage(); 

    logger.info("start oauth process: " + request.getLocationUri()); 

    //We send a redirect request to the browser so it can go to the consent screen of google. 
    return Response.status(Response.Status.TEMPORARY_REDIRECT).location(new URI(request.getLocationUri())).build(); 
    } 

    @GET 
    @Path("loggedin") 
    public Response getCode(@QueryParam("code") String code) 
     throws ServletException, IOException, URISyntaxException, OAuthSystemException, OAuthProblemException, OAuthRequestException { 

    logger.info("response from redirect. We obtained the following code: " + code); 

    OAuthClientRequest request = OAuthClientRequest 
    .tokenProvider(OAuthProviderType.GOOGLE) 
    .setGrantType(GrantType.AUTHORIZATION_CODE) 
    .setClientId(CLIENT_ID) 
    .setClientSecret(CLIENT_SECRET) 
    .setCode(code) 
      .setScope("https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email") 
    .setRedirectURI(REDIRECT_URI) 
    .buildBodyMessage(); 

    OAuthClient client = new OAuthClient(new URLConnectionClient()); 
    OAuthJSONAccessTokenResponse tokenResponse = client.accessToken(request, OAuthJSONAccessTokenResponse.class); 

    logger.log(Level.WARNING, "token: " + tokenResponse.getAccessToken() + " valid to: " + tokenResponse.getExpiresIn()); 

    return Response.status(Response.Status.TEMPORARY_REDIRECT).location(new URI("../index.html")).build(); 
    } 

문제는 지금 그 InvalidOAuthParametersException와 OAuthServiceFactory.getOAuthService().getCurrentUser() 충돌합니다. 나를 위해 작동하지 않았다/

는 I에 유래 여기에 비슷한 질문을 찾았지만 해결책은 적용되지 않습니다. oauth 프로세스 자체가 순서대로있는 것 같습니다. 액세스 토큰과 올바른 올바른 기간이 있습니다. (내가 뭔가를 프로세스 중에 잘못 되었다면 나는 oltu에서 빈/널 토큰을 얻을 것이고 토큰 문자열처럼 보이는 문자열이 아닐 것이라고 가정한다.)

이전에는 UserService를 사용하여 기본 사용자 객체에 액세스했습니다. 그러나 이것은 openId에서만 작동하는 것으로 보입니다.

내 oltu 접근 방식에 대한 대안은 구글 + 물건에 서명을 사용하는 것입니다. 이유는 내가이 간다 하나의 예를 발견 하고이 자바 스크립트 물건을 사용 - 엄격하게 서버에 모든 oauth 물건을 처리하고 다른 js 라이브러리를 포함하지 않습니다.

"ID"와 "사용자가 로그인"에 대한 사용자 개체의 어떤 종류에 액세스 할 수있는 대안은 있습니까? (UserService.getCurrentUser()에서는 사용자가 로그인하지 않은 경우 null이 반환됩니다).

답변

0

귀하의 질문 :

은 "ID"와 "사용자가 로그인"에 대한 사용자 개체의 어떤 종류에 액세스 할 수있는 대안은 있습니까? (UserService.getCurrentUser()에서는 사용자가 로그인하지 않은 경우 null이 반환됩니다).

유효한 스택 오버 플로우 답 :

예.

미래에 답을 묻는 질문을 얻을 수 있도록 질문의 지침을 검토하십시오. 이 질문은 너무 광범위하며 유감스럽게도 답변을 얻을 수 있습니다.

지금, 난 그냥 snarky하고 유효한 질문 (연루되는 일이기는하지만)이기 때문에, 당신은 SO이 토론을위한 장소가 아니다 말하고 싶어하지 않는다. 이런 질문을 the google group for appengine에 게시해야합니다.