@sphereon/oid4vci-client 0.15.2-unstable.8 → 0.16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/AccessTokenClient.d.ts +7 -5
- package/dist/AccessTokenClient.d.ts.map +1 -1
- package/dist/AccessTokenClient.js +25 -5
- package/dist/AccessTokenClient.js.map +1 -1
- package/dist/AccessTokenClientV1_0_11.d.ts +7 -5
- package/dist/AccessTokenClientV1_0_11.d.ts.map +1 -1
- package/dist/AccessTokenClientV1_0_11.js +25 -5
- package/dist/AccessTokenClientV1_0_11.js.map +1 -1
- package/dist/AuthorizationCodeClient.d.ts.map +1 -1
- package/dist/AuthorizationCodeClient.js.map +1 -1
- package/dist/AuthorizationCodeClientV1_0_11.js +1 -1
- package/dist/AuthorizationCodeClientV1_0_11.js.map +1 -1
- package/dist/CredentialRequestClient.d.ts +5 -3
- package/dist/CredentialRequestClient.d.ts.map +1 -1
- package/dist/CredentialRequestClient.js +22 -4
- package/dist/CredentialRequestClient.js.map +1 -1
- package/dist/CredentialRequestClientV1_0_11.d.ts +5 -3
- package/dist/CredentialRequestClientV1_0_11.d.ts.map +1 -1
- package/dist/CredentialRequestClientV1_0_11.js +22 -4
- package/dist/CredentialRequestClientV1_0_11.js.map +1 -1
- package/dist/MetadataClientV1_0_13.d.ts.map +1 -1
- package/dist/MetadataClientV1_0_13.js +0 -5
- package/dist/MetadataClientV1_0_13.js.map +1 -1
- package/dist/OpenID4VCIClient.d.ts +2 -2
- package/dist/OpenID4VCIClient.d.ts.map +1 -1
- package/dist/OpenID4VCIClient.js +0 -12
- package/dist/OpenID4VCIClient.js.map +1 -1
- package/dist/OpenID4VCIClientV1_0_11.d.ts +2 -1
- package/dist/OpenID4VCIClientV1_0_11.d.ts.map +1 -1
- package/dist/OpenID4VCIClientV1_0_11.js.map +1 -1
- package/dist/OpenID4VCIClientV1_0_13.d.ts +2 -1
- package/dist/OpenID4VCIClientV1_0_13.d.ts.map +1 -1
- package/dist/OpenID4VCIClientV1_0_13.js.map +1 -1
- package/dist/ProofOfPossessionBuilder.d.ts +2 -1
- package/dist/ProofOfPossessionBuilder.d.ts.map +1 -1
- package/dist/ProofOfPossessionBuilder.js.map +1 -1
- package/dist/functions/AccessTokenUtil.d.ts.map +1 -1
- package/dist/functions/AccessTokenUtil.js +2 -2
- package/dist/functions/AccessTokenUtil.js.map +1 -1
- package/dist/functions/dpopUtil.d.ts +10 -0
- package/dist/functions/dpopUtil.d.ts.map +1 -0
- package/dist/functions/dpopUtil.js +30 -0
- package/dist/functions/dpopUtil.js.map +1 -0
- package/dist/functions/notifications.d.ts.map +1 -1
- package/dist/functions/notifications.js +3 -3
- package/dist/functions/notifications.js.map +1 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -1
- package/dist/index.js.map +1 -1
- package/lib/AccessTokenClient.ts +43 -7
- package/lib/AccessTokenClientV1_0_11.ts +43 -7
- package/lib/AuthorizationCodeClient.ts +1 -2
- package/lib/AuthorizationCodeClientV1_0_11.ts +1 -1
- package/lib/CredentialRequestClient.ts +38 -5
- package/lib/CredentialRequestClientV1_0_11.ts +38 -5
- package/lib/MetadataClientV1_0_13.ts +0 -6
- package/lib/OpenID4VCIClient.ts +4 -15
- package/lib/OpenID4VCIClientV1_0_11.ts +1 -1
- package/lib/OpenID4VCIClientV1_0_13.ts +1 -1
- package/lib/ProofOfPossessionBuilder.ts +1 -1
- package/lib/__tests__/AccessTokenClient.spec.ts +4 -11
- package/lib/__tests__/SphereonE2E.spec.test.ts +3 -3
- package/lib/functions/AccessTokenUtil.ts +2 -2
- package/lib/functions/dpopUtil.ts +35 -0
- package/lib/functions/notifications.ts +2 -4
- package/lib/index.ts +0 -1
- package/package.json +4 -3
- package/dist/IssuerSessionClient.d.ts +0 -3
- package/dist/IssuerSessionClient.d.ts.map +0 -1
- package/dist/IssuerSessionClient.js +0 -28
- package/dist/IssuerSessionClient.js.map +0 -1
- package/lib/IssuerSessionClient.ts +0 -17
- package/lib/__tests__/IssuerSessionClient.spec.ts +0 -64
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { JWK } from '@sphereon/oid4vc-common';
|
|
1
2
|
import {
|
|
2
3
|
AccessTokenResponse,
|
|
3
4
|
Alg,
|
|
@@ -19,7 +20,6 @@ import {
|
|
|
19
20
|
getSupportedCredentials,
|
|
20
21
|
getTypesFromCredentialSupported,
|
|
21
22
|
getTypesFromObject,
|
|
22
|
-
JWK,
|
|
23
23
|
KID_JWK_X5C_ERROR,
|
|
24
24
|
OID4VCICredentialFormat,
|
|
25
25
|
OpenId4VCIVersion,
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { JWK } from '@sphereon/oid4vc-common';
|
|
1
2
|
import {
|
|
2
3
|
AccessTokenResponse,
|
|
3
4
|
Alg,
|
|
@@ -17,7 +18,6 @@ import {
|
|
|
17
18
|
getIssuerFromCredentialOfferPayload,
|
|
18
19
|
getSupportedCredentials,
|
|
19
20
|
getTypesFromCredentialSupported,
|
|
20
|
-
JWK,
|
|
21
21
|
KID_JWK_X5C_ERROR,
|
|
22
22
|
NotificationRequest,
|
|
23
23
|
NotificationResult,
|
|
@@ -1,11 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
AccessTokenRequest,
|
|
3
|
-
AccessTokenResponse,
|
|
4
|
-
GrantTypes,
|
|
5
|
-
OpenIDResponse,
|
|
6
|
-
PRE_AUTH_CODE_LITERAL,
|
|
7
|
-
WellKnownEndpoints,
|
|
8
|
-
} from '@sphereon/oid4vci-common';
|
|
1
|
+
import { AccessTokenRequest, AccessTokenResponse, GrantTypes, PRE_AUTH_CODE_LITERAL, WellKnownEndpoints } from '@sphereon/oid4vci-common';
|
|
9
2
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
10
3
|
// @ts-ignore
|
|
11
4
|
import nock from 'nock';
|
|
@@ -50,7 +43,7 @@ describe('AccessTokenClient should', () => {
|
|
|
50
43
|
};
|
|
51
44
|
nock(MOCK_URL).post(/.*/).reply(200, JSON.stringify(body));
|
|
52
45
|
|
|
53
|
-
const accessTokenResponse
|
|
46
|
+
const accessTokenResponse = await accessTokenClient.acquireAccessTokenUsingRequest({
|
|
54
47
|
accessTokenRequest,
|
|
55
48
|
pinMetadata: {
|
|
56
49
|
isPinRequired: true,
|
|
@@ -88,7 +81,7 @@ describe('AccessTokenClient should', () => {
|
|
|
88
81
|
};
|
|
89
82
|
nock(MOCK_URL).post(/.*/).reply(200, JSON.stringify(body));
|
|
90
83
|
|
|
91
|
-
const accessTokenResponse
|
|
84
|
+
const accessTokenResponse = await accessTokenClient.acquireAccessTokenUsingRequest({
|
|
92
85
|
accessTokenRequest,
|
|
93
86
|
asOpts: { as: MOCK_URL },
|
|
94
87
|
});
|
|
@@ -227,7 +220,7 @@ describe('AccessTokenClient should', () => {
|
|
|
227
220
|
.post(/.*/)
|
|
228
221
|
.reply(200, {});
|
|
229
222
|
|
|
230
|
-
const response
|
|
223
|
+
const response = await accessTokenClient.acquireAccessToken({
|
|
231
224
|
credentialOffer: INITIATION_TEST,
|
|
232
225
|
pin: '1234',
|
|
233
226
|
});
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import * as crypto from 'crypto';
|
|
2
2
|
|
|
3
|
+
import { uuidv4 } from '@sphereon/oid4vc-common';
|
|
3
4
|
import { Alg, Jwt, ProofOfPossessionCallbacks } from '@sphereon/oid4vci-common';
|
|
4
5
|
import { CredentialMapper } from '@sphereon/ssi-types';
|
|
5
6
|
import * as didts from '@transmute/did-key.js';
|
|
6
7
|
import { fetch } from 'cross-fetch';
|
|
7
8
|
import debug from 'debug';
|
|
8
9
|
import { importJWK, JWK, SignJWT } from 'jose';
|
|
9
|
-
import { v4 } from 'uuid';
|
|
10
10
|
|
|
11
11
|
import { OpenID4VCIClientV1_0_11 } from '..';
|
|
12
12
|
|
|
@@ -94,7 +94,7 @@ async function getCredentialOffer(format: 'ldp_vc' | 'jwt_vc_json'): Promise<Cre
|
|
|
94
94
|
credentials: ['GuestCredential'],
|
|
95
95
|
grants: {
|
|
96
96
|
'urn:ietf:params:oauth:grant-type:pre-authorized_code': {
|
|
97
|
-
'pre-authorized_code':
|
|
97
|
+
'pre-authorized_code': uuidv4().substring(0, 10),
|
|
98
98
|
user_pin_required: false,
|
|
99
99
|
},
|
|
100
100
|
},
|
|
@@ -165,7 +165,7 @@ describe('ismapolis bug report #63, https://github.com/Sphereon-Opensource/OID4V
|
|
|
165
165
|
format: 'jwt_vc_json',
|
|
166
166
|
alg: Alg.ES256K,
|
|
167
167
|
kid: didDocument.verificationMethod[0].id,
|
|
168
|
-
jti:
|
|
168
|
+
jti: uuidv4(),
|
|
169
169
|
});
|
|
170
170
|
console.log(JSON.stringify(credentialResponse.credential));
|
|
171
171
|
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import { uuidv4 } from '@sphereon/oid4vc-common';
|
|
1
2
|
import { AccessTokenRequest, AccessTokenRequestOpts, Jwt, OpenId4VCIVersion } from '@sphereon/oid4vci-common';
|
|
2
|
-
import { v4 } from 'uuid';
|
|
3
3
|
|
|
4
4
|
import { ProofOfPossessionBuilder } from '../ProofOfPossessionBuilder';
|
|
5
5
|
|
|
@@ -35,7 +35,7 @@ export const createJwtBearerClientAssertion = async (
|
|
|
35
35
|
iss: clientId,
|
|
36
36
|
sub: clientId,
|
|
37
37
|
aud: credentialIssuer,
|
|
38
|
-
jti:
|
|
38
|
+
jti: uuidv4(),
|
|
39
39
|
exp: Date.now() / 1000 + 60,
|
|
40
40
|
iat: Date.now() / 1000 - 60,
|
|
41
41
|
},
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { dpopTokenRequestNonceError } from '@sphereon/oid4vc-common';
|
|
2
|
+
import { OpenIDResponse } from 'oid4vci-common';
|
|
3
|
+
|
|
4
|
+
export type RetryRequestWithDPoPNonce = { ok: true; dpopNonce: string } | { ok: false };
|
|
5
|
+
|
|
6
|
+
export function shouldRetryTokenRequestWithDPoPNonce(response: OpenIDResponse<unknown, unknown>): RetryRequestWithDPoPNonce {
|
|
7
|
+
if (!response.errorBody || response.errorBody.error !== dpopTokenRequestNonceError) {
|
|
8
|
+
return { ok: false };
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const dPoPNonce = response.origResponse.headers.get('DPoP-Nonce');
|
|
12
|
+
if (!dPoPNonce) {
|
|
13
|
+
throw new Error('Missing required DPoP-Nonce header.');
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
return { ok: true, dpopNonce: dPoPNonce };
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function shouldRetryResourceRequestWithDPoPNonce(response: OpenIDResponse<unknown, unknown>): RetryRequestWithDPoPNonce {
|
|
20
|
+
if (!response.errorBody || response.origResponse.status !== 401) {
|
|
21
|
+
return { ok: false };
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const wwwAuthenticateHeader = response.origResponse.headers.get('WWW-Authenticate');
|
|
25
|
+
if (!wwwAuthenticateHeader?.includes(dpopTokenRequestNonceError)) {
|
|
26
|
+
return { ok: false };
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const dPoPNonce = response.origResponse.headers.get('DPoP-Nonce');
|
|
30
|
+
if (!dPoPNonce) {
|
|
31
|
+
throw new Error('Missing required DPoP-Nonce header.');
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return { ok: true, dpopNonce: dPoPNonce };
|
|
35
|
+
}
|
|
@@ -19,12 +19,10 @@ export async function sendNotification(
|
|
|
19
19
|
const error = response.errorBody?.error !== undefined;
|
|
20
20
|
const result = {
|
|
21
21
|
error,
|
|
22
|
-
response: error ?
|
|
22
|
+
response: error ? response.errorBody : undefined,
|
|
23
23
|
};
|
|
24
24
|
if (error) {
|
|
25
|
-
LOG.warning(
|
|
26
|
-
`Notification endpoint returned an error for event '${request.event}' and id ${request.notification_id}: ${await response.errorBody?.json()}`,
|
|
27
|
-
);
|
|
25
|
+
LOG.warning(`Notification endpoint returned an error for event '${request.event}' and id ${request.notification_id}: ${response.errorBody}`);
|
|
28
26
|
} else {
|
|
29
27
|
LOG.debug(`Notification endpoint returned success for event '${request.event}' and id ${request.notification_id}`);
|
|
30
28
|
}
|
package/lib/index.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sphereon/oid4vci-client",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.16.0",
|
|
4
4
|
"description": "OpenID for Verifiable Credential Issuance (OpenID4VCI) client",
|
|
5
5
|
"source": "lib/index.ts",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -15,7 +15,8 @@
|
|
|
15
15
|
"build": "tsc"
|
|
16
16
|
},
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@sphereon/
|
|
18
|
+
"@sphereon/oid4vc-common": "0.16.0",
|
|
19
|
+
"@sphereon/oid4vci-common": "0.16.0",
|
|
19
20
|
"@sphereon/ssi-types": "0.28.0",
|
|
20
21
|
"cross-fetch": "^3.1.8",
|
|
21
22
|
"debug": "^4.3.5"
|
|
@@ -69,5 +70,5 @@
|
|
|
69
70
|
"OIDC4VCI",
|
|
70
71
|
"OID4VCI"
|
|
71
72
|
],
|
|
72
|
-
"gitHead": "
|
|
73
|
+
"gitHead": "7d938320eba5818dfe2bf6ae5291bb3c614085e1"
|
|
73
74
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"IssuerSessionClient.d.ts","sourceRoot":"","sources":["../lib/IssuerSessionClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,0BAA0B,EAAE,qBAAqB,EAAwB,MAAM,0BAA0B,CAAC;AAInH,eAAO,MAAM,sBAAsB,SAAgB,0BAA0B,KAAG,OAAO,CAAC,qBAAqB,CAY5G,CAAA"}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.acquireIssuerSessionId = void 0;
|
|
13
|
-
const oid4vci_common_1 = require("@sphereon/oid4vci-common");
|
|
14
|
-
const index_1 = require("./index");
|
|
15
|
-
const acquireIssuerSessionId = (opts) => __awaiter(void 0, void 0, void 0, function* () {
|
|
16
|
-
index_1.LOG.debug(`acquiring issuer session endpoint from endpoint ${opts.sessionEndpoint}`);
|
|
17
|
-
const sessionResponse = yield (0, oid4vci_common_1.post)(opts.sessionEndpoint);
|
|
18
|
-
if (sessionResponse.errorBody !== undefined) {
|
|
19
|
-
return Promise.reject(`an error occurred while requesting a issuer session token from endpoint ${opts.sessionEndpoint}:
|
|
20
|
-
${sessionResponse.errorBody.error} - ${sessionResponse.errorBody.error_description}`);
|
|
21
|
-
}
|
|
22
|
-
if (sessionResponse.successBody === undefined || !Object.keys(sessionResponse.successBody).includes('session_id')) {
|
|
23
|
-
return Promise.reject(`an error occurred while requesting a issuer session token from endpoint ${opts.sessionEndpoint}, missing session_token response`);
|
|
24
|
-
}
|
|
25
|
-
return sessionResponse.successBody;
|
|
26
|
-
});
|
|
27
|
-
exports.acquireIssuerSessionId = acquireIssuerSessionId;
|
|
28
|
-
//# sourceMappingURL=IssuerSessionClient.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"IssuerSessionClient.js","sourceRoot":"","sources":["../lib/IssuerSessionClient.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,6DAAmH;AAEnH,mCAA8B;AAEvB,MAAM,sBAAsB,GAAG,CAAO,IAAgC,EAAkC,EAAE;IAC/G,WAAG,CAAC,KAAK,CAAC,mDAAmD,IAAI,CAAC,eAAe,EAAE,CAAC,CAAA;IACpF,MAAM,eAAe,GAAG,MAAM,IAAA,qBAAI,EAAC,IAAI,CAAC,eAAe,CAA0C,CAAA;IACjG,IAAI,eAAe,CAAC,SAAS,KAAK,SAAS,EAAE,CAAC;QAC5C,OAAO,OAAO,CAAC,MAAM,CAAC,2EAA2E,IAAI,CAAC,eAAe;OAClH,eAAe,CAAC,SAAS,CAAC,KAAK,MAAM,eAAe,CAAC,SAAS,CAAC,iBAAiB,EAAE,CAAC,CAAA;IACxF,CAAC;IACD,IAAI,eAAe,CAAC,WAAW,KAAK,SAAS,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,eAAe,CAAC,WAAW,CAAC,CAAC,QAAQ,CAAC,YAAY,CAAC,EAAE,CAAC;QAClH,OAAO,OAAO,CAAC,MAAM,CAAC,2EAA2E,IAAI,CAAC,eAAe,kCAAkC,CAAC,CAAA;IAE1J,CAAC;IACD,OAAO,eAAe,CAAC,WAAW,CAAA;AACpC,CAAC,CAAA,CAAA;AAZY,QAAA,sBAAsB,0BAYlC"}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { IssuerSessionIdRequestOpts, IssuerSessionResponse, OpenIDResponse, post } from '@sphereon/oid4vci-common';
|
|
2
|
-
|
|
3
|
-
import { LOG } from './index';
|
|
4
|
-
|
|
5
|
-
export const acquireIssuerSessionId = async (opts: IssuerSessionIdRequestOpts): Promise<IssuerSessionResponse> => {
|
|
6
|
-
LOG.debug(`acquiring issuer session endpoint from endpoint ${opts.sessionEndpoint}`)
|
|
7
|
-
const sessionResponse = await post(opts.sessionEndpoint) as OpenIDResponse<IssuerSessionResponse>
|
|
8
|
-
if (sessionResponse.errorBody !== undefined) {
|
|
9
|
-
return Promise.reject(`an error occurred while requesting a issuer session token from endpoint ${opts.sessionEndpoint}:
|
|
10
|
-
${sessionResponse.errorBody.error} - ${sessionResponse.errorBody.error_description}`)
|
|
11
|
-
}
|
|
12
|
-
if (sessionResponse.successBody === undefined || !Object.keys(sessionResponse.successBody).includes('session_id')) {
|
|
13
|
-
return Promise.reject(`an error occurred while requesting a issuer session token from endpoint ${opts.sessionEndpoint}, missing session_token response`)
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
return sessionResponse.successBody
|
|
17
|
-
}
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import { IssuerSessionIdRequestOpts } from '@sphereon/oid4vci-common';
|
|
2
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
3
|
-
// @ts-ignore
|
|
4
|
-
import nock from 'nock'
|
|
5
|
-
import { acquireIssuerSessionId } from '../IssuerSessionClient';
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
describe('IssuerSessionClient', () => {
|
|
9
|
-
describe('acquireIssuerSessionId', () => {
|
|
10
|
-
const mockSessionEndpoint = 'https://server.example.com/session_endpoint'
|
|
11
|
-
const mockSessionId = 'iOiJSUzI1NiIsInR'
|
|
12
|
-
|
|
13
|
-
beforeEach(() => {
|
|
14
|
-
nock.cleanAll()
|
|
15
|
-
})
|
|
16
|
-
|
|
17
|
-
it('should successfully acquire an issuer session ID', async () => {
|
|
18
|
-
const mockResponse = {
|
|
19
|
-
session_id: mockSessionId
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
nock('https://server.example.com')
|
|
23
|
-
.post('/session_endpoint')
|
|
24
|
-
.reply(200, mockResponse, { 'Content-Type': 'application/json' })
|
|
25
|
-
|
|
26
|
-
const opts: IssuerSessionIdRequestOpts = {
|
|
27
|
-
sessionEndpoint: mockSessionEndpoint
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
const result = await acquireIssuerSessionId(opts)
|
|
31
|
-
|
|
32
|
-
expect(result).toEqual(mockResponse)
|
|
33
|
-
})
|
|
34
|
-
|
|
35
|
-
it('should reject with an error if the response contains an error body', async () => {
|
|
36
|
-
const mockErrorResponse = {
|
|
37
|
-
error: 'invalid_request',
|
|
38
|
-
error_description: 'The request is missing a required parameter'
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
nock('https://server.example.com')
|
|
42
|
-
.post('/session_endpoint')
|
|
43
|
-
.reply(400, mockErrorResponse, { 'Content-Type': 'application/json' })
|
|
44
|
-
|
|
45
|
-
const opts: IssuerSessionIdRequestOpts = {
|
|
46
|
-
sessionEndpoint: mockSessionEndpoint
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
await expect(acquireIssuerSessionId(opts)).rejects.toMatch(/an error occurred while requesting a issuer session token/)
|
|
50
|
-
})
|
|
51
|
-
|
|
52
|
-
it('should reject with an error if the response is missing the session_token', async () => {
|
|
53
|
-
nock('https://server.example.com')
|
|
54
|
-
.post('/session_endpoint')
|
|
55
|
-
.reply(200, undefined, { 'Content-Type': 'application/json' })
|
|
56
|
-
|
|
57
|
-
const opts: IssuerSessionIdRequestOpts = {
|
|
58
|
-
sessionEndpoint: mockSessionEndpoint
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
await expect(acquireIssuerSessionId(opts)).rejects.toMatch(/an error occurred while requesting a issuer session token.*missing session_token response/)
|
|
62
|
-
})
|
|
63
|
-
})
|
|
64
|
-
})
|