Skip to content

Commit

Permalink
refactor: issuermetadata
Browse files Browse the repository at this point in the history
  • Loading branch information
auer-martin committed Oct 26, 2023
1 parent 1398555 commit eaa8e82
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,6 @@ export function getOfferedCredentialsWithMetadata(
)
}

// TODO: use getUniFormat??

for (const foundSupportedCredential of foundSupportedCredentials) {
offeredCredentials.push({
credentialSupported: foundSupportedCredential,
Expand Down Expand Up @@ -187,31 +185,19 @@ export function handleAuthorizationDetails(
authorizationDetails: AuthDetails | AuthDetails[],
metadata: EndpointMetadataResult
): AuthDetails | AuthDetails[] | undefined {
if (authorizationDetails) {
if (Array.isArray(authorizationDetails)) {
return authorizationDetails.map((value) => handleLocations({ ...value }, metadata))
} else {
return handleLocations({ ...authorizationDetails }, metadata)
}
if (Array.isArray(authorizationDetails)) {
return authorizationDetails.map((value) => handleLocations({ ...value }, metadata))
} else {
return handleLocations({ ...authorizationDetails }, metadata)
}
return authorizationDetails
}

// copied from sphereon
export function handleLocations(authorizationDetails: AuthDetails, metadata: EndpointMetadataResult) {
if (
authorizationDetails &&
(metadata.credentialIssuerMetadata?.authorization_server || metadata.authorization_endpoint)
) {
if (authorizationDetails.locations) {
if (Array.isArray(authorizationDetails.locations)) {
;(authorizationDetails.locations as string[]).push(metadata.issuer)
} else {
authorizationDetails.locations = [authorizationDetails.locations as string, metadata.issuer]
}
} else {
authorizationDetails.locations = metadata.issuer
}
if (metadata.credentialIssuerMetadata?.authorization_server || metadata.authorization_endpoint) {
if (!authorizationDetails.locations) authorizationDetails.locations = metadata.issuer
else if (Array.isArray(authorizationDetails.locations)) authorizationDetails.locations.push(metadata.issuer)
else authorizationDetails.locations = [authorizationDetails.locations as string, metadata.issuer]
}
return authorizationDetails
}
Expand Down
12 changes: 4 additions & 8 deletions packages/openid4vc-holder/tests/openid4vci-holder.e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ import { agentDependencies } from '@aries-framework/node'
import { ariesAskar } from '@hyperledger/aries-askar-nodejs'
import nock, { cleanAll, enableNetConnect } from 'nock'

import { OpenId4VcHolderModule, OpenIdCredentialFormatProfile } from '../src'
import { OpenIdCredentialFormatProfile } from '../src'
import { OpenId4VcHolderModule } from '../src/issuance/OpenId4VciHolderModule'

import {
mattrLaunchpadJsonLd_draft_08,
Expand Down Expand Up @@ -632,16 +633,11 @@ describe('OpenId4VcHolder', () => {

const resolved = await agent.modules.openId4VcHolder.resolveCredentialOffer(credentialOffer)

const authCodeFlowOptions = {
const resolvedAuthorizationRequest = await agent.modules.openId4VcHolder.resolveAuthorizationRequest(resolved, {
clientId: 'test-client',
redirectUri: 'http://blank',
scope: ['openid', 'OpenBadgeCredential'],
}

const resolvedAuthorizationRequest = await agent.modules.openId4VcHolder.resolveAuthorizationRequest(
resolved,
authCodeFlowOptions
)
})

const code =
'eyJhbGciOiJFZERTQSJ9.eyJzdWIiOiJiMGUxNjc4NS1kNzIyLTQyYTUtYTA0Zi00YmVhYjI4ZTAzZWEiLCJpc3MiOiJodHRwczovL2lzc3Vlci5wb3J0YWwud2FsdC5pZCIsImF1ZCI6IlRPS0VOIn0.ibEpHFaHFBLWyhEf4SotDQZBeh_FMrfncWapNox1Iv1kdQWQ2cLQeS1VrCyVmPsbx0tN2MAyDFG7DnAaq8MiAA'
Expand Down

0 comments on commit eaa8e82

Please sign in to comment.