diff options
| -rw-r--r-- | ios/MullvadREST/RESTAPIProxy.swift | 29 | ||||
| -rw-r--r-- | ios/MullvadREST/RESTAuthorization.swift | 7 | ||||
| -rw-r--r-- | ios/MullvadREST/RESTRequestFactory.swift | 14 |
3 files changed, 23 insertions, 27 deletions
diff --git a/ios/MullvadREST/RESTAPIProxy.swift b/ios/MullvadREST/RESTAPIProxy.swift index 5defa28a24..6daf2418ee 100644 --- a/ios/MullvadREST/RESTAPIProxy.swift +++ b/ios/MullvadREST/RESTAPIProxy.swift @@ -12,8 +12,8 @@ import struct WireGuardKitTypes.IPAddressRange import class WireGuardKitTypes.PublicKey extension REST { - public final class APIProxy: Proxy<ProxyConfiguration> { - public init(configuration: ProxyConfiguration) { + public final class APIProxy: Proxy<AuthProxyConfiguration> { + public init(configuration: AuthProxyConfiguration) { super.init( name: "APIProxy", configuration: configuration, @@ -114,22 +114,27 @@ extension REST { retryStrategy: REST.RetryStrategy, completionHandler: @escaping CompletionHandler<CreateApplePaymentResponse> ) -> Cancellable { - let requestHandler = AnyRequestHandler { endpoint in - var requestBuilder = try self.requestFactory - .createRequestBuilder( + let requestHandler = AnyRequestHandler( + createURLRequest: { endpoint, authorization in + var requestBuilder = try self.requestFactory.createRequestBuilder( endpoint: endpoint, method: .post, pathTemplate: "create-apple-payment" ) - requestBuilder.setAuthorization(.accountNumber(accountNumber)) + requestBuilder.setAuthorization(authorization) - let body = CreateApplePaymentRequest( - receiptString: receiptString - ) - try requestBuilder.setHTTPBody(value: body) + let body = CreateApplePaymentRequest( + receiptString: receiptString + ) + try requestBuilder.setHTTPBody(value: body) - return requestBuilder.getRequest() - } + return requestBuilder.getRequest() + }, + authorizationProvider: createAuthorizationProvider( + accountNumber: accountNumber, + retryStrategy: .default + ) + ) let responseHandler = AnyResponseHandler { response, data -> ResponseHandlerResult<CreateApplePaymentResponse> in diff --git a/ios/MullvadREST/RESTAuthorization.swift b/ios/MullvadREST/RESTAuthorization.swift index 200c632f24..90478c9645 100644 --- a/ios/MullvadREST/RESTAuthorization.swift +++ b/ios/MullvadREST/RESTAuthorization.swift @@ -17,10 +17,7 @@ protocol RESTAuthorizationProvider { } extension REST { - enum Authorization { - case accountNumber(String) - case accessToken(String) - } + typealias Authorization = String struct AccessTokenProvider: RESTAuthorizationProvider { private let accessTokenManager: AccessTokenManager @@ -43,7 +40,7 @@ extension REST { retryStrategy: retryStrategy ) { operationCompletion in completion(operationCompletion.map { tokenData in - return .accessToken(tokenData.accessToken) + return tokenData.accessToken }) } } diff --git a/ios/MullvadREST/RESTRequestFactory.swift b/ios/MullvadREST/RESTRequestFactory.swift index f255bc9dcf..67368d959b 100644 --- a/ios/MullvadREST/RESTRequestFactory.swift +++ b/ios/MullvadREST/RESTRequestFactory.swift @@ -113,16 +113,10 @@ extension REST { } mutating func setAuthorization(_ authorization: REST.Authorization) { - let value: String - switch authorization { - case let .accountNumber(accountNumber): - value = "Token \(accountNumber)" - - case let .accessToken(accessToken): - value = "Bearer \(accessToken)" - } - - restRequest.urlRequest.addValue(value, forHTTPHeaderField: HTTPHeader.authorization) + restRequest.urlRequest.addValue( + "Bearer \(authorization)", + forHTTPHeaderField: HTTPHeader.authorization + ) } func getRequest() -> REST.Request { |
