AccessTokenPlugin

public struct AccessTokenPlugin : PluginType

A plugin for adding basic or bearer-type authorization headers to requests. Example:

Authorization: Basic <token>
Authorization: Bearer <token>
Authorization: <Сustom> <token>
  • Undocumented

    Declaration

    Swift

    public typealias TokenClosure = (AuthorizationType) -> String
  • A closure returning the access token to be applied in the header.

    Declaration

    Swift

    public let tokenClosure: TokenClosure
  • Initialize a new AccessTokenPlugin.

    • tokenClosure: A closure returning the token to be applied in the pattern Authorization: <AuthorizationType> <token>

    Declaration

    Swift

    public init(tokenClosure: @escaping TokenClosure)
  • Prepare a request by adding an authorization header if necessary.

    • request: The request to modify.
    • target: The target of the request.

    Declaration

    Swift

    public func prepare(_ request: URLRequest, target: TargetType) -> URLRequest

    Return Value

    The modified URLRequest.