Scala 值id不是securesocial.core.Identity的成员
我试图将SecuSocial模块添加到我的scala Play项目中。但我得到一个错误,如下所示:Scala 值id不是securesocial.core.Identity的成员,scala,playframework,securesocial,Scala,Playframework,Securesocial,我试图将SecuSocial模块添加到我的scala Play项目中。但我得到一个错误,如下所示: 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.
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
}
}
构建.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
我猜您正在使用Secure Social的主快照。这意味着,中央回购协议中的任何更改都将在您构建时下载 主快照的最新更改如下: 所以你的代码应该是
case class WithProvider(provider: String) extends Authorization {
def isAuthorized(user: Identity) = {
user.identityId.providerId == provider
}
}
我猜您正在使用Secure Social的主快照。这意味着,中央回购协议中的任何更改都将在您构建时下载 主快照的最新更改如下: 所以你的代码应该是
case class WithProvider(provider: String) extends Authorization {
def isAuthorized(user: Identity) = {
user.identityId.providerId == provider
}
}
我在问题中添加了build.sbt。我的图书馆依赖关系正确吗?或者想要更改?我不使用Play 2.2.0,但如果该版本的SecureSocial已发布,则您可以继续使用它。但我的假设是,我描述的更改也在2.2.0版本中。所以您必须将
id
更改为identityId
。我在问题中添加了build.sbt。我的图书馆依赖关系正确吗?或者想要更改?我不使用Play 2.2.0,但如果该版本的SecureSocial已发布,则您可以继续使用它。但我的假设是,我描述的更改也在2.2.0版本中。因此,您必须将id
更改为identityId
。