play 2.3 で securesocial3.0 を使う

公式のドキュメントが古いので、使い方をまとめる。

手順

  1. securesocialを導入する
  2. 設定

1.導入

1.1 build.sbt の libraryDependencies に securesocialを追加
libraryDependencies ++= Seq(
  ...
  "securesocial" %% "securesocial" % "3.0-M3" ,
  ...
)
conf/routes に securesocial のルーティングを追加
...
->         /auth                securesocial.Routes
...
1.3 conf/play.plugins に mail plugin を追加
...
1500:com.typesafe.plugin.CommonsMailerPlugin
...

優先度は状況に応じて
oauthのみを使う場合は特に追加する必要はありません

2.設定

2.1 conf/securesocial.conf

securesocial.confの記述は以前のドキュメントと変わらないので、http://securesocial.ws/guide/configuration.htmlを参考に
用意したら conf/application.conf に include

include "securesocial.conf"
2.2 Global.scala に 自前のRuntimeEnvironmentを作成

サンプルプロジェクトを参考に(コピペ)

object Global extends play.api.GlobalSettings {

  /**
   * The runtime environment for this sample app.
   */
  object MyRuntimeEnvironment extends RuntimeEnvironment.Default[DemoUser] {
    override implicit val executionContext = play.api.libs.concurrent.Execution.defaultContext
    override lazy val routes = new CustomRoutesService()
    override lazy val userService: InMemoryUserService = new InMemoryUserService()
    override lazy val eventListeners = List(new MyEventListener())
    override lazy val providers = ListMap(
      include(new TwitterProvider(routes, cacheService, oauth1ClientFor(TwitterProvider.Twitter)))
    )
  }

  /**
   * An implementation that checks if the controller expects a RuntimeEnvironment and
   * passes the instance to it if required.
   *
   * This can be replaced by any DI framework to inject it differently.
   *
   * @param controllerClass
   * @tparam A
   * @return
   */
  override def getControllerInstance[A](controllerClass: Class[A]): A = {
    val instance = controllerClass.getConstructors.find { c =>
      val params = c.getParameterTypes
      params.length == 1 && params(0) == classOf[RuntimeEnvironment[DemoUser]]
    }.map {
      _.asInstanceOf[Constructor[A]].newInstance(MyRuntimeEnvironment)
    }
    instance.getOrElse(super.getControllerInstance(controllerClass))
  }
}

既存のものをカスタマイズしたいときはRuntimeEnvironmentのフィールドをoverrideして書き換えてください。
e.g. viewを自前のものに置き換えたいなら、

override lazy val viewTemplates = new MyViewTemplates

securesocial/RuntimeEnvironment.scala at master · jaliss/securesocial · GitHub
実際にコードを見ながらのほうがわかりやすいかと思います。

自前のproviderを使いたいなら、
https://gist.github.com/krrrr38/d709ca3a8cf92e4294b7
を参考に