Skip to content

Commit

Permalink
Merge pull request #76 from vrk-kpa/refactor/CredentialIssuerMetadata…
Browse files Browse the repository at this point in the history
…Resolver-api

Refactor credential issuer metadata resolver api
  • Loading branch information
dtsiflit authored Oct 10, 2024
2 parents aa315bc + c4f8444 commit 5483f37
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ 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?
) async -> Result<OutputType?, ErrorType>
source: InputType
) async -> Result<OutputType, ErrorType>
}

public actor CredentialIssuerMetadataResolver: CredentialIssuerMetadataType {
Expand All @@ -56,26 +56,14 @@ 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?
) async -> Result<CredentialIssuerMetadata?, Error> {
switch source {
case .credentialIssuer(let issuerId):

let pathComponent1 = ".well-known"
let pathComponent2 = "openid-credential-issuer"

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)
source: CredentialIssuerSource
) async -> Result<CredentialIssuerMetadata, some Error> {
switch source {
case .credentialIssuer(let issuerId):
let url = issuerId.url
.appendingPathComponent(".well-known")
.appendingPathComponent("openid-credential-issuer")
return await fetcher.fetch(url: url)
}
return .failure(ValidationError.error(reason: "Unable to retrieve metadata"))
case .none:
return .failure(CredentialError.genericError)
}
}
}
3 changes: 1 addition & 2 deletions Tests/Helpers/Wallet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 5483f37

Please sign in to comment.