@@ -27,11 +27,10 @@ import akka.stream.Materializer
27
27
import play .api .libs .streams .ActorFlow
28
28
import actors .{ClientSocketActor , PublishSocketMessageActor }
29
29
import play .api .mvc ._
30
- import scala .concurrent .ExecutionContext
30
+ import scala .concurrent .{ Future , ExecutionContext }
31
31
import authorization .AuthProvider
32
32
import authorization .AuthAction
33
- import play .api .libs .json .Json
34
-
33
+ import play .api .libs .json .{Json , JsValue }
35
34
36
35
37
36
trait MyExecutionContext extends ExecutionContext
@@ -205,23 +204,30 @@ class InstanceRegistryController @Inject()(implicit system: ActorSystem, mat: Ma
205
204
206
205
def authentication (): Action [AnyContent ] = Action .async {
207
206
request =>
208
- val json = request.body.asJson.get
209
-
210
- val username = (json \ " username" ).as[String ]
211
- val password = (json \ " password" ).as[String ]
212
-
213
- ws.url(instanceRegistryUri + " /users" + " /authenticate" )
214
- .withAuth(username, password, WSAuthScheme .BASIC )
215
- .withHttpHeaders((" Delphi-Authorization" , s " ${AuthProvider .generateJwt()}" ))
216
- .post(" " )
217
- .map { response =>
218
- if (response.status == 200 ) {
219
- Ok (Json .obj(" token" -> response.body, " refreshToken" -> " " ))
220
- } else {
221
- new Status (response.status)
207
+ // val json = request.body.asJson.get
208
+
209
+
210
+ val jsonBody : Option [JsValue ] = request.body.asJson
211
+
212
+ jsonBody.map { json =>
213
+
214
+ val username = (json \ " username" ).as[String ]
215
+ val password = (json \ " password" ).as[String ]
216
+
217
+ ws.url(instanceRegistryUri + " /users" + " /authenticate" )
218
+ .withAuth(username, password, WSAuthScheme .BASIC )
219
+ .withHttpHeaders((" Delphi-Authorization" , s " ${AuthProvider .generateJwt()}" ))
220
+ .post(" " )
221
+ .map { response =>
222
+ if (response.status == 200 ) {
223
+ Ok (Json .obj(" token" -> response.body, " refreshToken" -> " " ))
224
+ } else {
225
+ new Status (response.status)
226
+ }
222
227
}
223
- }(myExecutionContext)
224
- }
228
+ }.getOrElse{ Future (BadRequest (" Invalid body" ))}
229
+
230
+ }
225
231
226
232
/**
227
233
* This function is used to add a label to specific instance.
0 commit comments