oauth2


License

License

Categories

Categories

H2 Data Databases OAuth2 Security
GroupId

GroupId

com.github.finagle
ArtifactId

ArtifactId

finagle-oauth2_2.10
Last Version

Last Version

0.1.7
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.10

How to add to project

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

Dependencies

compile (2)

Group / Artifact Type Version
org.scala-lang : scala-library jar 2.10.6
com.twitter : finagle-http_2.10 jar 6.35.0

test (2)

Group / Artifact Type Version
org.scalacheck : scalacheck_2.10 jar 1.13.1
org.scalatest : scalatest_2.10 jar 3.0.0

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
0.1.7
0.1.6
0.1.5
0.1.4