New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Proposed implementation of RequestDelegate for authentication #18
Conversation
Make APIClientDelegate functions throws
I am trying to implement your pr and i have a question. How can we still implement our own version of
of the You have already implemented 2 of the 3 |
This change was released separately in 0.6.0. I'm not sure if |
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 the
AuthenticationCredential
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(_:)
.