Skip to content
Snippets Groups Projects
Commit ca8d5a65 authored by Felipe D'Abrantes's avatar Felipe D'Abrantes
Browse files

Update feed-service JWT structure

parent 83b39452
No related branches found
No related tags found
1 merge request!20Prevent non-admin users from inserting a question"
......@@ -14,7 +14,7 @@ import play.api.libs.json.Json
import javax.inject.Inject
class AuthenticationRequest[A](val jwt: String, val requesterId: Option[ObjectId], request: Request[A])
class AuthenticationRequest[A](val jwt: String, val requesterId: Option[ObjectId], val isAdmin: Boolean, request: Request[A])
extends WrappedRequest[A](request)
......@@ -30,8 +30,8 @@ class AuthenticationTransformer @Inject() (implicit val executionContext: Execut
* @return The new parameter to pass to the Action block.
*/
override def transform[A](request: Request[A]) = Future.successful {
val (jwt: String, requesterId: Option[ObjectId]) = processJWT(request)
new AuthenticationRequest(jwt, requesterId, request)
val (jwt: String, requesterId: Option[ObjectId], isAdmin: Boolean) = processJWT(request)
new AuthenticationRequest(jwt, requesterId, isAdmin, request)
}
/**
......@@ -40,7 +40,7 @@ class AuthenticationTransformer @Inject() (implicit val executionContext: Execut
* @param request The incoming request.
* @return The user ID specified in the JWT's payload.
*/
def processJWT[A](request: Request[A]): (String, Option[ObjectId]) = {
def processJWT[A](request: Request[A]): (String, Option[ObjectId], Boolean) = {
val privateKey = ConfigFactory.load().getString("jwt.privateKey")
try {
......@@ -53,13 +53,14 @@ class AuthenticationTransformer @Inject() (implicit val executionContext: Execut
val content = payload.get.content
val jsonContent = Json.parse(content)
val requesterId = (jsonContent \ "userId").as[String]
val isAdmin = (jsonContent \ "admin").as[Boolean]
(token, Some(new ObjectId(requesterId)))
(token, Some(new ObjectId(requesterId)), isAdmin)
}
catch {
case ex: Throwable => {
println(s"JWT Error: $ex")
("", None)
("", None, false)
}
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment