From a823c2261d7dd6cd887867a3b4516591baead8c1 Mon Sep 17 00:00:00 2001 From: Rosendahl Sami Date: Wed, 11 Sep 2024 16:59:24 +0300 Subject: [PATCH 1/4] Change CredentialIssuerMetadataType.resolve source parameter to non-optional --- .../CredentialOffer/CredentialIssuerMetadataResolver.swift | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/Sources/Main/Resolvers/CredentialOffer/CredentialIssuerMetadataResolver.swift b/Sources/Main/Resolvers/CredentialOffer/CredentialIssuerMetadataResolver.swift index 52b75a9..941e917 100644 --- a/Sources/Main/Resolvers/CredentialOffer/CredentialIssuerMetadataResolver.swift +++ b/Sources/Main/Resolvers/CredentialOffer/CredentialIssuerMetadataResolver.swift @@ -35,7 +35,7 @@ public protocol CredentialIssuerMetadataType { /// - source: The input source for resolving data. /// - Returns: An asynchronous result containing the resolved data or an error. func resolve( - source: InputType? + source: InputType ) async -> Result } @@ -56,7 +56,7 @@ public actor CredentialIssuerMetadataResolver: CredentialIssuerMetadataType { /// - source: The input source for resolving metadata. /// - Returns: An asynchronous result containing the resolved metadata or an error of type ResolvingError. public func resolve( - source: CredentialIssuerSource? + source: CredentialIssuerSource ) async -> Result { switch source { case .credentialIssuer(let issuerId): @@ -74,8 +74,6 @@ public actor CredentialIssuerMetadataResolver: CredentialIssuerMetadataType { return .success(metaData) } return .failure(ValidationError.error(reason: "Unable to retrieve metadata")) - case .none: - return .failure(CredentialError.genericError) } } } From 999fb63848531ea0e7f38ed1e819dfee207b78c8 Mon Sep 17 00:00:00 2001 From: Rosendahl Sami Date: Wed, 11 Sep 2024 17:03:00 +0300 Subject: [PATCH 2/4] Change CredentialIssuerMetadataType.resolve success result to non-optional --- .../CredentialOffer/CredentialIssuerMetadataResolver.swift | 4 ++-- Tests/Helpers/Wallet.swift | 3 +-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/Sources/Main/Resolvers/CredentialOffer/CredentialIssuerMetadataResolver.swift b/Sources/Main/Resolvers/CredentialOffer/CredentialIssuerMetadataResolver.swift index 941e917..5484403 100644 --- a/Sources/Main/Resolvers/CredentialOffer/CredentialIssuerMetadataResolver.swift +++ b/Sources/Main/Resolvers/CredentialOffer/CredentialIssuerMetadataResolver.swift @@ -36,7 +36,7 @@ public protocol CredentialIssuerMetadataType { /// - Returns: An asynchronous result containing the resolved data or an error. func resolve( source: InputType - ) async -> Result + ) async -> Result } public actor CredentialIssuerMetadataResolver: CredentialIssuerMetadataType { @@ -57,7 +57,7 @@ public actor CredentialIssuerMetadataResolver: CredentialIssuerMetadataType { /// - Returns: An asynchronous result containing the resolved metadata or an error of type ResolvingError. public func resolve( source: CredentialIssuerSource - ) async -> Result { + ) async -> Result { switch source { case .credentialIssuer(let issuerId): diff --git a/Tests/Helpers/Wallet.swift b/Tests/Helpers/Wallet.swift index 88029dc..5c7b7ef 100644 --- a/Tests/Helpers/Wallet.swift +++ b/Tests/Helpers/Wallet.swift @@ -66,8 +66,7 @@ extension Wallet { switch issuerMetadata { case .success(let metaData): - if let authorizationServer = metaData?.authorizationServers?.first, - let metaData { + if let authorizationServer = metaData.authorizationServers?.first { let resolver = AuthorizationServerMetadataResolver( oidcFetcher: Fetcher(session: self.session), oauthFetcher: Fetcher(session: self.session) From d71a97ed1d99cace365eb89158c45d81d4b4025e Mon Sep 17 00:00:00 2001 From: Rosendahl Sami Date: Wed, 11 Sep 2024 17:14:30 +0300 Subject: [PATCH 3/4] Do not mask Fetcher error in CredentialIssuerMetadataResolver.resolve --- .../CredentialIssuerMetadataResolver.swift | 24 +++++++------------ 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/Sources/Main/Resolvers/CredentialOffer/CredentialIssuerMetadataResolver.swift b/Sources/Main/Resolvers/CredentialOffer/CredentialIssuerMetadataResolver.swift index 5484403..b61ee32 100644 --- a/Sources/Main/Resolvers/CredentialOffer/CredentialIssuerMetadataResolver.swift +++ b/Sources/Main/Resolvers/CredentialOffer/CredentialIssuerMetadataResolver.swift @@ -57,23 +57,17 @@ public actor CredentialIssuerMetadataResolver: CredentialIssuerMetadataType { /// - Returns: An asynchronous result containing the resolved metadata or an error of type ResolvingError. public func resolve( source: CredentialIssuerSource - ) async -> Result { - switch source { - case .credentialIssuer(let issuerId): + ) async -> Result { + switch source { + case .credentialIssuer(let issuerId): + let pathComponent1 = ".well-known" + let pathComponent2 = "openid-credential-issuer" - let pathComponent1 = ".well-known" - let pathComponent2 = "openid-credential-issuer" + let url = issuerId.url + .appendingPathComponent(pathComponent1) + .appendingPathComponent(pathComponent2) - let url = issuerId.url - .appendingPathComponent(pathComponent1) - .appendingPathComponent(pathComponent2) - - let result = await fetcher.fetch(url: url) - let metaData = try? result.get() - if let metaData = metaData { - return .success(metaData) + return await fetcher.fetch(url: url) } - return .failure(ValidationError.error(reason: "Unable to retrieve metadata")) - } } } From c4f84449f2b459ec45667c69ba5356483962655c Mon Sep 17 00:00:00 2001 From: Rosendahl Sami Date: Wed, 11 Sep 2024 17:16:54 +0300 Subject: [PATCH 4/4] Inline local constants --- .../CredentialIssuerMetadataResolver.swift | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/Sources/Main/Resolvers/CredentialOffer/CredentialIssuerMetadataResolver.swift b/Sources/Main/Resolvers/CredentialOffer/CredentialIssuerMetadataResolver.swift index b61ee32..397b64d 100644 --- a/Sources/Main/Resolvers/CredentialOffer/CredentialIssuerMetadataResolver.swift +++ b/Sources/Main/Resolvers/CredentialOffer/CredentialIssuerMetadataResolver.swift @@ -60,13 +60,9 @@ public actor CredentialIssuerMetadataResolver: CredentialIssuerMetadataType { ) async -> Result { switch source { case .credentialIssuer(let issuerId): - let pathComponent1 = ".well-known" - let pathComponent2 = "openid-credential-issuer" - let url = issuerId.url - .appendingPathComponent(pathComponent1) - .appendingPathComponent(pathComponent2) - + .appendingPathComponent(".well-known") + .appendingPathComponent("openid-credential-issuer") return await fetcher.fetch(url: url) } }