Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor credential issuer metadata resolver api #76

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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