@sphereon/ssi-sdk.ms-request-api 0.13.1-next.15 → 0.13.1-next.18
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/IssuerUtil.js +7 -6
- package/dist/IssuerUtil.js.map +1 -1
- package/dist/agent/MsRequestApi.d.ts +1 -0
- package/dist/agent/MsRequestApi.d.ts.map +1 -1
- package/dist/agent/MsRequestApi.js +18 -6
- package/dist/agent/MsRequestApi.js.map +1 -1
- package/dist/ssi-sdk.ms-request-api.d.ts +1 -0
- package/package.json +4 -4
- package/plugin.schema.json +1 -2
- package/src/IssuerUtil.ts +7 -7
- package/src/agent/MsRequestApi.ts +29 -8
package/dist/IssuerUtil.js
CHANGED
|
@@ -13,8 +13,8 @@ exports.generatePin = exports.fetchIssuanceRequestMs = void 0;
|
|
|
13
13
|
const cross_fetch_1 = require("cross-fetch");
|
|
14
14
|
function fetchIssuanceRequestMs(issuanceInfo, accessToken, msIdentityHostName) {
|
|
15
15
|
return __awaiter(this, void 0, void 0, function* () {
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
const requestEndpoint = `${msIdentityHostName}${issuanceInfo.authenticationInfo.azTenantId}/verifiablecredentials/request`;
|
|
17
|
+
const payload = JSON.stringify(issuanceInfo.issuanceConfig);
|
|
18
18
|
const fetchOptions = {
|
|
19
19
|
method: 'POST',
|
|
20
20
|
body: payload,
|
|
@@ -24,16 +24,17 @@ function fetchIssuanceRequestMs(issuanceInfo, accessToken, msIdentityHostName) {
|
|
|
24
24
|
Authorization: `Bearer ${accessToken}`,
|
|
25
25
|
},
|
|
26
26
|
};
|
|
27
|
-
const response = yield (0, cross_fetch_1.fetch)(
|
|
27
|
+
const response = yield (0, cross_fetch_1.fetch)(requestEndpoint, fetchOptions);
|
|
28
28
|
return yield response.json();
|
|
29
29
|
});
|
|
30
30
|
}
|
|
31
31
|
exports.fetchIssuanceRequestMs = fetchIssuanceRequestMs;
|
|
32
32
|
function generatePin(digits) {
|
|
33
|
-
|
|
33
|
+
const add = 1;
|
|
34
|
+
let max = 12 - add;
|
|
34
35
|
max = Math.pow(10, digits + add);
|
|
35
|
-
|
|
36
|
-
|
|
36
|
+
const min = max / 10; // Math.pow(10, n) basically
|
|
37
|
+
const number = Math.floor(Math.random() * (max - min + 1)) + min;
|
|
37
38
|
return ('' + number).substring(add);
|
|
38
39
|
}
|
|
39
40
|
exports.generatePin = generatePin;
|
package/dist/IssuerUtil.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IssuerUtil.js","sourceRoot":"","sources":["../src/IssuerUtil.ts"],"names":[],"mappings":";;;;;;;;;;;;AAEA,6CAAmC;AACnC,SAAsB,sBAAsB,CAC1C,YAA2B,EAC3B,WAAmB,EACnB,kBAA0B;;QAE1B,
|
|
1
|
+
{"version":3,"file":"IssuerUtil.js","sourceRoot":"","sources":["../src/IssuerUtil.ts"],"names":[],"mappings":";;;;;;;;;;;;AAEA,6CAAmC;AACnC,SAAsB,sBAAsB,CAC1C,YAA2B,EAC3B,WAAmB,EACnB,kBAA0B;;QAE1B,MAAM,eAAe,GAAG,GAAG,kBAAkB,GAAG,YAAY,CAAC,kBAAkB,CAAC,UAAU,gCAAgC,CAAA;QAE1H,MAAM,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,YAAY,CAAC,cAAc,CAAC,CAAA;QAC3D,MAAM,YAAY,GAAG;YACnB,MAAM,EAAE,MAAM;YACd,IAAI,EAAE,OAAO;YACb,OAAO,EAAE;gBACP,cAAc,EAAE,kBAAkB;gBAClC,gBAAgB,EAAE,OAAO,CAAC,MAAM,CAAC,QAAQ,EAAE;gBAC3C,aAAa,EAAE,UAAU,WAAW,EAAE;aACvC;SACF,CAAA;QACD,MAAM,QAAQ,GAAG,MAAM,IAAA,mBAAK,EAAC,eAAe,EAAE,YAAY,CAAC,CAAA;QAC3D,OAAO,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAA;IAC9B,CAAC;CAAA;AAnBD,wDAmBC;AAED,SAAgB,WAAW,CAAC,MAAc;IACxC,MAAM,GAAG,GAAG,CAAC,CAAA;IACb,IAAI,GAAG,GAAG,EAAE,GAAG,GAAG,CAAA;IAClB,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,MAAM,GAAG,GAAG,CAAC,CAAA;IAChC,MAAM,GAAG,GAAG,GAAG,GAAG,EAAE,CAAA,CAAC,4BAA4B;IACjD,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,GAAG,GAAG,GAAG,CAAC,CAAC,CAAC,GAAG,GAAG,CAAA;IAChE,OAAO,CAAC,EAAE,GAAG,MAAM,CAAC,CAAC,SAAS,CAAC,GAAG,CAAC,CAAA;AACrC,CAAC;AAPD,kCAOC"}
|
|
@@ -4,6 +4,7 @@ import { IMsRequestApi } from '../types/IMsRequestApi';
|
|
|
4
4
|
* {@inheritDoc IMsRequestApi}
|
|
5
5
|
*/
|
|
6
6
|
export declare class MsRequestApi implements IAgentPlugin {
|
|
7
|
+
private clients;
|
|
7
8
|
readonly methods: IMsRequestApi;
|
|
8
9
|
/** {@inheritDoc IMsRequestApi.issuanceRequestMsVc} */
|
|
9
10
|
private issuanceRequestMsVc;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MsRequestApi.d.ts","sourceRoot":"","sources":["../../src/agent/MsRequestApi.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"MsRequestApi.d.ts","sourceRoot":"","sources":["../../src/agent/MsRequestApi.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AAE3C,OAAO,EAIL,aAAa,EAId,MAAM,wBAAwB,CAAA;AAE/B;;GAEG;AACH,qBAAa,YAAa,YAAW,YAAY;IAC/C,OAAO,CAAC,OAAO,CAA2F;IAE1G,QAAQ,CAAC,OAAO,EAAE,aAAa,CAE9B;IAED,sDAAsD;YACxC,mBAAmB;CA0DlC"}
|
|
@@ -17,6 +17,7 @@ const IssuerUtil_1 = require("../IssuerUtil");
|
|
|
17
17
|
*/
|
|
18
18
|
class MsRequestApi {
|
|
19
19
|
constructor() {
|
|
20
|
+
this.clients = new Map();
|
|
20
21
|
this.methods = {
|
|
21
22
|
issuanceRequestMsVc: this.issuanceRequestMsVc.bind(this),
|
|
22
23
|
};
|
|
@@ -24,8 +25,19 @@ class MsRequestApi {
|
|
|
24
25
|
/** {@inheritDoc IMsRequestApi.issuanceRequestMsVc} */
|
|
25
26
|
issuanceRequestMsVc(clientIssueRequest, context) {
|
|
26
27
|
return __awaiter(this, void 0, void 0, function* () {
|
|
27
|
-
|
|
28
|
-
|
|
28
|
+
const id = (0, ssi_sdk_ms_authenticator_1.determineMSAuthId)(clientIssueRequest.authenticationInfo);
|
|
29
|
+
if (!this.clients.has(id)) {
|
|
30
|
+
this.clients.set(id, yield (0, ssi_sdk_ms_authenticator_1.newMSClientCredentialAuthenticator)(clientIssueRequest.authenticationInfo));
|
|
31
|
+
}
|
|
32
|
+
const clientInfo = this.clients.get(id);
|
|
33
|
+
if (!clientInfo) {
|
|
34
|
+
throw Error(`Could not get client from arguments for id: ${id}`);
|
|
35
|
+
}
|
|
36
|
+
const authResult = yield (0, ssi_sdk_ms_authenticator_1.getMSClientCredentialAccessToken)(clientIssueRequest.authenticationInfo, {
|
|
37
|
+
confidentialClient: clientInfo.confidentialClient,
|
|
38
|
+
});
|
|
39
|
+
const accessToken = authResult.accessToken;
|
|
40
|
+
const msIdentityHostName = yield (0, ssi_sdk_ms_authenticator_1.assertEntraCredentialManifestUrlInCorrectRegion)(clientIssueRequest.authenticationInfo);
|
|
29
41
|
// Config Request and App Config File should be a parameter to this function
|
|
30
42
|
if (!clientIssueRequest.authenticationInfo.azTenantId) {
|
|
31
43
|
throw new Error('azTenantId is missing.');
|
|
@@ -35,24 +47,24 @@ class MsRequestApi {
|
|
|
35
47
|
if (clientIssueRequest.clientIssuanceConfig.issuance.pin) {
|
|
36
48
|
clientIssueRequest.clientIssuanceConfig.issuance.pin.value = (0, IssuerUtil_1.generatePin)(clientIssueRequest.clientIssuanceConfig.issuance.pin.length);
|
|
37
49
|
}
|
|
38
|
-
|
|
50
|
+
const issuance = {
|
|
39
51
|
type: clientIssueRequest.clientIssuanceConfig.issuance.type,
|
|
40
52
|
manifest: clientIssueRequest.clientIssuanceConfig.issuance.manifest,
|
|
41
53
|
pin: clientIssueRequest.clientIssuanceConfig.issuance.pin,
|
|
42
54
|
claims: clientIssueRequest.claims,
|
|
43
55
|
};
|
|
44
|
-
|
|
56
|
+
const issuanceConfig = {
|
|
45
57
|
authority: clientIssueRequest.clientIssuanceConfig.authority,
|
|
46
58
|
includeQRCode: clientIssueRequest.clientIssuanceConfig.includeQRCode,
|
|
47
59
|
registration: clientIssueRequest.clientIssuanceConfig.registration,
|
|
48
60
|
callback: clientIssueRequest.clientIssuanceConfig.callback,
|
|
49
61
|
issuance: issuance,
|
|
50
62
|
};
|
|
51
|
-
|
|
63
|
+
const issueRequest = {
|
|
52
64
|
authenticationInfo: clientIssueRequest.authenticationInfo,
|
|
53
65
|
issuanceConfig: issuanceConfig,
|
|
54
66
|
};
|
|
55
|
-
|
|
67
|
+
const resp = yield (0, IssuerUtil_1.fetchIssuanceRequestMs)(issueRequest, accessToken, msIdentityHostName);
|
|
56
68
|
// the response from the VC Request API call is returned to the caller (the UI). It contains the URI to the request which Authenticator can download after
|
|
57
69
|
// it has scanned the QR code. If the payload requested the VC Request service to create the QR code that is returned as well
|
|
58
70
|
// the javascript in the UI will use that QR code to display it on the screen to the user.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MsRequestApi.js","sourceRoot":"","sources":["../../src/agent/MsRequestApi.ts"],"names":[],"mappings":";;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"MsRequestApi.js","sourceRoot":"","sources":["../../src/agent/MsRequestApi.ts"],"names":[],"mappings":";;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GAAG,CAAC,KAAK,CAAA,CAAC,yCAAyC;aACpG;YACD,OAAO,IAAI,CAAA;QACb,CAAC;KAAA;CAEF;AAlED,oCAkEC"}
|
|
@@ -80,6 +80,7 @@ export declare interface IssuanceConfig {
|
|
|
80
80
|
* {@inheritDoc IMsRequestApi}
|
|
81
81
|
*/
|
|
82
82
|
export declare class MsRequestApi implements IAgentPlugin {
|
|
83
|
+
private clients;
|
|
83
84
|
readonly methods: IMsRequestApi;
|
|
84
85
|
/** {@inheritDoc IMsRequestApi.issuanceRequestMsVc} */
|
|
85
86
|
private issuanceRequestMsVc;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sphereon/ssi-sdk.ms-request-api",
|
|
3
|
-
"version": "0.13.1-next.
|
|
3
|
+
"version": "0.13.1-next.18+61bdfaf",
|
|
4
4
|
"source": "src/index.ts",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"generate-plugin-schema": "ts-node ../../packages/dev/bin/sphereon.js dev generate-plugin-schema"
|
|
16
16
|
},
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@sphereon/ssi-sdk.ms-authenticator": "0.13.1-next.
|
|
18
|
+
"@sphereon/ssi-sdk.ms-authenticator": "0.13.1-next.18+61bdfaf",
|
|
19
19
|
"@veramo/remote-client": "4.2.0",
|
|
20
20
|
"@veramo/remote-server": "4.2.0",
|
|
21
21
|
"cross-fetch": "^3.1.5",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"typeorm": "^0.3.12"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
|
-
"@sphereon/ssi-sdk.agent-config": "0.13.1-next.
|
|
27
|
+
"@sphereon/ssi-sdk.agent-config": "0.13.1-next.18+61bdfaf",
|
|
28
28
|
"@types/express": "^4.17.17",
|
|
29
29
|
"@types/express-session": "^1.17.4",
|
|
30
30
|
"@types/jest": "^27.5.2",
|
|
@@ -65,5 +65,5 @@
|
|
|
65
65
|
"API",
|
|
66
66
|
"Issuer"
|
|
67
67
|
],
|
|
68
|
-
"gitHead": "
|
|
68
|
+
"gitHead": "61bdfaf202ee8e5fc6f1e9b83138298798a7a440"
|
|
69
69
|
}
|
package/plugin.schema.json
CHANGED
|
@@ -61,8 +61,7 @@
|
|
|
61
61
|
"required": [
|
|
62
62
|
"azClientId",
|
|
63
63
|
"azTenantId",
|
|
64
|
-
"azClientSecret"
|
|
65
|
-
"credentialManifestUrl"
|
|
64
|
+
"azClientSecret"
|
|
66
65
|
],
|
|
67
66
|
"description": "azClientId: clientId of the application you're trying to login azClientSecret: secret of the application you're trying to login azTenantId: your MS Azure tenantId credentialManifestUrl: url of your credential manifest. usually in following format: https://beta.eu.did.msidentity.com/v1.0/<tenant_id>/verifiableCredential/contracts/<verifiable_credential_schema> authority: optional. if not provided, we'll use the azClientId to create the Tenanted format if provided should be one of these two formats: - Tenanted: https://login.microsoftonline.com/{tenant}/, where {tenant} is either the GUID representing the tenant ID or a domain name associated with the tenant. - Work and school accounts: https://login.microsoftonline.com/organizations/. region?: if present will use the provided, if not will make a request to determine the region scopes?: scopes that you want to access via this authentication skipCache?: whether to skip cache piiLoggingEnabled?: if not provided defaults to false logLevel?: can be one of these values: Error = 0, Warning = 1, Info = 2, Verbose = 3, Trace = 4 if not provided defaults to LogLevel.Verbose"
|
|
68
67
|
},
|
package/src/IssuerUtil.ts
CHANGED
|
@@ -6,9 +6,9 @@ export async function fetchIssuanceRequestMs(
|
|
|
6
6
|
accessToken: string,
|
|
7
7
|
msIdentityHostName: string
|
|
8
8
|
): Promise<IIssueRequestResponse> {
|
|
9
|
-
|
|
9
|
+
const requestEndpoint = `${msIdentityHostName}${issuanceInfo.authenticationInfo.azTenantId}/verifiablecredentials/request`
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
const payload = JSON.stringify(issuanceInfo.issuanceConfig)
|
|
12
12
|
const fetchOptions = {
|
|
13
13
|
method: 'POST',
|
|
14
14
|
body: payload,
|
|
@@ -18,15 +18,15 @@ export async function fetchIssuanceRequestMs(
|
|
|
18
18
|
Authorization: `Bearer ${accessToken}`,
|
|
19
19
|
},
|
|
20
20
|
}
|
|
21
|
-
const response = await fetch(
|
|
21
|
+
const response = await fetch(requestEndpoint, fetchOptions)
|
|
22
22
|
return await response.json()
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
export function generatePin(digits: number) {
|
|
26
|
-
|
|
27
|
-
|
|
26
|
+
const add = 1
|
|
27
|
+
let max = 12 - add
|
|
28
28
|
max = Math.pow(10, digits + add)
|
|
29
|
-
|
|
30
|
-
|
|
29
|
+
const min = max / 10 // Math.pow(10, n) basically
|
|
30
|
+
const number = Math.floor(Math.random() * (max - min + 1)) + min
|
|
31
31
|
return ('' + number).substring(add)
|
|
32
32
|
}
|
|
@@ -1,4 +1,12 @@
|
|
|
1
|
+
import {
|
|
2
|
+
assertEntraCredentialManifestUrlInCorrectRegion,
|
|
3
|
+
IMSClientCredentialAuthInfo,
|
|
4
|
+
determineMSAuthId,
|
|
5
|
+
getMSClientCredentialAccessToken,
|
|
6
|
+
newMSClientCredentialAuthenticator,
|
|
7
|
+
} from '@sphereon/ssi-sdk.ms-authenticator'
|
|
1
8
|
import { IAgentPlugin } from '@veramo/core'
|
|
9
|
+
import { fetchIssuanceRequestMs, generatePin } from '../IssuerUtil'
|
|
2
10
|
import {
|
|
3
11
|
IClientIssueRequest,
|
|
4
12
|
IIssueRequest,
|
|
@@ -8,21 +16,33 @@ import {
|
|
|
8
16
|
Issuance,
|
|
9
17
|
IssuanceConfig,
|
|
10
18
|
} from '../types/IMsRequestApi'
|
|
11
|
-
|
|
12
|
-
import { generatePin, fetchIssuanceRequestMs } from '../IssuerUtil'
|
|
19
|
+
|
|
13
20
|
/**
|
|
14
21
|
* {@inheritDoc IMsRequestApi}
|
|
15
22
|
*/
|
|
16
23
|
export class MsRequestApi implements IAgentPlugin {
|
|
24
|
+
private clients: Map<string, IMSClientCredentialAuthInfo> = new Map<string, IMSClientCredentialAuthInfo>()
|
|
25
|
+
|
|
17
26
|
readonly methods: IMsRequestApi = {
|
|
18
27
|
issuanceRequestMsVc: this.issuanceRequestMsVc.bind(this),
|
|
19
28
|
}
|
|
20
29
|
|
|
21
30
|
/** {@inheritDoc IMsRequestApi.issuanceRequestMsVc} */
|
|
22
31
|
private async issuanceRequestMsVc(clientIssueRequest: IClientIssueRequest, context: IRequiredContext): Promise<IIssueRequestResponse> {
|
|
23
|
-
|
|
32
|
+
const id = determineMSAuthId(clientIssueRequest.authenticationInfo)
|
|
33
|
+
if (!this.clients.has(id)) {
|
|
34
|
+
this.clients.set(id, await newMSClientCredentialAuthenticator(clientIssueRequest.authenticationInfo))
|
|
35
|
+
}
|
|
36
|
+
const clientInfo = this.clients.get(id)
|
|
37
|
+
if (!clientInfo) {
|
|
38
|
+
throw Error(`Could not get client from arguments for id: ${id}`)
|
|
39
|
+
}
|
|
40
|
+
const authResult = await getMSClientCredentialAccessToken(clientIssueRequest.authenticationInfo, {
|
|
41
|
+
confidentialClient: clientInfo.confidentialClient,
|
|
42
|
+
})
|
|
43
|
+
const accessToken = authResult.accessToken
|
|
24
44
|
|
|
25
|
-
|
|
45
|
+
const msIdentityHostName = await assertEntraCredentialManifestUrlInCorrectRegion(clientIssueRequest.authenticationInfo)
|
|
26
46
|
|
|
27
47
|
// Config Request and App Config File should be a parameter to this function
|
|
28
48
|
if (!clientIssueRequest.authenticationInfo.azTenantId) {
|
|
@@ -35,26 +55,26 @@ export class MsRequestApi implements IAgentPlugin {
|
|
|
35
55
|
clientIssueRequest.clientIssuanceConfig.issuance.pin.value = generatePin(clientIssueRequest.clientIssuanceConfig.issuance.pin.length)
|
|
36
56
|
}
|
|
37
57
|
|
|
38
|
-
|
|
58
|
+
const issuance: Issuance = {
|
|
39
59
|
type: clientIssueRequest.clientIssuanceConfig.issuance.type,
|
|
40
60
|
manifest: clientIssueRequest.clientIssuanceConfig.issuance.manifest,
|
|
41
61
|
pin: clientIssueRequest.clientIssuanceConfig.issuance.pin,
|
|
42
62
|
claims: clientIssueRequest.claims,
|
|
43
63
|
}
|
|
44
64
|
|
|
45
|
-
|
|
65
|
+
const issuanceConfig: IssuanceConfig = {
|
|
46
66
|
authority: clientIssueRequest.clientIssuanceConfig.authority,
|
|
47
67
|
includeQRCode: clientIssueRequest.clientIssuanceConfig.includeQRCode,
|
|
48
68
|
registration: clientIssueRequest.clientIssuanceConfig.registration,
|
|
49
69
|
callback: clientIssueRequest.clientIssuanceConfig.callback,
|
|
50
70
|
issuance: issuance,
|
|
51
71
|
}
|
|
52
|
-
|
|
72
|
+
const issueRequest: IIssueRequest = {
|
|
53
73
|
authenticationInfo: clientIssueRequest.authenticationInfo,
|
|
54
74
|
issuanceConfig: issuanceConfig,
|
|
55
75
|
}
|
|
56
76
|
|
|
57
|
-
|
|
77
|
+
const resp = await fetchIssuanceRequestMs(issueRequest, accessToken, msIdentityHostName)
|
|
58
78
|
|
|
59
79
|
// the response from the VC Request API call is returned to the caller (the UI). It contains the URI to the request which Authenticator can download after
|
|
60
80
|
// it has scanned the QR code. If the payload requested the VC Request service to create the QR code that is returned as well
|
|
@@ -65,4 +85,5 @@ export class MsRequestApi implements IAgentPlugin {
|
|
|
65
85
|
}
|
|
66
86
|
return resp
|
|
67
87
|
}
|
|
88
|
+
|
|
68
89
|
}
|