项目作者: hanabix

项目描述 :
Some useful graph shapes of akka-stream for OAuth2
高级语言: Scala
项目地址: git://github.com/hanabix/akka-stream-oauth2.git
创建时间: 2018-06-14T09:15:19Z
项目社区:https://github.com/hanabix/akka-stream-oauth2

开源协议:Apache License 2.0

下载


CI Publish Codacy Badge Coverage Status Maven Central

akka-stream-oauth2 provides some useful graph shapes of akka-stream for OAuth2.

Dependencies

  1. libraryDependencies += "com.github.zhongl" %% "akka-stream-oauth2-<core or wechat or dingtalk>" % <latest tag>

Usage

A simple web application it’s authencation based on Wechat Work.

  1. val ignore: HttpRequest => Boolean = ???
  2. val oauth2: OAuth2[AccessToken] = WeWork { ??? }
  3. val routes: Route = { ??? }
  4. val graph = GraphDSL.create() { implicit b =>
  5. import GraphDSL.Implicits._
  6. val guard = b.add(Guard.graph(oauth2, ignore))
  7. val merge = b.add(Merge[Future[HttpResponse]](2))
  8. val serve = b.add(Flow.fromFunction(Route.asyncHandler(routes)))
  9. // format: OFF
  10. guard.out0 ~> serve ~> merge
  11. guard.out1 ~> merge
  12. // format: ON
  13. FlowShape(guard.in, merge.out)
  14. }
  15. val parallelism: Int = ???
  16. val flow = Flow[HttpRequest].via(graph).mapAsync(parallelism)(identity)
  17. val f = http.bindAndHandle(flow, "0.0.0.0", 8080)
  18. gracefulShutdown(f)