From 914c753cb287779b04400a7f3e0c74ceb0e8e10d Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Thu, 25 Apr 2024 12:18:21 -0700 Subject: [PATCH] Remove superfluous OAuthAuthorizationGranting protocol. --- Account/Sources/Account/Account.swift | 23 +++---------------- .../FeedlyAccountDelegate+OAuth.swift | 2 +- .../OAuthAccountAuthorizationOperation.swift | 2 +- .../OAuthAuthorizationCodeGranting.swift | 7 ------ 4 files changed, 5 insertions(+), 29 deletions(-) diff --git a/Account/Sources/Account/Account.swift b/Account/Sources/Account/Account.swift index 82ccf2b5d..f334da27e 100644 --- a/Account/Sources/Account/Account.swift +++ b/Account/Sources/Account/Account.swift @@ -385,33 +385,16 @@ public enum FetchType { } } - public static func oauthAuthorizationCodeGrantRequest(for type: AccountType, secretsProvider: SecretsProvider) -> URLRequest { - let grantingType: OAuthAuthorizationGranting.Type - switch type { - case .feedly: - grantingType = FeedlyAccountDelegate.self - default: - fatalError("\(type) does not support OAuth authorization code granting.") - } - - return grantingType.oauthAuthorizationCodeGrantRequest(secretsProvider: secretsProvider) - } - public static func requestOAuthAccessToken(with response: OAuthAuthorizationResponse, client: OAuthAuthorizationClient, accountType: AccountType, transport: Transport = URLSession.webserviceTransport(), secretsProvider: SecretsProvider) async throws -> OAuthAuthorizationGrant { - let grantingType: OAuthAuthorizationGranting.Type - - switch accountType { - case .feedly: - grantingType = FeedlyAccountDelegate.self - default: + + guard accountType == .feedly else { fatalError("\(accountType) does not support OAuth authorization code granting.") } - - return try await grantingType.requestOAuthAccessToken(with: response, transport: transport, secretsProvider: secretsProvider) + return try await FeedlyAccountDelegate.requestOAuthAccessToken(with: response, transport: transport, secretsProvider: secretsProvider) } public func receiveRemoteNotification(userInfo: [AnyHashable: Any]) async { diff --git a/Account/Sources/Account/AccountDelegates/FeedlyAccountDelegate+OAuth.swift b/Account/Sources/Account/AccountDelegates/FeedlyAccountDelegate+OAuth.swift index e75193dbb..608001356 100644 --- a/Account/Sources/Account/AccountDelegates/FeedlyAccountDelegate+OAuth.swift +++ b/Account/Sources/Account/AccountDelegates/FeedlyAccountDelegate+OAuth.swift @@ -24,7 +24,7 @@ public struct FeedlyOAuthAccessTokenResponse: Decodable, OAuthAccessTokenRespons public var scope: String } -extension FeedlyAccountDelegate: OAuthAuthorizationGranting { +extension FeedlyAccountDelegate { private static let oauthAuthorizationGrantScope = "https://cloud.feedly.com/subscriptions" diff --git a/Account/Sources/Account/Feedly/OAuthAccountAuthorizationOperation.swift b/Account/Sources/Account/Feedly/OAuthAccountAuthorizationOperation.swift index cadee9378..e8533703b 100644 --- a/Account/Sources/Account/Feedly/OAuthAccountAuthorizationOperation.swift +++ b/Account/Sources/Account/Feedly/OAuthAccountAuthorizationOperation.swift @@ -56,7 +56,7 @@ public enum OAuthAccountAuthorizationOperationError: LocalizedError { @MainActor public func run() { assert(presentationAnchor != nil, "\(self) outlived presentation anchor.") - let request = Account.oauthAuthorizationCodeGrantRequest(for: accountType, secretsProvider: secretsProvider) + let request = FeedlyAccountDelegate.oauthAuthorizationCodeGrantRequest(secretsProvider: secretsProvider) guard let url = request.url else { return DispatchQueue.main.async { diff --git a/Account/Sources/Account/Feedly/OAuthAuthorizationCodeGranting.swift b/Account/Sources/Account/Feedly/OAuthAuthorizationCodeGranting.swift index 2ffcbb1af..4fa9f379e 100644 --- a/Account/Sources/Account/Feedly/OAuthAuthorizationCodeGranting.swift +++ b/Account/Sources/Account/Feedly/OAuthAuthorizationCodeGranting.swift @@ -165,10 +165,3 @@ public protocol OAuthAuthorizationCodeGrantRequesting { /// - Returns: On success, the access token response appropriate for concrete type's service. On failure, throws possibly a `URLError` or `OAuthAuthorizationErrorResponse` value. func requestAccessToken(_ authorizationRequest: OAuthAccessTokenRequest) async throws -> FeedlyOAuthAccessTokenResponse } - -protocol OAuthAuthorizationGranting: AccountDelegate { - - @MainActor static func oauthAuthorizationCodeGrantRequest(secretsProvider: SecretsProvider) -> URLRequest - - @MainActor static func requestOAuthAccessToken(with response: OAuthAuthorizationResponse, transport: Transport, secretsProvider: SecretsProvider) async throws -> OAuthAuthorizationGrant -}