2011-10-04 46 views
1

我正在使用openid4java庫在spring-mvc應用程序中實現'使用google登錄'功能。使用openid4java進行'使用google登錄'時驗證失敗

它在我的本地tomcat服務器上正常工作,但在遠程服務器上突然停止工作。在那之前它工作得很好。

在catalina.out中做一些記錄後,我發現,谷歌重定向到返回URL

VerificationResult verification = openIdService.getConsumerManager().verify(
         receivingURL.toString(), 
         response, discovered); 

Identifier verified = verification.getVerifiedId(); //Null 

的驗證值是在遠程服務器上的空後的反應的驗證失敗。在本地服務器上它的一個URI

我知道,在處理響應時,ConsumerManager需要與用於放置身份驗證請求的實例相同 。

的代碼的其餘部分如下

有一個OpenIdController其中OpenIdService是自動裝配Autowired被實現。

OpenIdServiceImpl實現OpenIdService並具有返回consumerManager實例的getConsumerManager方法。

在OpenIdServiceImpl的構造中,創建了一個ConsumerManager實例。

創建提交表單並處理響應的操作寫入 OpenIdController中,並使用getConsumerManager方法訪問consumerManager實例。

編輯:

我試過表單提交之前,並在回調這裏輸出

Debugging OpenId: Discovered (before) OpenID2 
OP-endpoint:https://www.google.com/accounts/o8/ud 
ClaimedID:null 
Delegate:null 
Debugging OpenId: Discovered (after) OpenID2 
OP-endpoint:https://www.google.com/accounts/o8/ud 
ClaimedID:null 
Delegate:nul 

我做什麼錯在這裏記錄發現信息?但它適用於本地服務器!

或者與遠程服務器上的tomcat配置有關?

任何幫助表示讚賞。如果需要,我可以發佈代碼。

謝謝。

+0

你確定你提供DiscoveryInformation'您關聯期間得到了_same_'? (我假設沒有'verify(...)'拋出異常) – Osw

+0

我已經編輯了DiscoveryInformation日誌輸出的問題。謝謝 – naiquevin

回答

1

我可以通過在創建ConsumerManager實例後添加以下幾行來解決此問題。

consumerManager.setAssociations(new InMemoryConsumerAssociationStore()); 
consumerManager.setNonceVerifier(new InMemoryNonceVerifier(5000)); 
consumerManager.setMinAssocSessEnc(AssociationSessionType.DH_SHA256); 

我發現它在評論這裏的SampleConsumer例子之一提到 - http://code.google.com/p/openid4java/wiki/SampleConsumer

看到響應#3從底部。

還沒有嘗試找出它做什麼,而是希望其正確的方式來解決它:)