0
我試圖SecuSocial模塊添加到我的斯卡拉播放Project.But我得到了一個錯誤如下,值id不是securesocial.core.Identity成員
value id is not a member of securesocial.core.Identity
In /home/ram/Authentication/app/controllers/Application.scala at line 13.
Application.scala
package controllers
import play.api._
import play.api.mvc._
import securesocial.core.{Identity, Authorization}
trait Authorization {
def isAuthorized(user: Identity): Boolean
}
case class WithProvider(provider: String) extends Authorization {
def isAuthorized(user: Identity) = {
user.id.providerId == provider // ** I got error in this line **
}
}
object Application extends Controller with securesocial.core.SecureSocial {
def index = SecuredAction { implicit request =>
Ok(views.html.index(request.user))
}
def myAction = SecuredAction(WithProvider("twitter")) { implicit request =>
// do something here
Ok("You can see this because you logged in using Twitter")
}
// // a sample action using the new authorization hook
// def onlyTwitter = SecuredAction(WithProvider("twitter")) { implicit request =>
// //
// // Note: If you had a User class and returned an instance of it from UserService, this
// // is how you would convert Identity to your own class:
// //
// // request.user match {
// // case user: User => // do whatever you need with your user class
// // case _ => // did not get a User instance, should not happen,log error/thow exception
// // }
// Ok("You can see this because you logged in using Twitter")
// }
def page = UserAwareAction { implicit request =>
val userName = request.user match {
case Some(user) => user.fullName
case _ => "guest"
}
Ok("Hello %s".format(userName))
}
// you don't want to redirect to the login page for ajax calls so
// adding a ajaxCall = true will make SecureSocial return a forbidden error
// instead.
def ajaxCall = SecuredAction(ajaxCall = true) { implicit request =>
// return some json
}
}
build.sbt
name := "Authentication"
version := "1.0-SNAPSHOT"
libraryDependencies ++= Seq(
jdbc,
anorm,
cache,
"com.micronautics" % "securesocial" % "2.2.0" withSources
)
resolvers += Resolver.url("sbt-plugin-snapshots", url("http://repo.scala-sbt.org/scalasbt/sbt-plugin-releases/"))(Resolver.ivyStylePatterns)
play.Project.playScalaSettings
我在我的問題補充build.sbt。我的圖書館依賴性是否正確?還是想改變? – Ramprasad
我沒有使用Play 2.2.0,但如果該版本的SecureSocial已發佈,那麼您可以繼續使用它。但我的假設是,我所描述的變化也在2.2.0版本中。所以你必須將'id'改成'identityId'。 – maba
不。不起作用。發生錯誤。 – Ramprasad