2011-10-17 5 views
2

Google gaelyk 앱 중 하나에 google-start-project 코드를 사용하고 있습니다. OAuth 2.0 인증 프로세스에 대한 그루비 코드입니다. 트위터와 달리 앱이 승인을 요청할 때마다 사용자는 앱을 계속 허용해야하며 이상하다고 생각합니다. 내가 만든 실수가 있니?OAuth 및 google plus api

// Check for an error returned by OAuth 
if (params.error) { 
    response.setContentType("text/plain"); 
    out.println("There was a problem during authentication: " + error); 
    log.severe("There was a problem during authentication: " + error); 
    return; 
} 

// When we're redirected back from the OAuth 2.0 grant page, a code will be supplied in a GET parameter named 'code' 

if (!params.code) { 
    // Now that we have the OAuth 2.0 code, we must exchange it for a token to make API requests. 

    // Build the authorization URL 
    AuthorizationRequestUrl authorizeUrl = new GoogleAuthorizationRequestUrl(
      CLIENT_ID, 
      REDIRECT_URI, 
      SCOPES 
     ); 
    authorizeUrl.redirectUri = REDIRECT_URI; 
    authorizeUrl.scope = SCOPES; 
    String authorizationUrl = authorizeUrl.build(); 

    log.info("Redirecting browser for OAuth 2.0 authorization to " + authorizationUrl); 
    response.sendRedirect(authorizationUrl); 
    return; 
} else { 
    log.info("Exchanging OAuth code for access token using server side call"); 

    AccessTokenResponse accessTokenResponse = new GoogleAccessTokenRequest.GoogleAuthorizationCodeGrant(
      new NetHttpTransport(), 
      new GsonFactory(), 
      CLIENT_ID, 
      CLIENT_SECRET, 
      params.code, 
      REDIRECT_URI 
     ).execute(); 

    log.info("Storing authentication token into the session"); 
    request.session.accessToken = accessTokenResponse.accessToken 
    request.session.refreshToken = accessTokenResponse.refreshToken 

    //The authentication is all done! Redirect back to the samples index so you can play with them. 
    response.sendRedirect("/"); 
} 
+0

redirect_uri의 가치는 무엇입니까? 여기서 문제가 생겼어. –

답변

0

아니요, 올바르게 처리하고 있습니다. Google+는 인증 전용 승인을 지원하지 않습니다. OAuth는 사용자를 인증하고 인증하는 것이 아닙니다. 인증을 위해서는 OpenID을 사용할 수 있습니다.

Btw는 시작 프로젝트가 약간 복잡하고, Maven을 지원하지 않으며, Google이 새로운 API 메소드를 추가 할 때 제 시간에 업데이트되지 않습니다. 따라서 this project을 만들었 으면, 당신에게 스위트가 있는지 확인할 수 있습니다.