basicAuth


License

License

GroupId

GroupId

com.github.finagle
ArtifactId

ArtifactId

finagle-http-auth_2.11
Last Version

Last Version

0.1.0
Release Date

Release Date

Type

Type

jar
Description

Description

basicAuth
basicAuth
Project URL

Project URL

https://github.com/finagle/finagle-oauth2
Project Organization

Project Organization

com.github.finagle
Source Code Management

Source Code Management

https://github.com/finagle/finagle-http-auth

Download finagle-http-auth_2.11

How to add to project

<!-- https://jarcasting.com/artifacts/com.github.finagle/finagle-http-auth_2.11/ -->
<dependency>
    <groupId>com.github.finagle</groupId>
    <artifactId>finagle-http-auth_2.11</artifactId>
    <version>0.1.0</version>
</dependency>
// https://jarcasting.com/artifacts/com.github.finagle/finagle-http-auth_2.11/
implementation 'com.github.finagle:finagle-http-auth_2.11:0.1.0'
// https://jarcasting.com/artifacts/com.github.finagle/finagle-http-auth_2.11/
implementation ("com.github.finagle:finagle-http-auth_2.11:0.1.0")
'com.github.finagle:finagle-http-auth_2.11:jar:0.1.0'
<dependency org="com.github.finagle" name="finagle-http-auth_2.11" rev="0.1.0">
  <artifact name="finagle-http-auth_2.11" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.github.finagle', module='finagle-http-auth_2.11', version='0.1.0')
)
libraryDependencies += "com.github.finagle" % "finagle-http-auth_2.11" % "0.1.0"
[com.github.finagle/finagle-http-auth_2.11 "0.1.0"]

Dependencies

compile (2)

Group / Artifact Type Version
org.scala-lang : scala-library jar 2.11.8
com.twitter : finagle-http_2.11 jar 6.41.0

test (2)

Group / Artifact Type Version
org.scalacheck : scalacheck_2.11 jar 1.13.4
org.scalatest : scalatest_2.11 jar 3.0.0

Project Modules

There are no modules declared in this project.

Build Status Maven Central

Implementing HTTP Basic Auth as a Finagle filters for both clients and servers.

Usage

Starting an HTTP server with Basic Auth filter applied.

scala> import com.twitter.finagle.Http, com.twitter.finagle.http.{BasicAuth, Request, Response}, com.twitter.finagle.Service, com.twitter.util.Future
import com.twitter.finagle.Http
import com.twitter.finagle.http.{BasicAuth, Request, Response}
import com.twitter.finagle.Service
import com.twitter.util.Future

scala> val s = new Service[Request, Response] { def apply(req: Request): Future[Response] = Future.value(Response()) }
s: com.twitter.finagle.Service[com.twitter.finagle.http.Request,com.twitter.finagle.http.Response] = <function1>

scala> val ba = BasicAuth.serverFromCredentials("admin", "12345")
ba: com.twitter.finagle.http.BasicAuth.Server = <function2>


scala> Http.server.serve(":8081", ba.andThen(s))
res2: com.twitter.finagle.ListeningServer = Group(/0:0:0:0:0:0:0:0:8081)

Starting an HTTP client along with two Basic Auth filters indicating wrong and correct credentials.

import com.twitter.finagle.Http
import com.twitter.finagle.http.{BasicAuth, Request, Response}
import com.twitter.finagle.Service
import com.twitter.util.{Await, Future}

scala> val good = BasicAuth.client("admin", "12345")
good: com.twitter.finagle.http.BasicAuth.Client = <function2>

scala> val bad = BasicAuth.client("root", "deadbeef")
bad: com.twitter.finagle.http.BasicAuth.Client = <function2>

scala> val c = Http.client.newService("localhost:8081")
Jan 15, 2017 4:28:43 PM com.twitter.finagle.Init$$anonfun$4 apply$mcV$sp
INFO: Finagle version 6.41.0 (rev=95eedf5f41f78414fae25d93cc8fae02eeb5a75d) built at 20161220-164342
c: com.twitter.finagle.Service[com.twitter.finagle.http.Request,com.twitter.finagle.http.Response] = <function1>

scala> Await.result(good.andThen(c)(Request()))
res0: com.twitter.finagle.http.Response = Response("HTTP/1.1 Status(200)")

scala> Await.result(bad.andThen(c)(Request()))
res1: com.twitter.finagle.http.Response = Response("HTTP/1.1 Status(401)")

License

finagle-http-auth is licensed under the Apache License, Version 2.0 (the "License"); you may not use this software except in compliance with the License.

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

com.github.finagle

Finagle

Finagle ecosystem projects

Versions

Version
0.1.0