@@ -32,18 +32,21 @@ trait OAuth2Client {
32
32
val settings : OAuth2Settings
33
33
val httpService : HttpService
34
34
35
- def exchangeCodeForToken (code : String , callBackUrl : String , builder : OAuth2InfoBuilder )( implicit ec : ExecutionContext ) : Future [OAuth2Info ]
35
+ def exchangeCodeForToken (code : String , callBackUrl : String , builder : OAuth2InfoBuilder ): Future [OAuth2Info ]
36
36
37
- def retrieveProfile (profileUrl : String )( implicit ec : ExecutionContext ) : Future [JsValue ]
37
+ def retrieveProfile (profileUrl : String ): Future [JsValue ]
38
38
39
39
type OAuth2InfoBuilder = WSResponse => OAuth2Info
40
+
41
+ implicit def executionContext : ExecutionContext
40
42
}
41
43
42
44
object OAuth2Client {
43
45
44
- class Default (val httpService : HttpService , val settings : OAuth2Settings ) extends OAuth2Client {
46
+ class Default (val httpService : HttpService , val settings : OAuth2Settings )(implicit val executionContext : ExecutionContext )
47
+ extends OAuth2Client {
45
48
46
- override def exchangeCodeForToken (code : String , callBackUrl : String , builder : OAuth2InfoBuilder )( implicit ec : ExecutionContext ) : Future [OAuth2Info ] = {
49
+ override def exchangeCodeForToken (code : String , callBackUrl : String , builder : OAuth2InfoBuilder ): Future [OAuth2Info ] = {
47
50
val params = Map (
48
51
OAuth2Constants .ClientId -> Seq (settings.clientId),
49
52
OAuth2Constants .ClientSecret -> Seq (settings.clientSecret),
@@ -54,22 +57,26 @@ object OAuth2Client {
54
57
httpService.url(settings.accessTokenUrl).post(params).map(builder)
55
58
}
56
59
57
- override def retrieveProfile (profileUrl : String )( implicit ec : ExecutionContext ) : Future [JsValue ] =
60
+ override def retrieveProfile (profileUrl : String ): Future [JsValue ] =
58
61
httpService.url(profileUrl).get().map(_.json)
59
62
}
60
63
}
61
64
/**
62
65
* Base class for all OAuth2 providers
63
66
*/
64
- abstract class OAuth2Provider (routesService : RoutesService ,
65
- client : OAuth2Client ,
66
- cacheService : CacheService ) extends IdentityProvider with ApiSupport {
67
+ abstract class OAuth2Provider (
68
+ routesService : RoutesService ,
69
+ client : OAuth2Client ,
70
+ cacheService : CacheService )
71
+ extends IdentityProvider with ApiSupport {
72
+
73
+ protected implicit val executionContext : ExecutionContext = client.executionContext
67
74
protected val logger = play.api.Logger (this .getClass.getName)
68
75
69
76
val settings = client.settings
70
77
def authMethod = AuthenticationMethod .OAuth2
71
78
72
- protected def getAccessToken [A ](code : String )(implicit request : Request [A ], ec : ExecutionContext ): Future [OAuth2Info ] = {
79
+ protected def getAccessToken [A ](code : String )(implicit request : Request [A ]): Future [OAuth2Info ] = {
73
80
val callbackUrl = routesService.authenticationUrl(id)
74
81
client.exchangeCodeForToken(code, callbackUrl, buildInfo)
75
82
.recover {
@@ -91,7 +98,6 @@ abstract class OAuth2Provider(routesService: RoutesService,
91
98
}
92
99
93
100
def authenticate ()(implicit request : Request [AnyContent ]): Future [AuthenticationResult ] = {
94
- import scala .concurrent .ExecutionContext .Implicits .global
95
101
val maybeError = request.queryString.get(OAuth2Constants .Error ).flatMap(_.headOption).map {
96
102
case OAuth2Constants .AccessDenied => Future .successful(AuthenticationResult .AccessDenied ())
97
103
case error =>
@@ -181,7 +187,6 @@ abstract class OAuth2Provider(routesService: RoutesService,
181
187
val malformedJson = Json .obj(" error" -> " Malformed json" ).toString()
182
188
183
189
def authenticateForApi (implicit request : Request [AnyContent ]): Future [AuthenticationResult ] = {
184
- import scala .concurrent .ExecutionContext .Implicits .global
185
190
val maybeCredentials = request.body.asJson flatMap {
186
191
_.validate[LoginJson ] match {
187
192
case ok : JsSuccess [LoginJson ] =>
0 commit comments