in pan-domain-auth-play/src/main/scala/com/gu/pandomainauth/action/Actions.scala [313:342]
def authenticateRequest(request: RequestHeader)(produceResultGivenAuthedUser: User => Future[Result]): Future[Result] = {
extractAuth(request) match {
case NotAuthenticated =>
logger.debug(s"user not authed against $domain, return 401")
Future(notAuthenticatedResult)
case InvalidCookie(e) =>
logger.warn("error checking user's auth, clear cookie and return 401", e)
// remove the invalid cookie data
Future(invalidCookieResult).map(flushCookie)
case Expired(authedUser) =>
logger.debug(s"user ${authedUser.user.email} login expired, return 419")
Future(expiredResult)
case GracePeriod(authedUser) =>
logger.debug(s"user ${authedUser.user.email} login expired but is in grace period.")
val response = produceResultGivenAuthedUser(authedUser.user)
responseWithSystemCookie(response, authedUser)
case NotAuthorized(authedUser) =>
logger.debug(s"user not authorized, return 403")
logger.debug(invalidUserMessage(authedUser))
Future(notAuthorizedResult)
case Authenticated(authedUser) =>
val response = produceResultGivenAuthedUser(authedUser.user)
responseWithSystemCookie(response, authedUser)
}
}