0

Google AuthSub リクエストを認証したいと思います。基本的に、秘密鍵とそれぞれの証明書を生成し、この証明書を Google にアップロードし、その後の Google AuthSub への呼び出しで鍵で署名する必要があります。最も簡単な方法は、Java の keytool を次のように使用することだと思います。

# Generate the RSA keys and certificate
keytool -genkey -v -alias Example -keystore ./Example.jks\
  -keyalg RSA -sigalg SHA1withRSA\
  -dname "CN=www.example.com, OU=Engineering, O=My_Company, L=Mountain  View, ST=CA, C=US"\
  -storepass changeme -keypass changeme

# Output the public certificate to a file
keytool -export -rfc -keystore ./Example.jks -storepass changeme \
  -alias Example -file mycert.pem

( http://code.google.com/apis/gdata/docs/auth/authsub.html#keytoolで指定)

指定された証明書 mycert.pem を Google にアップロードしました。私の Java クライアントでは、次のように秘密鍵をロードしました。

PrivateKey key = AuthSubUtil.getPrivateKeyFromKeystore(
                               "Example.jks", "changeme", "Example", "changeme");

このキーのロード時に例外はスローされません。キーは、次のように AuthSub 呼び出し中に使用されます。

String requestUrl =
  AuthSubUtil.getRequestUrl("http://www.example.com/RetrieveToken",
                            "https://www.google.com/calendar/feeds/",
                            true,
                            true);
...
// Servlet context, user follows the 'next link' with token attached.
String onetimeUseToken = AuthSubUtil.getTokenFromReply(
                                           httpServletRequest.getQueryString());

// Exchange for the AuthSub token.
String sessionToken = AuthSubUtil.exchangeForSessionToken(onetimeUseToken, key);

// Use the token.
CalendarService.setAuthSubToken(sessionToken, key);

// Get calendars from the user.
URL feedUrl = 
    new URL("https://www.google.com/calendar/feeds/default/owncalendars/full");

// Exception is thrown HERE.
CalendarFeed resultFeed = service.getFeed(feedUrl, CalendarFeed.class);

例外は、トークンの設定中または交換中にスローされるのではなく、ユーザーのリソースにアクセスしようとしたときにスローされます。これをどうすればいいのかよくわかりません。例外は次のとおりです。

Token invalid - Invalid AuthSub token.

フィード URL とスコープ URL について、 https://http://を少しいじりましたが、ほとんど成功せず、特定の組み合わせを試していない可能性があります。

4

1 に答える 1

0

上記のすべてが正しく機能しているようですが、無関係なコーディングエラーが発生しました。記録として、httpとhttpsはどちらも、一方が一貫して使用されている限り機能します(そうでない場合は、「スコープ」エラーが発生します)。

于 2011-01-22T07:13:04.573 に答える