Skip to content
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
22 lines (17 sloc) 663 Bytes
import Foundation
import Result
/// Provides each request with optional URLCredentials.
public final class CredentialsPlugin: PluginType {
public typealias CredentialClosure = (TargetType) -> URLCredential?
let credentialsClosure: CredentialClosure
/// Initializes a CredentialsPlugin.
public init(credentialsClosure: @escaping CredentialClosure) {
self.credentialsClosure = credentialsClosure
// MARK: Plugin
public func willSend(_ request: RequestType, target: TargetType) {
if let credentials = credentialsClosure(target) {
_ = request.authenticate(usingCredential: credentials)
You can’t perform that action at this time.