Skip to content

Commit

Permalink
chore: merge latest develop
Browse files Browse the repository at this point in the history
  • Loading branch information
nklomp committed Aug 2, 2024
1 parent 37a2f23 commit 5375279
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 56 deletions.
15 changes: 8 additions & 7 deletions packages/client/lib/IssuerSessionClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@ import { IssuerSessionIdRequestOpts, IssuerSessionResponse, OpenIDResponse, post
import { LOG } from './index';

export const acquireIssuerSessionId = async (opts: IssuerSessionIdRequestOpts): Promise<IssuerSessionResponse> => {
LOG.debug(`acquiring issuer session endpoint from endpoint ${opts.sessionEndpoint}`)
const sessionResponse = await post(opts.sessionEndpoint) as OpenIDResponse<IssuerSessionResponse>
LOG.debug(`acquiring issuer session endpoint from endpoint ${opts.sessionEndpoint}`);
const sessionResponse = (await post(opts.sessionEndpoint)) as OpenIDResponse<IssuerSessionResponse>;
if (sessionResponse.errorBody !== undefined) {
return Promise.reject(`an error occurred while requesting a issuer session token from endpoint ${opts.sessionEndpoint}:
${sessionResponse.errorBody.error} - ${sessionResponse.errorBody.error_description}`)
${sessionResponse.errorBody.error} - ${sessionResponse.errorBody.error_description}`);
}
if (sessionResponse.successBody === undefined || !Object.keys(sessionResponse.successBody).includes('session_id')) {
return Promise.reject(`an error occurred while requesting a issuer session token from endpoint ${opts.sessionEndpoint}, missing session_token response`)

return Promise.reject(
`an error occurred while requesting a issuer session token from endpoint ${opts.sessionEndpoint}, missing session_token response`,
);
}
return sessionResponse.successBody
}
return sessionResponse.successBody;
};
4 changes: 2 additions & 2 deletions packages/client/lib/MetadataClientV1_0_13.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,8 @@ export class MetadataClientV1_0_13 {
}
debug(`Issuer ${issuer} token endpoint ${token_endpoint}, credential endpoint ${credential_endpoint}`);

if(credentialIssuerMetadata?.session_endpoint !== undefined) {
session_endpoint = credentialIssuerMetadata.session_endpoint
if (credentialIssuerMetadata?.session_endpoint !== undefined) {
session_endpoint = credentialIssuerMetadata.session_endpoint;
}
return {
issuer,
Expand Down
20 changes: 10 additions & 10 deletions packages/client/lib/OpenID4VCIClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,16 @@ import {
getIssuerFromCredentialOfferPayload,
getSupportedCredentials,
getTypesFromCredentialSupported,
getTypesFromObject, IssuerSessionResponse,
JWK,
getTypesFromObject,
IssuerSessionResponse,
KID_JWK_X5C_ERROR,
NotificationRequest,
NotificationResult,
OID4VCICredentialFormat,
OpenId4VCIVersion,
PKCEOpts,
ProofOfPossessionCallbacks,
toAuthorizationResponsePayload
toAuthorizationResponsePayload,
} from '@sphereon/oid4vci-common';
import { CredentialFormat } from '@sphereon/ssi-types';
import Debug from 'debug';
Expand All @@ -45,12 +45,12 @@ import { CredentialOfferClient } from './CredentialOfferClient';
import { CredentialRequestOpts } from './CredentialRequestClient';
import { CredentialRequestClientBuilderV1_0_11 } from './CredentialRequestClientBuilderV1_0_11';
import { CredentialRequestClientBuilderV1_0_13 } from './CredentialRequestClientBuilderV1_0_13';
import { acquireIssuerSessionId } from './IssuerSessionClient';
import { MetadataClient } from './MetadataClient';
import { OpenID4VCIClientStateV1_0_11 } from './OpenID4VCIClientV1_0_11';
import { OpenID4VCIClientStateV1_0_13 } from './OpenID4VCIClientV1_0_13';
import { ProofOfPossessionBuilder } from './ProofOfPossessionBuilder';
import { generateMissingPKCEOpts, sendNotification } from './functions';
import { acquireIssuerSessionId } from './IssuerSessionClient';

const debug = Debug('sphereon:oid4vci');

Expand Down Expand Up @@ -363,14 +363,14 @@ export class OpenID4VCIClient {
return this.accessTokenResponse;
}

public async acquireIssuerSessionId() : Promise<IssuerSessionResponse | undefined> {
if(!this._state.endpointMetadata) {
return Promise.reject('endpointMetadata no loaded, retrieveServerMetadata()')
public async acquireIssuerSessionId(): Promise<IssuerSessionResponse | undefined> {
if (!this._state.endpointMetadata) {
return Promise.reject('endpointMetadata no loaded, retrieveServerMetadata()');
}
if(!('session_endpoint' in this._state.endpointMetadata) || !this._state.endpointMetadata.session_endpoint) {
return undefined
if (!('session_endpoint' in this._state.endpointMetadata) || !this._state.endpointMetadata.session_endpoint) {
return undefined;
}
return acquireIssuerSessionId({sessionEndpoint: this._state.endpointMetadata.session_endpoint})
return acquireIssuerSessionId({ sessionEndpoint: this._state.endpointMetadata.session_endpoint });
}

public async acquireCredentials({
Expand Down
66 changes: 31 additions & 35 deletions packages/client/lib/__tests__/IssuerSessionClient.spec.ts
Original file line number Diff line number Diff line change
@@ -1,64 +1,60 @@
import { IssuerSessionIdRequestOpts } from '@sphereon/oid4vci-common';
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
import nock from 'nock'
import { acquireIssuerSessionId } from '../IssuerSessionClient';
import nock from 'nock';

import { acquireIssuerSessionId } from '../IssuerSessionClient';

describe('IssuerSessionClient', () => {
describe('acquireIssuerSessionId', () => {
const mockSessionEndpoint = 'https://server.example.com/session_endpoint'
const mockSessionId = 'iOiJSUzI1NiIsInR'
const mockSessionEndpoint = 'https://server.example.com/session_endpoint';
const mockSessionId = 'iOiJSUzI1NiIsInR';

beforeEach(() => {
nock.cleanAll()
})
nock.cleanAll();
});

it('should successfully acquire an issuer session ID', async () => {
const mockResponse = {
session_id: mockSessionId
}
session_id: mockSessionId,
};

nock('https://server.example.com')
.post('/session_endpoint')
.reply(200, mockResponse, { 'Content-Type': 'application/json' })
nock('https://server.example.com').post('/session_endpoint').reply(200, mockResponse, { 'Content-Type': 'application/json' });

const opts: IssuerSessionIdRequestOpts = {
sessionEndpoint: mockSessionEndpoint
}
sessionEndpoint: mockSessionEndpoint,
};

const result = await acquireIssuerSessionId(opts)
const result = await acquireIssuerSessionId(opts);

expect(result).toEqual(mockResponse)
})
expect(result).toEqual(mockResponse);
});

it('should reject with an error if the response contains an error body', async () => {
const mockErrorResponse = {
error: 'invalid_request',
error_description: 'The request is missing a required parameter'
}
error_description: 'The request is missing a required parameter',
};

nock('https://server.example.com')
.post('/session_endpoint')
.reply(400, mockErrorResponse, { 'Content-Type': 'application/json' })
nock('https://server.example.com').post('/session_endpoint').reply(400, mockErrorResponse, { 'Content-Type': 'application/json' });

const opts: IssuerSessionIdRequestOpts = {
sessionEndpoint: mockSessionEndpoint
}
sessionEndpoint: mockSessionEndpoint,
};

await expect(acquireIssuerSessionId(opts)).rejects.toMatch(/an error occurred while requesting a issuer session token/)
})
await expect(acquireIssuerSessionId(opts)).rejects.toMatch(/an error occurred while requesting a issuer session token/);
});

it('should reject with an error if the response is missing the session_token', async () => {
nock('https://server.example.com')
.post('/session_endpoint')
.reply(200, undefined, { 'Content-Type': 'application/json' })
nock('https://server.example.com').post('/session_endpoint').reply(200, undefined, { 'Content-Type': 'application/json' });

const opts: IssuerSessionIdRequestOpts = {
sessionEndpoint: mockSessionEndpoint
}

await expect(acquireIssuerSessionId(opts)).rejects.toMatch(/an error occurred while requesting a issuer session token.*missing session_token response/)
})
})
})
sessionEndpoint: mockSessionEndpoint,
};

await expect(acquireIssuerSessionId(opts)).rejects.toMatch(
/an error occurred while requesting a issuer session token.*missing session_token response/,
);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export interface CredentialResponse extends ExperimentalSubjectIssuance {
}

export interface IssuerSessionResponse {
session_id: string
session_id: string;
}

export interface CredentialOfferRequestWithBaseUrl extends UniformCredentialOfferRequest {
Expand Down
2 changes: 1 addition & 1 deletion packages/oid4vci-common/lib/types/Generic.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -400,5 +400,5 @@ export interface NotificationErrorResponse {
}

export interface IssuerSessionIdRequestOpts {
sessionEndpoint: string
sessionEndpoint: string;
}

0 comments on commit 5375279

Please sign in to comment.