in pan-domain-auth-play/src/main/scala/com/gu/pandomainauth/action/Actions.scala [243:275]
def authenticateRequest(request: RequestHeader)(produceResultGivenAuthedUser: User => Future[Result]): Future[Result] = {
extractAuth(request) match {
case NotAuthenticated =>
logger.debug(s"user not authed against $domain, authing")
sendForAuth(request)
case InvalidCookie(e) =>
logger.warn("error checking user's auth, clear cookie and re-auth", e)
// remove the invalid cookie data
sendForAuth(request).map(flushCookie)
case Expired(authedUser) =>
logger.debug(s"user ${authedUser.user.email} login expired, sending to re-auth")
sendForAuth(request, Some(authedUser.user.email))
case GracePeriod(authedUser) =>
logger.debug(s"user ${authedUser.user.email} login expired, in grace period, sending to re-auth")
sendForAuth(request, Some(authedUser.user.email))
case NotAuthorized(authedUser) =>
logger.debug(s"user not authorized, show error")
Future(showUnauthedMessage(invalidUserMessage(authedUser))(request))
case Authenticated(authedUser) =>
val response = produceResultGivenAuthedUser(authedUser.user)
if (authedUser.authenticatedIn(system)) {
response
} else {
logger.debug(s"user ${authedUser.user.email} from other system valid: adding validity in $system.")
response.map(includeSystemInCookie(authedUser))
}
}
}