Skip to content

Commit a2a4537

Browse files
committed
Merge pull request #1 from nulab/master
fetch upstream
2 parents 4705fa4 + 684a2be commit a2a4537

File tree

5 files changed

+62
-41
lines changed

5 files changed

+62
-41
lines changed

README.md

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
[The OAuth 2.0](http://tools.ietf.org/html/rfc6749) server-side implementation written in Scala.
44

5-
This provides OAuth 2.0 server-side functionality and supporting function for [Playframework](http://www.playframework.com/). Playframework 2.2 is now supported.
5+
This provides OAuth 2.0 server-side functionality and supporting function for [Playframework](http://www.playframework.com/). Playframework 2.2 and 2.3 are now supported.
66

77
The idea of this library originally comes from [oauth2-server](https://github.com/yoichiro/oauth2-server) which is Java implementation of OAuth 2.0.
88

@@ -22,15 +22,15 @@ If you'd like to use this with Playframework, add "play2-oauth2-provider" to lib
2222

2323
```scala
2424
libraryDependencies ++= Seq(
25-
"com.nulab-inc" %% "play2-oauth2-provider" % "0.6.0"
25+
"com.nulab-inc" %% "play2-oauth2-provider" % "0.7.1"
2626
)
2727
```
2828

2929
Otherwise, add "scala-oauth2-core" instead. In this case, you need to implement your own OAuth provider working with web framework you use.
3030

3131
```scala
3232
libraryDependencies ++= Seq(
33-
"com.nulab-inc" %% "scala-oauth2-core" % "0.6.0"
33+
"com.nulab-inc" %% "scala-oauth2-core" % "0.7.1"
3434
)
3535
```
3636

@@ -111,3 +111,12 @@ object MyController extends Controller with OAuth2Provider {
111111
```
112112

113113
If you'd like to change the OAuth workflow, modify handleRequest methods of TokenEndPoint and ```ProtectedResource``` traits.
114+
115+
## Examples
116+
117+
- [Playframework 2.2](https://github.com/oyediyildiz/scala-oauth2-provider-example)
118+
119+
## Application using this library
120+
121+
- [Typetalk](https://typetalk.in/)
122+
- [Backlog](https://backlogtool.com/)

play2-oauth2-provider/src/main/scala/scalaoauth2/provider/OAuth2Provider.scala

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,10 @@ trait OAuth2Provider extends OAuth2BaseProvider {
110110
* @return Request is successful then return JSON to client in OAuth 2.0 format.
111111
* Request is failed then return BadRequest or Unauthorized status to client with cause into the JSON.
112112
*/
113-
def issueAccessToken[A, U](dataHandler: DataHandler[U])(implicit request: play.api.mvc.Request[A]): SimpleResult = {
113+
def issueAccessToken[A, U](dataHandler: DataHandler[U])(implicit request: play.api.mvc.Request[A]): Result = {
114114
TokenEndpoint.handleRequest(request, dataHandler) match {
115-
case Left(e) if e.statusCode == 400 => BadRequest(responseOAuthErrorJson(e))
116-
case Left(e) if e.statusCode == 401 => Unauthorized(responseOAuthErrorJson(e))
115+
case Left(e) if e.statusCode == 400 => BadRequest(responseOAuthErrorJson(e)).withHeaders(responseOAuthErrorHeader(e))
116+
case Left(e) if e.statusCode == 401 => Unauthorized(responseOAuthErrorJson(e)).withHeaders(responseOAuthErrorHeader(e))
117117
case Right(r) => Ok(Json.toJson(responseAccessToken(r)))
118118
}
119119
}
@@ -128,7 +128,7 @@ trait OAuth2Provider extends OAuth2BaseProvider {
128128
* @return Authentication is successful then the response use your API result.
129129
* Authentication is failed then return BadRequest or Unauthorized status to client with cause into the JSON.
130130
*/
131-
def authorize[A, U](dataHandler: DataHandler[U])(callback: AuthInfo[U] => SimpleResult)(implicit request: play.api.mvc.Request[A]): SimpleResult = {
131+
def authorize[A, U](dataHandler: DataHandler[U])(callback: AuthInfo[U] => Result)(implicit request: play.api.mvc.Request[A]): Result = {
132132
ProtectedResource.handleRequest(request, dataHandler) match {
133133
case Left(e) if e.statusCode == 400 => BadRequest.withHeaders(responseOAuthErrorHeader(e))
134134
case Left(e) if e.statusCode == 401 => Unauthorized.withHeaders(responseOAuthErrorHeader(e))
@@ -181,10 +181,10 @@ trait OAuth2AsyncProvider extends OAuth2BaseProvider {
181181
* @return Request is successful then return JSON to client in OAuth 2.0 format.
182182
* Request is failed then return BadRequest or Unauthorized status to client with cause into the JSON.
183183
*/
184-
def issueAccessToken[A, U](dataHandler: DataHandler[U])(implicit request: play.api.mvc.Request[A]): Future[SimpleResult] = {
184+
def issueAccessToken[A, U](dataHandler: DataHandler[U])(implicit request: play.api.mvc.Request[A]): Future[Result] = {
185185
TokenEndpoint.handleRequest(request, dataHandler) match {
186-
case Left(e) if e.statusCode == 400 => Future.successful(BadRequest(responseOAuthErrorJson(e)))
187-
case Left(e) if e.statusCode == 401 => Future.successful(Unauthorized(responseOAuthErrorJson(e)))
186+
case Left(e) if e.statusCode == 400 => Future.successful(BadRequest(responseOAuthErrorJson(e)).withHeaders(responseOAuthErrorHeader(e)))
187+
case Left(e) if e.statusCode == 401 => Future.successful(Unauthorized(responseOAuthErrorJson(e)).withHeaders(responseOAuthErrorHeader(e)))
188188
case Right(r) => Future.successful(Ok(Json.toJson(responseAccessToken(r))))
189189
}
190190
}
@@ -199,7 +199,7 @@ trait OAuth2AsyncProvider extends OAuth2BaseProvider {
199199
* @return Authentication is successful then the response use your API result.
200200
* Authentication is failed then return BadRequest or Unauthorized status to client with cause into the JSON.
201201
*/
202-
def authorize[A, U](dataHandler: DataHandler[U])(callback: AuthInfo[U] => Future[SimpleResult])(implicit request: play.api.mvc.Request[A]): Future[SimpleResult] = {
202+
def authorize[A, U](dataHandler: DataHandler[U])(callback: AuthInfo[U] => Future[Result])(implicit request: play.api.mvc.Request[A]): Future[Result] = {
203203
ProtectedResource.handleRequest(request, dataHandler) match {
204204
case Left(e) if e.statusCode == 400 => Future.successful(BadRequest.withHeaders(responseOAuthErrorHeader(e)))
205205
case Left(e) if e.statusCode == 401 => Future.successful(Unauthorized.withHeaders(responseOAuthErrorHeader(e)))

project/Build.scala

Lines changed: 35 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -4,58 +4,63 @@ import Keys._
44
object ScalaOAuth2Build extends Build {
55

66
lazy val _organization = "com.nulab-inc"
7-
lazy val _version = "0.6.0"
8-
lazy val _playVersion = "2.2.0"
7+
lazy val _version = "0.7.1"
8+
def _playVersion(version: String) = version match {
9+
case "2.11.0" => "2.3.0"
10+
case _ => "2.2.3"
11+
}
912

1013
val _scalaVersion = "2.10.3"
11-
val _crossScalaVersions = Seq("2.9.3", "2.10.3")
14+
val _crossScalaVersions = Seq("2.10.3", "2.11.0")
1215

1316
val commonDependenciesInTestScope = Seq(
14-
"org.scalatest" %% "scalatest" % "2.0" % "test"
17+
"org.scalatest" %% "scalatest" % "2.1.6" % "test"
18+
)
19+
20+
lazy val scalaOAuth2ProviderSettings = Defaults.defaultSettings ++ Seq(
21+
organization := _organization,
22+
version := _version,
23+
scalaVersion := _scalaVersion,
24+
crossScalaVersions := _crossScalaVersions,
25+
scalacOptions ++= _scalacOptions,
26+
publishTo <<= version { (v: String) => _publishTo(v) },
27+
publishMavenStyle := true,
28+
publishArtifact in Test := false,
29+
pomIncludeRepository := { x => false },
30+
pomExtra := _pomExtra
1531
)
1632

33+
lazy val root = Project(
34+
id = "scala-oauth2-provider",
35+
base = file("."),
36+
settings = scalaOAuth2ProviderSettings ++ Seq(
37+
name := "scala-oauth2-provider",
38+
description := "OAuth 2.0 server-side implementation written in Scala"
39+
)
40+
).aggregate(scalaOAuth2Core, play2OAuth2Provider)
41+
1742
lazy val scalaOAuth2Core = Project(
1843
id = "scala-oauth2-core",
1944
base = file("scala-oauth2-core"),
20-
settings = Defaults.defaultSettings ++ Seq(
21-
organization := _organization,
45+
settings = scalaOAuth2ProviderSettings ++ Seq(
2246
name := "scala-oauth2-core",
2347
description := "OAuth 2.0 server-side implementation written in Scala",
24-
version := _version,
25-
scalaVersion := _scalaVersion,
26-
crossScalaVersions := _crossScalaVersions,
27-
scalacOptions ++= _scalacOptions,
2848
libraryDependencies ++= Seq(
2949
"commons-codec" % "commons-codec" % "1.8"
30-
) ++ commonDependenciesInTestScope,
31-
publishTo <<= version { (v: String) => _publishTo(v) },
32-
publishMavenStyle := true,
33-
publishArtifact in Test := false,
34-
pomIncludeRepository := { x => false },
35-
pomExtra := _pomExtra
50+
) ++ commonDependenciesInTestScope
3651
)
3752
)
3853

3954
lazy val play2OAuth2Provider = Project(
4055
id = "play2-oauth2-provider",
4156
base = file("play2-oauth2-provider"),
42-
settings = Defaults.defaultSettings ++ Seq(
43-
organization := _organization,
57+
settings = scalaOAuth2ProviderSettings ++ Seq(
4458
name := "play2-oauth2-provider",
4559
description := "Support scala-oauth2-core library on Playframework Scala",
46-
version := _version,
47-
scalaVersion := _scalaVersion,
48-
crossScalaVersions := _crossScalaVersions,
49-
scalacOptions ++= _scalacOptions,
50-
resolvers += "Typesafe repository" at "http://repo.typesafe.com/typesafe/releases/",
60+
resolvers += "Typesafe repository" at "http://repo.typesafe.com/typesafe/maven-releases/",
5161
libraryDependencies ++= Seq(
52-
"com.typesafe.play" %% "play" % _playVersion % "provided"
53-
) ++ commonDependenciesInTestScope,
54-
publishTo <<= version { (v: String) => _publishTo(v) },
55-
publishMavenStyle := true,
56-
publishArtifact in Test := false,
57-
pomIncludeRepository := { x => false },
58-
pomExtra := _pomExtra
62+
"com.typesafe.play" %% "play" % _playVersion(scalaVersion.value) % "provided"
63+
) ++ commonDependenciesInTestScope
5964
)
6065
) dependsOn(scalaOAuth2Core)
6166

scala-oauth2-core/src/main/scala/scalaoauth2/provider/AccessTokenFetcher.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ object AuthHeader extends AccessTokenFetcher {
4949
val pairs = REGEXP_DIV_COMMA.split(trimmedHeader).map { exp =>
5050
val (key, value) = exp.split("=", 2) match {
5151
case Array(k, v) => (k, v.replaceFirst("^\"", ""))
52+
case Array(k) => (k, "")
5253
}
5354

5455
(key, URLDecoder.decode(value.replaceFirst("\"$", ""), "UTF-8"))

scala-oauth2-core/src/test/scala/scalaoauth2/provider/AuthHeaderSpec.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,4 +71,10 @@ class AuthHeaderSpec extends FlatSpec {
7171
result.token should be ("token1")
7272
}
7373

74+
it should "fetch illegal parameter without =" in {
75+
val result = AuthHeader.fetch(createRequest(Some("""OAuth access_token_value,fizz=buzz,foo""")))
76+
result.token should be ("access_token_value")
77+
result.params("fizz") should be ("buzz")
78+
result.params("foo") should be ("")
79+
}
7480
}

0 commit comments

Comments
 (0)