hanabix / akka-stream-oauth2   0.1.21

Apache License 2.0 GitHub

Some useful graph shapes of akka-stream for OAuth2

Scala versions: 2.13 2.12

CI Publish Codacy Badge Coverage Status Maven Central

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

Dependencies

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.

val ignore: HttpRequest => Boolean = ???
val oauth2: OAuth2[AccessToken] = WeWork { ??? }
val routes: Route = { ??? }
val graph = GraphDSL.create() { implicit b =>
  import GraphDSL.Implicits._

  val guard = b.add(Guard.graph(oauth2, ignore))
  val merge = b.add(Merge[Future[HttpResponse]](2))
  val serve = b.add(Flow.fromFunction(Route.asyncHandler(routes)))

  // format: OFF
  guard.out0 ~> serve ~> merge
  guard.out1          ~> merge
  // format: ON

  FlowShape(guard.in, merge.out)
}
    
val parallelism: Int = ???
val flow = Flow[HttpRequest].via(graph).mapAsync(parallelism)(identity)
val f = http.bindAndHandle(flow, "0.0.0.0", 8080)
gracefulShutdown(f)