Back to Alamofire

AuthenticationInterceptor

docs/Classes/AuthenticationInterceptor.html

5.12.02.9 KB
Original Source

AuthenticationInterceptor

public final class AuthenticationInterceptor<AuthenticatorType> : RequestInterceptor, Sendable where AuthenticatorType : Authenticator

The AuthenticationInterceptor class manages the queuing and threading complexity of authenticating requests. It relies on an Authenticator type to handle the actual URLRequest authentication and Credential refresh.

Typealiases

`

                Credential
                `

Type of credential used to authenticate requests.

Declaration

Swift

public typealias Credential = AuthenticatorType.Credential

Helper Types

`

                RefreshWindow
                `

Type that defines a time window used to identify excessive refresh calls. When enabled, prior to executing a refresh, the AuthenticationInterceptor compares the timestamp history of previous refresh calls against the RefreshWindow. If more refreshes have occurred within the refresh window than allowed, the refresh is cancelled and an AuthorizationError.excessiveRefresh error is thrown.

See more

Declaration

Swift

public struct RefreshWindow

Properties

`

                credential
                `

The Credential used to authenticate requests.

Declaration

Swift

public var credential: Credential? { get set }

Initialization

`

                init(authenticator:credential:refreshWindow:)
                `

Creates an AuthenticationInterceptor instance from the specified parameters.

A nil RefreshWindow will result in the AuthenticationInterceptor not checking for excessive refresh calls. It is recommended to always use a RefreshWindow to avoid endless refresh cycles.

Declaration

Swift

public init(authenticator: AuthenticatorType,
            credential: Credential? = nil,
            refreshWindow: RefreshWindow? = RefreshWindow())

Parameters

| authenticator |

The Authenticator type.

| | credential |

The Credential if it exists. nil by default.

| | refreshWindow |

The RefreshWindow used to identify excessive refresh calls. RefreshWindow() by default.

|

Adapt

`

                adapt(_:for:completion:)
                `

Declaration

Swift

public func adapt(_ urlRequest: URLRequest, for session: Session, completion: @escaping @Sendable (Result<URLRequest, any Error>) -> Void)

Retry

`

                retry(_:for:dueTo:completion:)
                `

Declaration

Swift

public func retry(_ request: Request, for session: Session, dueTo error: any Error, completion: @escaping @Sendable (RetryResult) -> Void)