Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/finagle/finagle-oauth2
OAuth2 Server-Side Provider for Finagle
https://github.com/finagle/finagle-oauth2
finagle finch oauth oauth2 scala
Last synced: about 3 hours ago
JSON representation
OAuth2 Server-Side Provider for Finagle
- Host: GitHub
- URL: https://github.com/finagle/finagle-oauth2
- Owner: finagle
- License: apache-2.0
- Created: 2014-05-18T13:47:26.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2024-02-29T16:50:43.000Z (9 months ago)
- Last Synced: 2024-05-01T21:18:12.936Z (7 months ago)
- Topics: finagle, finch, oauth, oauth2, scala
- Language: Scala
- Size: 137 KB
- Stars: 84
- Watchers: 9
- Forks: 22
- Open Issues: 32
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[![Build Status](https://img.shields.io/travis/finagle/finagle-oauth2/master.svg)](https://travis-ci.org/finagle/finagle-oauth2)
[![Maven Central](https://img.shields.io/maven-central/v/com.github.finagle/finagle-oauth2_2.12.svg)](https://maven-badges.herokuapp.com/maven-central/com.github.finagle/finagle-oauth2_2.12)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.
```scala
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.Futureval 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.
```scala
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.Futureobject 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]: https://github.com/twitter/finagle
[scala-oauth2-provider]: https://github.com/nulab/scala-oauth2-provider