Skip to content

Commit

Permalink
Merge pull request #5 from skelpo/develop
Browse files Browse the repository at this point in the history
Check if request body can exist before decoding
  • Loading branch information
calebkleveter authored Apr 26, 2018
2 parents 5df5571 + 86f51f6 commit e4e2b53
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions Sources/JWTAuthenticatable/BasicJWTAuthenticatable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ extension BasicJWTAuthenticatable {

public static func authBody(from request: Request)throws -> Future<BasicAuthorization?> {

// We can't decode the body if there isn't one, so let's return `nil` before we try and fail.
if request.http.method.hasRequestBody == .no || request.http.method.hasRequestBody == .unlikely {
return request.eventLoop.newSucceededFuture(result: nil)
}

// Get the request body as a `UsernamePassword` instance and convert it to a `BasicAuthorization` instance.
return try request.content.decode(UsernamePassword<Self>.self).map(to: AuthBody?.self) { authData in
guard let password = authData.password, let username = authData.username else {
Expand Down

0 comments on commit e4e2b53

Please sign in to comment.