Created Request.parseJWT extension method

This commit is contained in:
Caleb Kleveter 2017-12-07 09:11:27 -06:00
parent 5574a4c4d8
commit f9ac9a5ab6
1 changed files with 17 additions and 0 deletions

View File

@ -0,0 +1,17 @@
import HTTP
import JWT
import AuthProvider
extension Request {
func parseJWT() throws -> JWT {
guard let authHeader = auth.header else {
throw AuthenticationError.noAuthorizationHeader
}
guard let bearer = authHeader.bearer else {
throw AuthenticationError.invalidBearerAuthorization
}
return try JWT(token: bearer.string)
}
}