Frage

I tried to add SecuSocial module to my scala Play Project.But I got an error as follows,

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
War es hilfreich?

Lösung

I guess that you are using the master snapshot of Secure Social. This means that any changes in the central repo will be downloaded when you build.

The latest changes to the master snapshot is this: Renamed id field in Identity to identityId (breaks backwards compatibility).

So your code should be

case class WithProvider(provider: String) extends Authorization {
  def isAuthorized(user: Identity) = {
    user.identityId.providerId == provider
  }
}
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top