Hi
Wha’ts the preferred way to get an identity in an error handler (e.g. onNotAuthorized)?
Background:
I like to display a error view that shows the currently logged in user and the error.
I use the following method right now:
private def identity()(implicit requestHeader: RequestHeader): Future[Option[UserIdentity]] = {
Try {
val env = injector.instance[com.mohiva.play.silhouette.api.Environment[DefaultEnv]]
implicit val req: Request[AnyContent] = Request(requestHeader, AnyContent())
env.authenticatorService.retrieve.flatMap {
case None => Future.successful(None)
case Some(auth) =>
env.identityService
.retrieve(auth.loginInfo)
.fallbackTo(Future.successful(None))
}
}.getOrElse(Future.successful(None))
}
Best Regards
Stefan