Created Request.parseJWT extension method
This commit is contained in:
parent
5574a4c4d8
commit
f9ac9a5ab6
|
@ -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)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue