2014-02-26 130 views
4

我在使用Steam作爲OpenId提供程序時遇到問題。一切正常,直到我的網站的回調,我看到蒸汽登錄網頁,我可以登錄我的用戶,但是當執行回調時,我得到一個異常。 我使用play 2.2和Scala。該代碼是非常相似的play docsSteam OpenId和Play Framework

def loginPost = Action.async { implicit request => 
    OpenID.redirectURL("http://steamcommunity.com/openid", 
     routes.Application.openIDCallback.absoluteURL(), 
     realm = Option("http://mydomain.com/")) 
     .map(url => Redirect(url)) 
     .recover { case error => Redirect(routes.Application.login) } 
    } 

    def openIDCallback = Action.async { implicit request => 
     OpenID.verifiedId.map(info => Ok(info.id + "\n" + info.attributes)) 
     .recover { 
      case error => 
      println(error.getMessage()) //prints null 
      Redirect(routes.Application.login) 
     } 
    } 

堆棧跟蹤找到了一個:

Internal server error, for (GET) [/steam/login?openid.ns=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0&openid.mode=error&openid.error=Invalid+claimed_id+or+identity] -> 

play.api.Application$$anon$1: Execution exception[[BAD_RESPONSE$: null]] 
    at play.api.Application$class.handleError(Application.scala:293) ~[play_2.10.jar:2.2.1] 
    at play.api.DefaultApplication.handleError(Application.scala:399) [play_2.10.jar:2.2.1] 
    at play.core.server.netty.PlayDefaultUpstreamHandler$$anonfun$12$$anonfun$apply$1.applyOrElse(PlayDefaultUpstreamHandler.scala:165) [play_2.10.jar:2.2.1] 
    at play.core.server.netty.PlayDefaultUpstreamHandler$$anonfun$12$$anonfun$apply$1.applyOrElse(PlayDefaultUpstreamHandler.scala:162) [play_2.10.jar:2.2.1] 
    at scala.runtime.AbstractPartialFunction.apply(AbstractPartialFunction.scala:33) [scala-library-2.10.3.jar:na] 
    at scala.util.Failure$$anonfun$recover$1.apply(Try.scala:185) [scala-library-2.10.3.jar:na] 
Caused by: play.api.libs.openid.Errors$BAD_RESPONSE$: null 
    at play.api.libs.openid.Errors$BAD_RESPONSE$.<clinit>(OpenIDError.scala) ~[play_2.10.jar:2.2.1] 
    at play.api.libs.openid.OpenIDClient.verifiedId(OpenID.scala:111) ~[play_2.10.jar:2.2.1] 
    at play.api.libs.openid.OpenIDClient.verifiedId(OpenID.scala:92) ~[play_2.10.jar:2.2.1] 
    at controllers.Application$$anonfun$openIDCallback$1.apply(Application.scala:29) ~[classes/:2.2.1] 
    at controllers.Application$$anonfun$openIDCallback$1.apply(Application.scala:28) ~[classes/:2.2.1] 
    at play.api.mvc.Action$.invokeBlock(Action.scala:357) ~[play_2.10.jar:2.2.1] 

我在返回的網址看到此錯誤消息openid.error=Invalid+claimed_id+or+identity但無法找到相關的東西。

我錯過了什麼?謝謝。

回答

0

這是因爲Play Framework OpenID類不能正確生成重定向URL。從這一行代碼打印出來的url變量的值:http://openid.net/specs/openid-authentication-2_0.html#discovered_info

https://steamcommunity.com/openid/login?openid.ns=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0 
&openid.mode=checkid_setup 
&openid.claimed_id=http%3A%2F%2Fsteamcommunity.com%2Fopenid 
&openid.identity=http%3A%2F%2Fsteamcommunity.com%2Fopenid 
&openid.return_to=http%3A%2F%2Fwww.mydomain.com%2Fsteam%2Flogin 
&openid.realm=http%3A%2F%2Fwww.mydomain.com 

這是每次的OpenID 2.0規範不正確,具體爲:

.map(url => Redirect(url)) 

它最有可能看起來是這樣的:

如果最終用戶輸入OpenID提供商(OP)標識符,則不存在聲明標識符。爲了進行OpenID身份驗證請求,當輸入OP標識符時,必須使用值「http://specs.openid.net/auth/2.0/identifier_select」作爲聲明標識符和OP本地標識符。

此基礎上,生成的重定向url變量應該是:

https://steamcommunity.com/openid/login?openid.ns=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0 
&openid.mode=checkid_setup 
&openid.claimed_id=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0%2Fidentifier_select 
&openid.identity=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0%2Fidentifier_select 
&openid.return_to=http%3A%2F%2Fwww.mydomain.com%2Fsteam%2Flogin 
&openid.realm=http%3A%2F%2Fwww.mydomain.com 

我已經寫了一個問題,這在播放框架問題跟蹤:

https://github.com/playframework/playframework/issues/3740

與此同時,您可以在上使用任意數量的字符串替換技術變量將openid.claimed_idopenid.identity參數設置爲正確的http://specs.openid.net/auth/2.0/identifier_select值。