我正在Play Framework中借助Silhouette进行身份验证(JWT)制作 REST API。
我需要为每个安全响应添加一些标题(仅当用户登录时)。所以我想使用过滤器来添加它们。但是我得到了这个我无法弄清楚的奇怪错误:
对于请求 'POST /signIn' [Invalid Json: 由于 [Source: akka.util.ByteIterator$ByteArrayIterator$$anon$1@7bf4f7c1; 行:1,列:0]]
我的过滤器:
class SecuredFilter @Inject() (silhouette: Silhouette[DefaultEnv])(implicit val mat: Materializer, ec: ExecutionContext) extends Filter {
def apply(nextFilter: RequestHeader => Future[Result])(requestHeader: RequestHeader): Future[Result] = {
val action = silhouette.UserAwareAction.async { userAwareReq =>
userAwareReq.identity match {
case None => nextFilter(requestHeader)
case Some(identity) =>
nextFilter(requestHeader).map { result =>
result.withHeaders( /* add headers*/ )
}
}
}
action(requestHeader).run
}
}
过滤器类:
class Filters @Inject() (csrfFilter: CSRFFilter, securityHeadersFilter: SecurityHeadersFilter,
securedFilter: SecuredFilter) extends HttpFilters {
override def filters: Seq[EssentialFilter] = Seq(csrfFilter, securityHeadersFilter, securedFilter)
}