本文整理汇总了Scala中com.mohiva.play.silhouette.impl.providers.OAuth2Info类的典型用法代码示例。如果您正苦于以下问题:Scala OAuth2Info类的具体用法?Scala OAuth2Info怎么用?Scala OAuth2Info使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了OAuth2Info类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1: OAuth2InfoQueries
//设置package包名称以及导入依赖的类
package models.queries
import com.mohiva.play.silhouette.api.LoginInfo
import com.mohiva.play.silhouette.impl.providers.OAuth2Info
import jdub.async.{ Row, Statement }
import jdub.async.queries.BaseQueries
import org.joda.time.LocalDateTime
import play.api.libs.json.{ JsValue, Json }
object OAuth2InfoQueries extends BaseQueries[OAuth2Info] {
override protected val tableName = "oauth2_info"
override protected val columns = Seq("provider", "key", "access_token", "token_type", "expires_in", "refresh_token", "params", "created")
override protected val idColumns = Seq("provider", "key")
override protected val searchColumns = Seq("key", "access_token")
val getById = GetById
val removeById = RemoveById
case class CreateOAuth2Info(l: LoginInfo, o: OAuth2Info) extends Statement {
override val sql = insertSql
override val values = Seq(l.providerID, l.providerKey) ++ toDataSeq(o)
}
case class UpdateOAuth2Info(l: LoginInfo, o: OAuth2Info) extends Statement {
override val sql = {
s"update $tableName set access_token = ?, token_type = ?, expires_in = ?, refresh_token = ?, params = ?, created = ? where provider = ? and key = ?"
}
override val values = toDataSeq(o) ++ Seq(l.providerID, l.providerKey)
}
override protected def fromRow(row: Row) = {
val params = row.asOpt[String]("params").map { p =>
Json.parse(p).as[Map[String, JsValue]].map(x => x._1 -> x._2.as[String])
}
OAuth2Info(
accessToken = row.as[String]("access_token"),
tokenType = row.asOpt[String]("token_type"),
expiresIn = row.asOpt[Int]("expires_in"),
refreshToken = row.asOpt[String]("refresh_token"),
params = params
)
}
override protected def toDataSeq(o: OAuth2Info) = {
val params = o.params.map(p => Json.prettyPrint(Json.toJson(p)))
Seq(o.accessToken, o.tokenType, o.expiresIn, o.refreshToken, params, new LocalDateTime())
}
}
示例2: OAuth2InfoService
//设置package包名称以及导入依赖的类
package services.user
import com.mohiva.play.silhouette.api.LoginInfo
import com.mohiva.play.silhouette.impl.daos.DelegableAuthInfoDAO
import com.mohiva.play.silhouette.impl.providers.OAuth2Info
import jdub.async.Database
import models.queries.OAuth2InfoQueries
import play.api.libs.concurrent.Execution.Implicits.defaultContext
import scala.concurrent.Future
object OAuth2InfoService extends DelegableAuthInfoDAO[OAuth2Info] {
override def find(loginInfo: LoginInfo) = Database.query(OAuth2InfoQueries.getById(Seq(loginInfo.providerID, loginInfo.providerKey)))
override def save(loginInfo: LoginInfo, authInfo: OAuth2Info) = {
Database.transaction { conn =>
Database.execute(OAuth2InfoQueries.UpdateOAuth2Info(loginInfo, authInfo), Some(conn)).flatMap { rowsAffected =>
if (rowsAffected == 0) {
Database.execute(OAuth2InfoQueries.CreateOAuth2Info(loginInfo, authInfo), Some(conn)).map(x => authInfo)
} else {
Future.successful(authInfo)
}
}
}
}
override def add(loginInfo: LoginInfo, authInfo: OAuth2Info) = {
Database.execute(OAuth2InfoQueries.CreateOAuth2Info(loginInfo, authInfo)).map(x => authInfo)
}
override def update(loginInfo: LoginInfo, authInfo: OAuth2Info) = {
Database.execute(OAuth2InfoQueries.UpdateOAuth2Info(loginInfo, authInfo)).map(x => authInfo)
}
override def remove(loginInfo: LoginInfo) = {
Database.execute(OAuth2InfoQueries.removeById(Seq(loginInfo.providerID, loginInfo.providerKey))).map(x => Unit)
}
}
示例3: OAuth2InfoDAO
//设置package包名称以及导入依赖的类
package models.daos
import com.mohiva.play.silhouette.api.LoginInfo
import com.mohiva.play.silhouette.impl.daos.DelegableAuthInfoDAO
import com.mohiva.play.silhouette.impl.providers.OAuth2Info
import com.mongodb.casbah.Imports
import com.mongodb.casbah.Imports._
import models.Database
class OAuth2InfoDAO extends DelegableAuthInfoDAO[OAuth2Info] with AuthInfoDAO[OAuth2Info] {
override def data: Imports.MongoCollection = Database.db("oAuth2Info")
override def loadFromDB(dbAuthInfo: DBObject): OAuth2Info = {
val params = dbAuthInfo.getAs[DBObject]("params").map(_.map(e => e._1 -> e._2.toString).toMap)
OAuth2Info(
Database.loadString(dbAuthInfo, "accessToken"),
Database.loadOptionalString(dbAuthInfo, "tokenType"),
Database.loadOptionalString(dbAuthInfo, "expiresIn").map(_.toInt),
Database.loadOptionalString(dbAuthInfo, "refreshToken"),
params
)
}
override def convertToDB(loginInfo: LoginInfo, authInfo: OAuth2Info): DBObject = {
MongoDBObject(
"providerID" -> loginInfo.providerID,
"providerKey" -> loginInfo.providerKey,
"accessToken" -> authInfo.accessToken,
"tokenType" -> authInfo.tokenType,
"expiresIn" -> authInfo.expiresIn,
"refreshToken" -> authInfo.refreshToken,
"params" -> authInfo.params
)
}
}
示例4: find
//设置package包名称以及导入依赖的类
package models.daos.slick
import com.mohiva.play.silhouette.api.LoginInfo
import com.mohiva.play.silhouette.impl.daos.DelegableAuthInfoDAO
import com.mohiva.play.silhouette.impl.providers.OAuth2Info
import play.api.db.slick._
import scala.concurrent.Future
import models.daos.slick.DBTableDefinitions._
import play.api.db.slick.Config.driver.simple._
def find(loginInfo: LoginInfo): Future[Option[OAuth2Info]] = {
Future.successful(
DB withSession { implicit session =>
slickLoginInfos.filter(info => info.providerID === loginInfo.providerID && info.providerKey === loginInfo.providerKey).firstOption match {
case Some(info) =>
val oAuth2Info = slickOAuth2Infos.filter(_.loginInfoId === info.id).first
Some(OAuth2Info(oAuth2Info.accessToken, oAuth2Info.tokenType, oAuth2Info.expiresIn, oAuth2Info.refreshToken))
case None => None
}
}
)
}
}
示例5: HomeController
//设置package包名称以及导入依赖的类
package controllers
import javax.inject._
import com.kylegalloway.evescala.EveScalaBuilder
import com.mohiva.play.silhouette.api.Silhouette
import com.mohiva.play.silhouette.api.repositories.AuthInfoRepository
import com.mohiva.play.silhouette.impl.providers.OAuth2Info
import play.api.i18n.{I18nSupport, MessagesApi}
import play.api.libs.concurrent.Execution.Implicits._
import play.api.mvc._
import play.api.routing._
import silhouette.SessionEnv
import scala.concurrent.Future
@Singleton
class HomeController @Inject()(
val messagesApi: MessagesApi,
silhouette: Silhouette[SessionEnv],
authInfoRepository: AuthInfoRepository,
eveScalaBuilder: EveScalaBuilder
) extends Controller with I18nSupport {
def index = silhouette.SecuredAction.async { implicit request =>
authInfoRepository.find[OAuth2Info](request.identity.loginInfo).flatMap { authInfoOpt: Option[OAuth2Info] =>
authInfoOpt match {
case None => Future.successful(Redirect(routes.HomeController.login()))
case Some(authInfo) => {
Future.successful(Ok(views.html.home()))
}
}
}
}
def login = silhouette.UnsecuredAction { implicit request =>
Ok(views.html.login())
}
def walletJournal = silhouette.SecuredAction { implicit request =>
Ok(views.html.walletJournal())
}
def javascriptRoutes = Action { implicit request =>
Ok(
JavaScriptReverseRouter("jsRoutes")(
routes.javascript.EveSSOAuthController.authenticate,
routes.javascript.Assets.versioned
)
).as("text/javascript")
}
}