Skip to content

Commit af19ade

Browse files
committed
version 0.16.0
1 parent 6ed086e commit af19ade

File tree

2 files changed

+45
-33
lines changed

2 files changed

+45
-33
lines changed

README.md

Lines changed: 42 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@ The idea of this library originally comes from [oauth2-server](https://github.co
88

99
## Supported OAuth features
1010

11-
This library currently supports three grant types as follows
11+
This library supports all grant types.
1212

1313
- Authorization Code Grant
1414
- Resource Owner Password Credentials Grant
1515
- Client Credentials Grant
16+
- Implicit Grant
1617

1718
and an access token type called [Bearer](http://tools.ietf.org/html/rfc6750).
1819

@@ -24,7 +25,7 @@ If you'd like to use this with Play Framework, add "play2-oauth2-provider" to li
2425

2526
```scala
2627
libraryDependencies ++= Seq(
27-
"com.nulab-inc" %% "play2-oauth2-provider" % "0.15.1"
28+
"com.nulab-inc" %% "play2-oauth2-provider" % "0.16.0"
2829
)
2930
```
3031

@@ -50,7 +51,7 @@ Add "scala-oauth2-core" instead. In this case, you need to implement your own OA
5051

5152
```scala
5253
libraryDependencies ++= Seq(
53-
"com.nulab-inc" %% "scala-oauth2-core" % "0.15.1"
54+
"com.nulab-inc" %% "scala-oauth2-core" % "0.16.0"
5455
)
5556
```
5657

@@ -65,9 +66,9 @@ case class User(id: Long, name: String, hashedPassword: String)
6566

6667
class MyDataHandler extends DataHandler[User] {
6768

68-
def validateClient(clientCredential: ClientCredential, grantType: String): Future[Boolean] = ???
69+
def validateClient(request: AuthorizationRequest): Future[Boolean] = ???
6970

70-
def findUser(username: String, password: String): Future[Option[User]] = ???
71+
def findUser(request: AuthorizationRequest): Future[Option[User]] = ???
7172

7273
def createAccessToken(authInfo: AuthInfo[User]): Future[AccessToken] = ???
7374

@@ -79,8 +80,6 @@ class MyDataHandler extends DataHandler[User] {
7980

8081
def findAuthInfoByRefreshToken(refreshToken: String): Future[Option[AuthInfo[User]]] = ???
8182

82-
def findClientUser(clientCredential: ClientCredential, scope: Option[String]): Future[Option[User]] = ???
83-
8483
def deleteAuthCode(code: String): Future[Unit] = ???
8584

8685
def findAccessToken(token: String): Future[Option[AccessToken]] = ???
@@ -121,17 +120,48 @@ case class AuthInfo[User](
121120

122121
### Work with Play Framework
123122

124-
You should follow three steps below to work with Play Framework.
123+
You should follow four steps below to work with Play Framework.
125124

125+
* Customizing Grant Handlers
126126
* Define a controller to issue access token
127127
* Assign a route to the controller
128128
* Access to an authorized resource
129129

130-
First, define your own controller with mixining ```OAuth2Provider``` trait provided by this library to issue access token.
130+
You want to use which grant types are supported or to use a customized handler for a grant type, you should override the ```handlers``` map in a customized ```TokenEndpoint``` trait.
131+
132+
```scala
133+
class MyTokenEndpoint extends TokenEndpoint {
134+
override val handlers = Map(
135+
OAuthGrantType.AUTHORIZATION_CODE -> new AuthorizationCode(),
136+
OAuthGrantType.REFRESH_TOKEN -> new RefreshToken(),
137+
OAuthGrantType.CLIENT_CREDENTIALS -> new ClientCredentials(),
138+
OAuthGrantType.PASSWORD -> new Password(),
139+
OAuthGrantType.IMPLICIT -> new Implicit()
140+
)
141+
}
142+
```
143+
144+
Here's an example of a customized ```TokenEndpoint``` that 1) only supports the ```password``` grant type, and 2) customizes the ```password``` grant type handler to not require client credentials:
145+
146+
```scala
147+
class MyTokenEndpoint extends TokenEndpoint {
148+
val passwordNoCred = new Password() {
149+
override def clientCredentialRequired = false
150+
}
151+
152+
override val handlers = Map(
153+
OAuthGrantType.PASSWORD -> passwordNoCred
154+
)
155+
}
156+
```
157+
158+
Define your own controller with mixining ```OAuth2Provider``` trait provided by this library to issue access token with customized `TokenEndpoint`.
131159

132160
```scala
133161
import scalaoauth2.provider._
134162
object OAuth2Controller extends Controller with OAuth2Provider {
163+
override val tokenEndpoint = new MyTokenEndpoint()
164+
135165
def accessToken = Action.async { implicit request =>
136166
issueAccessToken(new MyDataHandler())
137167
}
@@ -158,26 +188,7 @@ object MyController extends Controller with OAuth2Provider {
158188
}
159189
```
160190

161-
If you'd like to change the OAuth workflow, modify handleRequest methods of TokenEndPoint and ```ProtectedResource``` traits.
162-
163-
### Customizing Grant Handlers
164-
165-
If you want to change which grant types are supported or to use a customized handler for a grant type, you can
166-
override the ```handlers``` map in a customized ```TokenEndpoint``` trait. Here's an example of a customized
167-
```TokenEndpoint``` that 1) only supports the ```password``` grant type, and 2) customizes the ```password``` grant
168-
type handler to not require client credentials:
169-
170-
```scala
171-
class MyTokenEndpoint extends TokenEndpoint {
172-
val passwordNoCred = new Password() {
173-
override def clientCredentialRequired = false
174-
}
175-
176-
override val handlers = Map(
177-
OAuthGrantType.PASSWORD -> passwordNoCred
178-
)
179-
}
180-
```
191+
If you'd like to change the OAuth workflow, modify handleRequest methods of `TokenEndPoint` and `ProtectedResource` traits.
181192

182193
### Using Action composition
183194

@@ -216,4 +227,5 @@ object MyController extends Controller {
216227

217228
- [Typetalk](https://typetalk.in/)
218229
- [Backlog](https://backlogtool.com/)
219-
- [Flic by Shortcut Labs](https://flic.io/)
230+
- [Flic by Shortcut Labs](
231+
)

project/Build.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ import com.typesafe.sbt.SbtScalariform._
55
object ScalaOAuth2Build extends Build {
66

77
lazy val _organization = "com.nulab-inc"
8-
lazy val _version = "0.16.0-SNAPSHOT"
9-
lazy val _playVersion = "2.4.0"
8+
lazy val _version = "0.16.0"
9+
lazy val _playVersion = "2.4.6"
1010

1111
val _scalaVersion = "2.10.5"
12-
val _crossScalaVersions = Seq("2.10.5", "2.11.6")
12+
val _crossScalaVersions = Seq("2.10.5", "2.11.7")
1313

1414
val commonDependenciesInTestScope = Seq(
1515
"org.scalatest" %% "scalatest" % "2.2.4" % "test"

0 commit comments

Comments
 (0)