An implementation of the Silhouette persistence layer using ReactiveMongo.
In your project/Build.scala:
libraryDependencies ++= Seq(
"com.mohiva" %% "play-silhouette-persistence-reactivemongo" % "5.0.6"
)
An instance of the DAO can be created as follow:
implicit lazy val format = Json.format[OAuth1Info]
val dao = new MongoAuthInfoDAO[OAuth1Info](reactiveMongoApi, config)
The Json format is needed to serialize the auth info data into Json. It will be passed implicitly to the DAO instance. The ReactiveMongo API and the Play configuration instance should be provided through dependency injection.
To provide bindings for Guice, you should implement a provider for every auth info type:
/**
* Provides the implementation of the delegable OAuth1 auth info DAO.
*
* @param reactiveMongoApi The ReactiveMongo API.
* @param config The Play configuration.
* @return The implementation of the delegable OAuth1 auth info DAO.
*/
@Provides
def provideOAuth1InfoDAO(reactiveMongoApi: ReactiveMongoApi, config: Configuration): DelegableAuthInfoDAO[OAuth1Info] = {
implicit lazy val format = Json.format[OAuth1Info]
new MongoAuthInfoDAO[OAuth1Info](reactiveMongoApi, config)
}
To define the collection name under which the auth info data should be saved, you must provide a configuration setting
in the form silhouette.persistence.reactivemongo.collection.[AuthInfo]
.
As example:
silhouette {
persistence.reactivemongo.collection.OAuth1Info = "auth.info.oauth1"
persistence.reactivemongo.collection.OAuth2Info = "auth.info.oauth2"
persistence.reactivemongo.collection.OpenIDInfo = "auth.info.oauth1"
persistence.reactivemongo.collection.PasswordInfo = "auth.info.passwords"
}
If no configuration can be found, then the DAO uses automatically the name of the auth info class prefixed with auth.
.
So for the OAuth1Info
type, it uses the collection name auth.OAuth1Info
.
The code is licensed under Apache License v2.0 and the documentation under CC BY 3.0.