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 moreAuthenticationInterceptorcompares 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.excessiveRefresherror is thrown.Declaration
Swift
public struct RefreshWindow
-
The
Credentialused to authenticate requests.Declaration
Swift
public var credential: Credential? { get set }
-
Creates an
AuthenticationInterceptorinstance from the specified parameters.A
nilRefreshWindowwill result in theAuthenticationInterceptornot checking for excessive refresh calls. It is recommended to always use aRefreshWindowto avoid endless refresh cycles.Declaration
Swift
public init(authenticator: AuthenticatorType, credential: Credential? = nil, refreshWindow: RefreshWindow? = RefreshWindow())Parameters
authenticatorThe
Authenticatortype.credentialThe
Credentialif it exists.nilby default.refreshWindowThe
RefreshWindowused 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)
View on GitHub
Install in Dash