Closed simorgh3196 closed 2 years ago
I am trying to implement your pr and i have a question. How can we still implement our own version of
public func shouldClientRetry(_ client: APIClient, for request: URLRequest, with error: Error) async throws -> Bool
of the APIClientDelegate
?
You have already implemented 2 of the 3 APIClientDelegate
methods and the last one has a default implementation.
Changed method shouldClientRetry( client: APIClient, withError error: Error) async throws -> Bool to shouldClientRetry( client: APIClient, for request: URLRequest, with error: Error) async throws -> Bool in APIClientDelegate because URLRequest was needed to manage retries for parallel requests.
This change was released separately in 0.6.0.
I'm not sure if Authenticator
should be shipped as part of the main framework. Unlike Alamofire, the goal of Get is to allow the users to build these things based on their requirements, while keeping the main framework small.
I suggested creating a separate authentication package and I'll happily mention it in the repo. What do you think @simorgh3196?
I'm going to close this PR for now because there are no plans to bake any authentication mechanisms into the framework. The goal is to provide just enough APIs to build on top of the framework.
Hello :)
I've created a proposal for an additional feature and would appreciate your feedback.
Introduction
Provides an implementation of APIClientDelegate specifically for authenticating requests.
Motivation
Alamofire provides an implementation called
AuthenticationInterceptor
for authentication. (docs)AuthenticationInterceptor
takes care of state management when sending concurrent requests. Therefore, users only need to implement each type that conforms to theAuthenticationCredential
protocol and theAuthenticator
protocol.I would like to see an implementation of
AuthenticationInterceptor
that manages authentication inGet
as well. (With an implementation based on async/await and actor, of course.)Implementation
Authenticator
Types adopting the
Authenticator
protocol will load or updateCredential
and apply theCredential
toURLRequest
.AuthenticationInterceptor
The
AuthenticationInterceptor
class provides authentication for requests using exclusive control. It relies on anAuthenticator
type to handle the actualURLRequest
authentication andCredential
refresh.AuthenticationInterceptor uses actor
State
, for exclusion control, and can apply and refresh authentication in order even for parallel requests.Sample Usage
Authenticator
protocol.AuthenticationInterceptor
withSampleAuthenticator
asAPIClientDelegate
Impact on existing packages
Breaking Changes
Changed method
shouldClientRetry(_ client: APIClient, withError error: Error) async throws -> Bool
toshouldClientRetry(_ client: APIClient, for request: URLRequest, with error: Error) async throws -> Bool
inAPIClientDelegate
becauseURLRequest
was needed to manage retries for parallel requests.Other Changes
In order to pass the
URLRequest
actually sent toAPIClientDelegate.shouldClientRetry(_:for:with:)
,APIClientDelegate.client(_:willSendRequest:)
is now called fromAPIClient.send(_:)
to call it fromAPIClient.send(_:)
instead ofAPIClient.actuallySend(_:)
.