Skip to content

Commit

Permalink
Merge pull request #10 from RobotsAndPencils/remove-token-provider
Browse files Browse the repository at this point in the history
Remove token provider
  • Loading branch information
alexmazlov authored Jan 30, 2023
2 parents c6df778 + bb8e758 commit 9777085
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 27 deletions.
4 changes: 0 additions & 4 deletions AsyncNetworkService.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
4A2BCAE528B5693F0031844D /* UploadableFile.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4A2BCAE428B5693F0031844D /* UploadableFile.swift */; };
4A2BCAE728B5710C0031844D /* Data+.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4A2BCAE628B5710C0031844D /* Data+.swift */; };
4AB0D5032876099B00C36A3A /* NetworkResponseInterceptor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4AB0D5022876099B00C36A3A /* NetworkResponseInterceptor.swift */; };
4AB0D50728763C0E00C36A3A /* AuthenticationTokenProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4AB0D50628763C0E00C36A3A /* AuthenticationTokenProvider.swift */; };
E8A91431279B2D3800095A98 /* AsyncNetworkService.docc in Sources */ = {isa = PBXBuildFile; fileRef = E8A91430279B2D3800095A98 /* AsyncNetworkService.docc */; };
E8A91437279B2D3800095A98 /* AsyncNetworkService.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E8A9142C279B2D3800095A98 /* AsyncNetworkService.framework */; };
E8A9143C279B2D3800095A98 /* AsyncNetworkServiceTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = E8A9143B279B2D3800095A98 /* AsyncNetworkServiceTests.swift */; };
Expand Down Expand Up @@ -59,7 +58,6 @@
4A2BCAE428B5693F0031844D /* UploadableFile.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UploadableFile.swift; sourceTree = "<group>"; };
4A2BCAE628B5710C0031844D /* Data+.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Data+.swift"; sourceTree = "<group>"; };
4AB0D5022876099B00C36A3A /* NetworkResponseInterceptor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NetworkResponseInterceptor.swift; sourceTree = "<group>"; };
4AB0D50628763C0E00C36A3A /* AuthenticationTokenProvider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AuthenticationTokenProvider.swift; sourceTree = "<group>"; };
8347924927FCBCC100AFDDF3 /* Package.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Package.swift; sourceTree = "<group>"; };
E8A9142C279B2D3800095A98 /* AsyncNetworkService.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = AsyncNetworkService.framework; sourceTree = BUILT_PRODUCTS_DIR; };
E8A9142F279B2D3800095A98 /* AsyncNetworkService.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AsyncNetworkService.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -197,7 +195,6 @@
E8A91458279B353200095A98 /* URLRequestBuilder.swift */,
E8A9147E279B677600095A98 /* NetworkLogger.swift */,
4AB0D5022876099B00C36A3A /* NetworkResponseInterceptor.swift */,
4AB0D50628763C0E00C36A3A /* AuthenticationTokenProvider.swift */,
);
path = Common;
sourceTree = "<group>";
Expand Down Expand Up @@ -411,7 +408,6 @@
E8A91447279B2F5F00095A98 /* AsyncHTTPNetworkService.swift in Sources */,
E8A9144C279B308900095A98 /* URLRequest+.swift in Sources */,
E8A91457279B33F500095A98 /* NotificationObserver.swift in Sources */,
4AB0D50728763C0E00C36A3A /* AuthenticationTokenProvider.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
12 changes: 1 addition & 11 deletions AsyncNetworkService/AsyncHTTPNetworkService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import Foundation

/// A protocol used for `AsyncHTTPNetworkService` that speaks to a remote resource via URL requests
public protocol AsyncNetworkService: AnyObject {
var authenticationTokenProvider: AuthenticationTokenProvider? { get set }

/// If this is set, all network requests made through this service will have the modifier applied.
/// To apply multiple mutations to each network request, use `CompositeNetworkRequestModifier`.
var requestModifiers: [NetworkRequestModifier] { get set }
Expand All @@ -27,7 +25,6 @@ public protocol AsyncNetworkService: AnyObject {
}

public class AsyncHTTPNetworkService: AsyncNetworkService {
public weak var authenticationTokenProvider: AuthenticationTokenProvider?
public var requestModifiers: [NetworkRequestModifier]
public var responseInterceptors: [NetworkResponseInterceptor]

Expand All @@ -46,16 +43,9 @@ public class AsyncHTTPNetworkService: AsyncNetworkService {
}

private func applyModifiers(to request: ConvertsToURLRequest) -> URLRequest {
let updatedRequest = requestModifiers.reduce(request.asURLRequest()) { previousRequest, modifier in
requestModifiers.reduce(request.asURLRequest()) { previousRequest, modifier in
modifier.mutate(previousRequest)
}
// if we've set the authorization header lets update it with the new one that got sent back from the client
// if not, return the regular request
if updatedRequest.allHTTPHeaderFields?["Authorization"] != nil {
return updatedRequest.token(authenticationTokenProvider?.authenticationToken ?? "") // for all calls, for simplicity - lets add the bearer token
} else {
return updatedRequest
}
}

func safeRequest<T>(requestBuilder: @escaping () async throws -> T) async throws -> T {
Expand Down
12 changes: 0 additions & 12 deletions AsyncNetworkService/Common/AuthenticationTokenProvider.swift

This file was deleted.

0 comments on commit 9777085

Please sign in to comment.