oauth2


License

License

Categories

Categories

H2 Data Databases OAuth2 Security
GroupId

GroupId

com.github.finagle
ArtifactId

ArtifactId

finagle-oauth2_2.11
Last Version

Last Version

19.8.0
Release Date

Release Date

Type

Type

jar
Description

Description

oauth2
oauth2
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-oauth2

Download finagle-oauth2_2.11

How to add to project

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

Dependencies

compile (2)

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

test (2)

Group / Artifact Type Version
org.scalacheck : scalacheck_2.11 jar 1.14.0
org.scalatest : scalatest_2.11 jar 3.0.8

Project Modules

There are no modules declared in this project.

Build Status Maven Central

OAuth2 Provider for Finagle

This is a Finagle-friendly version of scala-oauth2-provider.

User Guide

  1. Implement com.twitter.finagle.oauth2.DataHandler using your own data store (in-memory, DB, etc).
  2. Use com.twitter.finagle.OAuth2 API to authorize requests and issue access tokens.

A service that emits OAuth2 access tokens based on request's credentials.

import com.twitter.finagle.OAuth2
import com.twitter.finagle.oauth2.{OAuthError, DataHandler}

import com.twitter.finagle.http.{Request, Response, Version, Status}
import com.twitter.finagle.Service
import com.twitter.util.Future

val dataHandler: DataHandler[?] = ???

object TokenService extends Service[Request, Response] with OAuth2 {
  def apply(req: Request): Future[Response] =
    issueAccessToken(req, dataHandler).flatMap { token =>
      val rep = Response(Version.Http11, Status.Ok)
      rep.setContentString(token.accessToken)
      Future.value(rep)
    } handle {
      case e: OAuthError => e.toResponse
    }
}

A service that checks whether the request contains a valid token.

import com.twitter.finagle.OAuth2
import com.twitter.finagle.oauth2.{OAuthError, DataHandler}

import com.twitter.finagle.http.{Request, Response, Version, Status}
import com.twitter.finagle.Service
import com.twitter.util.Future

object ProtectedService extends Service[Request, Response] with OAuth2 {
  def apply(req: Request): Future[Response] =
    authorize(req, dataHandler).flatMap { authInfo =>
      val rep = Response(Version.Http11, Status.Ok)
      rep.setContentString(s"Hello ${authInfo.user}!")
      Future.value(rep)
    } handle {
      case e: OAuthError => e.toResponse
    }
}
com.github.finagle

Finagle

Finagle ecosystem projects

Versions

Version
19.8.0
19.7.0
19.6.0
19.5.1
19.4.0
19.3.0
19.2.0
19.1.0
18.12.0
18.11.0
18.10.0
18.8.0
18.7.0
18.4.0
17.12.0
0.6.45
0.6.44
0.6.43
0.4.0
0.3.0
0.2.0
0.1.7
0.1.6
0.1.5
0.1.4