Giter Site home page Giter Site logo

finagle-oauth2's Introduction

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

finagle-oauth2's People

Contributors

arron-green avatar clhodapp avatar crispywalrus avatar frgomes avatar gbicou avatar hughfdjackson avatar scala-steward avatar sergeykolbasov avatar vkostyukov avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

finagle-oauth2's Issues

Update for Finagle 6.42.0

Updating to Finagle 6.42.0 leads to errors such as this:
java.lang.NoSuchMethodError: com.twitter.finagle.http.HeaderMap.getAll

Would it be possible to get a new compatible release?

Update Reame with suitable examples

There is only one way to implement token service. But the protected service might be implemented in two usage ways of finagle-oauth2: w/o filter and w/ type-safe filter.

Make sure headers are correct

WWW-Authenticate: Bearer List(error="invalid_request", e, r, r, o, r, _, d, e, s, c, r, i, p, t, i, o, n, =, ", r, e, q, u, i, r, e, d,  , p, a, r, a, m, e, t, e, r, :,  , u, s, e, r, n, a, m, e, ")

We can use trait mixing for token service

Like this:

trait OAuthTokenConverter {
  def convertToken(t: Token): Response
}
val tokenizer = new OAuth2Endpoint(dataHandler) with OAuthTokenInJson with OAuthErrorInJson

OAuth2 Implicit grant type

Not sure where to ask this question, I'm about to implement OAuth2 for my application and the suitable grant type for my application is implicit. I've noticed that this library is not supporting it (or am I missing it), but the scala-oauth library does have it.

Is there a particular reason why it's not present and can I give it a shot to add it to this project?

Authentification Filters

case class AuthorizedRequest[U](authInfo: AuthInfo[U]) extends RequestProxy

val f = new AuthentificateFilter[User] with OAuth2 {
  def apply(req: Request, service: Service[AuthorizedRequest[User], Response]): Future[Response] =
    // try authorize
    service(AuthorizedRequest(authInfo))
    // else bad request
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.