2011-10-17 16 views
2

私はgaelykアプリケーションの1つに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を作成しました。あなたがスイートであるかどうかを確認できます。

関連する問題