AuthenticationInterceptor

public final class AuthenticationInterceptor : Interceptor

Implementation of a request interceptor which handles authentication. Currently there are four different authentication methods provided which are none, basicAuthentication, bearerToken and custom. To be able to be highly flexible to also being able to switch between authentication methods, we provided the possibility to pass in an autoclosure which is evaluated when this request is being intercepted.

  • The authentication methods currently supported.

    See more

    Declaration

    Swift

    public enum AuthenticationMethod
  • # Summary The initialiser for the AuthenticationRequestInterceptor

    Declaration

    Swift

    public init(authenticationMethod: @autoclosure @escaping (() -> AuthenticationMethod))

    Parameters

    authenticationMethod

    Either pass in an enum case or an autoclosure which then returns an AuthenticationMethod

  • # Summary Intercepting the request by adding the authentication header according to the given authentication metod.

    • When choosing none as authentication method nothing will be added to the request.
    • When choosing basicAuthentication a base 64 encoded string from the given username and password will be generated and added to the header fields of the request.
    • When choosing bearerToken the given token will be added to the header fields of the request.
    • When choosing custom the given header field key and header field value will be added to the header fields of the request.

    Declaration

    Swift

    public func intercept(_ request: URLRequest) -> URLRequest

    Parameters

    request

    The request to be intercepted.

    Return Value

    The intercepted request.