aboutsummaryrefslogtreecommitdiff
path: root/src/main/scala/xyz/driver/core/rest/auth/AuthProvider.scala
diff options
context:
space:
mode:
authorZach Smith <zach@driver.xyz>2018-08-21 16:25:04 -0700
committerGitHub <noreply@github.com>2018-08-21 16:25:04 -0700
commit1f320bfba719d4cc3a4d46bc90a30d8a6bbd91d4 (patch)
tree156dfa050cd48f45918b31ea624a7aafc7ad8420 /src/main/scala/xyz/driver/core/rest/auth/AuthProvider.scala
parent4e903b7bd19dd9daf7172ab06fe2e52b6b1fdb60 (diff)
downloaddriver-core-1f320bfba719d4cc3a4d46bc90a30d8a6bbd91d4.tar.gz
driver-core-1f320bfba719d4cc3a4d46bc90a30d8a6bbd91d4.tar.bz2
driver-core-1f320bfba719d4cc3a4d46bc90a30d8a6bbd91d4.zip
Add UnauthorizedException and catch it in AuthProvider (#198)
* Add AuthorizationException and pass it through in authorize directive * Move recover to authenticator method
Diffstat (limited to 'src/main/scala/xyz/driver/core/rest/auth/AuthProvider.scala')
-rw-r--r--src/main/scala/xyz/driver/core/rest/auth/AuthProvider.scala5
1 files changed, 4 insertions, 1 deletions
diff --git a/src/main/scala/xyz/driver/core/rest/auth/AuthProvider.scala b/src/main/scala/xyz/driver/core/rest/auth/AuthProvider.scala
index 1fddd45..e1a94e1 100644
--- a/src/main/scala/xyz/driver/core/rest/auth/AuthProvider.scala
+++ b/src/main/scala/xyz/driver/core/rest/auth/AuthProvider.scala
@@ -4,6 +4,7 @@ import akka.http.scaladsl.server.directives.Credentials
import com.typesafe.scalalogging.Logger
import scalaz.OptionT
import xyz.driver.core.auth.{AuthToken, Permission, User}
+import xyz.driver.core.rest.errors.{ExternalServiceException, UnauthorizedException}
import xyz.driver.core.rest.{AuthorizedServiceRequestContext, ContextHeaders, ServiceRequestContext, serviceContext}
import scala.concurrent.{ExecutionContext, Future}
@@ -34,7 +35,9 @@ abstract class AuthProvider[U <: User](
log.info(s"Request (${context.trackingId}) missing authentication credentials")
Future.successful(None)
case Credentials.Provided(authToken) =>
- authenticatedUser(context.withAuthToken(AuthToken(authToken))).run
+ authenticatedUser(context.withAuthToken(AuthToken(authToken))).run.recover({
+ case ExternalServiceException(_, _, Some(UnauthorizedException(_))) => None
+ })
}
/**