我试图将 SecuSocial 模块添加到我的 scala Play 项目中。但我收到如下错误,
value id is not a member of securesocial.core.Identity
In /home/ram/Authentication/app/controllers/Application.scala at line 13.
应用程序.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