• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Scala OAuth2Info类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了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())
  }
} 
开发者ID:laurinka,项目名称:golfmit,代码行数:49,代码来源:OAuth2InfoQueries.scala


示例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)
  }
} 
开发者ID:laurinka,项目名称:golfmit,代码行数:39,代码来源:OAuth2InfoService.scala


示例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
    )
  }
} 
开发者ID:Bastcloa,项目名称:testJenkins,代码行数:39,代码来源:OAuth2InfoDAO.scala


示例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
        }
      }
    )
  }
} 
开发者ID:mahmoudabbasi,项目名称:slickseedproject,代码行数:25,代码来源:OAuth2InfoDAOSlick.scala


示例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")
  }
} 
开发者ID:pequalsnp,项目名称:eve-isk-tracker,代码行数:53,代码来源:HomeController.scala



注:本文中的com.mohiva.play.silhouette.impl.providers.OAuth2Info类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Scala EventSource类代码示例发布时间:2022-05-23
下一篇:
Scala LifeCycle类代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap