Skip to content
This repository has been archived by the owner on Nov 16, 2020. It is now read-only.

Commit

Permalink
Merge pull request #9 from cardoso/master
Browse files Browse the repository at this point in the history
Add AuthorizationHeader initializers for Basic and Bearer
  • Loading branch information
tanner0101 authored Jul 20, 2017
2 parents 2e697a4 + f53b922 commit dead10f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
8 changes: 6 additions & 2 deletions Sources/Authentication/Header/Basic.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import Core

extension AuthorizationHeader {
public var basic: Password? {
guard let range = string.range(of: "Basic ") else {
Expand All @@ -18,4 +16,10 @@ extension AuthorizationHeader {

return Password(username: username, password: password)
}

public init(basic: Password) {
let credentials = "\(basic.username):\(basic.password)"
let encoded = credentials.makeBytes().base64Encoded.makeString()
self.init(string: "Basic \(encoded)")
}
}
4 changes: 4 additions & 0 deletions Sources/Authentication/Header/Bearer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,8 @@ extension AuthorizationHeader {
let token = string.substring(from: range.upperBound)
return Token(string: token)
}

public init(bearer: Token) {
self.init(string: "Bearer \(bearer.string)")
}
}

0 comments on commit dead10f

Please sign in to comment.