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.
-
Type of credential used to authenticate requests.
Declaration
Swift
public typealias Credential = AuthenticatorType.Credential
-
Type that defines a time window used to identify excessive refresh calls. When enabled, prior to executing a refresh, the
See moreAuthenticationInterceptor
compares the timestamp history of previous refresh calls against theRefreshWindow
. If more refreshes have occurred within the refresh window than allowed, the refresh is cancelled and anAuthorizationError.excessiveRefresh
error is thrown.Declaration
Swift
public struct RefreshWindow
-
The
Credential
used to authenticate requests.Declaration
Swift
public var credential: Credential? { get set }
-
Creates an
AuthenticationInterceptor
instance from the specified parameters.A
nil
RefreshWindow
will result in theAuthenticationInterceptor
not checking for excessive refresh calls. It is recommended to always use aRefreshWindow
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.
-
Declaration
Swift
public func adapt(_ urlRequest: URLRequest, for session: Session, completion: @escaping @Sendable (Result<URLRequest, any Error>) -> Void)
-
Declaration
Swift
public func retry(_ request: Request, for session: Session, dueTo error: any Error, completion: @escaping @Sendable (RetryResult) -> Void)