@axinom/mosaic-id-link-be 0.13.4-rc.24 → 0.13.4-rc.25
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/dev/dev-create-service-account.d.ts.map +1 -1
- package/dist/dev/dev-create-service-account.js +23 -35
- package/dist/dev/dev-create-service-account.js.map +1 -1
- package/dist/long-lived-token/index.d.ts.map +1 -1
- package/dist/long-lived-token/index.js +26 -38
- package/dist/long-lived-token/index.js.map +1 -1
- package/dist/service-account-token/index.d.ts.map +1 -1
- package/dist/service-account-token/index.js +82 -110
- package/dist/service-account-token/index.js.map +1 -1
- package/dist/well-known-endpoints/index.d.ts.map +1 -1
- package/dist/well-known-endpoints/index.js +3 -38
- package/dist/well-known-endpoints/index.js.map +1 -1
- package/package.json +5 -5
- package/src/dev/dev-create-service-account.ts +33 -49
- package/src/long-lived-token/index.ts +38 -54
- package/src/service-account-token/index.ts +120 -147
- package/src/well-known-endpoints/index.ts +3 -35
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dev-create-service-account.d.ts","sourceRoot":"","sources":["../../src/dev/dev-create-service-account.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"dev-create-service-account.d.ts","sourceRoot":"","sources":["../../src/dev/dev-create-service-account.ts"],"names":[],"mappings":"AAQA,8CAA8C;AAC9C,MAAM,WAAW,iBAAiB;IAChC,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;IACrB,kBAAkB,EAAE,MAAM,CAAC;CAC5B;AAED;;;;;;GAMG;AACH,eAAO,MAAM,uBAAuB,iBACpB,MAAM,aACT,MAAM,sBACG,MAAM,YAChB,MAAM,iBACD,MAAM;eAER,MAAM;;QAGlB,QAAQ,iBAAiB,CAwC3B,CAAC"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.devCreateServiceAccount = void 0;
|
|
4
|
-
const mosaic_service_common_1 = require("@axinom/mosaic-service-common");
|
|
5
4
|
const gql_client_1 = require("../common/gql-client");
|
|
6
5
|
const graphql_types_1 = require("../generated/graphql.types");
|
|
7
6
|
const well_known_endpoints_1 = require("../well-known-endpoints");
|
|
@@ -13,43 +12,32 @@ const well_known_endpoints_1 = require("../well-known-endpoints");
|
|
|
13
12
|
* @returns {DevServiceAccount} New development service account information.
|
|
14
13
|
*/
|
|
15
14
|
const devCreateServiceAccount = async (authEndpoint, serviceId, serviceAccountName, tenantId, environmentId, permissions) => {
|
|
16
|
-
var _a
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
environmentId: environmentId,
|
|
27
|
-
permissionStructure: permissions,
|
|
28
|
-
},
|
|
15
|
+
var _a;
|
|
16
|
+
const client = (0, gql_client_1.getGqlClient)((await (0, well_known_endpoints_1.getWellKnownEndpoints)(authEndpoint)).authGraphQlEndpoint, 'Bearer token-not-needed-for-DEV-endpoints');
|
|
17
|
+
const result = await client.mutate({
|
|
18
|
+
mutation: graphql_types_1.DevCreateServiceAccountDocument,
|
|
19
|
+
variables: {
|
|
20
|
+
input: {
|
|
21
|
+
serviceAccountName,
|
|
22
|
+
tenantId,
|
|
23
|
+
environmentId: environmentId,
|
|
24
|
+
permissionStructure: permissions,
|
|
29
25
|
},
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
throw new Error(`Unexpected null or undefined value received for '_DEV_createServiceAccount' result.`);
|
|
38
|
-
}
|
|
39
|
-
else {
|
|
40
|
-
const aggregatedErrorMessage = (_b = result.errors) === null || _b === void 0 ? void 0 : _b.reduce((aggregatedError, gqlError) => {
|
|
41
|
-
return (aggregatedError += gqlError.message);
|
|
42
|
-
}, '');
|
|
43
|
-
throw new Error(aggregatedErrorMessage);
|
|
26
|
+
},
|
|
27
|
+
errorPolicy: 'all',
|
|
28
|
+
fetchPolicy: 'no-cache',
|
|
29
|
+
});
|
|
30
|
+
if (!result.errors) {
|
|
31
|
+
if ((_a = result.data) === null || _a === void 0 ? void 0 : _a._DEV_createServiceAccount) {
|
|
32
|
+
return result.data._DEV_createServiceAccount;
|
|
44
33
|
}
|
|
34
|
+
throw new Error(`Unexpected null or undefined value received for '_DEV_createServiceAccount' result.`);
|
|
45
35
|
}
|
|
46
|
-
|
|
47
|
-
(
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
});
|
|
52
|
-
throw error;
|
|
36
|
+
else {
|
|
37
|
+
const aggregatedErrorMessage = result.errors.reduce((aggregatedError, gqlError) => {
|
|
38
|
+
return (aggregatedError += gqlError.message);
|
|
39
|
+
}, '');
|
|
40
|
+
throw new Error(aggregatedErrorMessage);
|
|
53
41
|
}
|
|
54
42
|
};
|
|
55
43
|
exports.devCreateServiceAccount = devCreateServiceAccount;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dev-create-service-account.js","sourceRoot":"","sources":["../../src/dev/dev-create-service-account.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"dev-create-service-account.js","sourceRoot":"","sources":["../../src/dev/dev-create-service-account.ts"],"names":[],"mappings":";;;AAAA,qDAAoD;AACpD,8DAIoC;AACpC,kEAAgE;AAShE;;;;;;GAMG;AACI,MAAM,uBAAuB,GAAG,KAAK,EAC1C,YAAoB,EACpB,SAAiB,EACjB,kBAA0B,EAC1B,QAAgB,EAChB,aAAqB,EACrB,WAGG,EACyB,EAAE;;IAC9B,MAAM,MAAM,GAAG,IAAA,yBAAY,EACzB,CAAC,MAAM,IAAA,4CAAqB,EAAC,YAAY,CAAC,CAAC,CAAC,mBAAmB,EAC/D,2CAA2C,CAC5C,CAAC;IAEF,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,MAAM,CAGhC;QACA,QAAQ,EAAE,+CAA+B;QACzC,SAAS,EAAE;YACT,KAAK,EAAE;gBACL,kBAAkB;gBAClB,QAAQ;gBACR,aAAa,EAAE,aAAa;gBAC5B,mBAAmB,EAAE,WAAW;aACjC;SACF;QACD,WAAW,EAAE,KAAK;QAClB,WAAW,EAAE,UAAU;KACxB,CAAC,CAAC;IAEH,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE;QAClB,IAAI,MAAA,MAAM,CAAC,IAAI,0CAAE,yBAAyB,EAAE;YAC1C,OAAO,MAAM,CAAC,IAAI,CAAC,yBAAyB,CAAC;SAC9C;QACD,MAAM,IAAI,KAAK,CACb,qFAAqF,CACtF,CAAC;KACH;SAAM;QACL,MAAM,sBAAsB,GAAG,MAAM,CAAC,MAAM,CAAC,MAAM,CACjD,CAAC,eAAe,EAAE,QAAQ,EAAE,EAAE;YAC5B,OAAO,CAAC,eAAe,IAAI,QAAQ,CAAC,OAAO,CAAC,CAAC;QAC/C,CAAC,EACD,EAAE,CACH,CAAC;QAEF,MAAM,IAAI,KAAK,CAAC,sBAAsB,CAAC,CAAC;KACzC;AACH,CAAC,CAAC;AAlDW,QAAA,uBAAuB,2BAkDlC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/long-lived-token/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/long-lived-token/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAStD;;;;;;;GAOG;AACH,eAAO,MAAM,sBAAsB,iBACnB,MAAM,uBACC,MAAM,mBACV,MAAM,8BACK,MAAM,KACjC,QAAQ,WAAW,CA8CrB,CAAC"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.generateLongLivedToken = void 0;
|
|
4
|
-
const mosaic_service_common_1 = require("@axinom/mosaic-service-common");
|
|
5
4
|
const gql_client_1 = require("../common/gql-client");
|
|
6
5
|
const graphql_types_1 = require("../generated/graphql.types");
|
|
7
6
|
const well_known_endpoints_1 = require("../well-known-endpoints");
|
|
@@ -14,46 +13,35 @@ const well_known_endpoints_1 = require("../well-known-endpoints");
|
|
|
14
13
|
* @returns {TokenResult} Long lived access token.
|
|
15
14
|
*/
|
|
16
15
|
const generateLongLivedToken = async (authEndpoint, serviceAccountToken, userAccessToken, validityDurationInSeconds) => {
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
userToken: userAccessToken,
|
|
25
|
-
validityDurationInSeconds,
|
|
26
|
-
},
|
|
16
|
+
const client = (0, gql_client_1.getGqlClient)((await (0, well_known_endpoints_1.getWellKnownEndpoints)(authEndpoint)).authGraphQlEndpoint, serviceAccountToken);
|
|
17
|
+
const result = await client.mutate({
|
|
18
|
+
mutation: graphql_types_1.GenerateLongLivedTokenDocument,
|
|
19
|
+
variables: {
|
|
20
|
+
input: {
|
|
21
|
+
userToken: userAccessToken,
|
|
22
|
+
validityDurationInSeconds,
|
|
27
23
|
},
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
const tokenResponse = result.data.generateLongLivedToken;
|
|
36
|
-
const longLivedToken = {
|
|
37
|
-
accessToken: tokenResponse.accessToken,
|
|
38
|
-
tokenType: tokenResponse.tokenType,
|
|
39
|
-
expiresInSeconds: tokenResponse.expiresInSeconds,
|
|
40
|
-
};
|
|
41
|
-
return longLivedToken;
|
|
42
|
-
}
|
|
43
|
-
else {
|
|
44
|
-
const aggregatedErrorMessage = result.errors.reduce((aggregatedError, gqlError) => {
|
|
45
|
-
return (aggregatedError += gqlError.message);
|
|
46
|
-
}, '');
|
|
47
|
-
throw new Error(aggregatedErrorMessage);
|
|
24
|
+
},
|
|
25
|
+
errorPolicy: 'all',
|
|
26
|
+
fetchPolicy: 'no-cache',
|
|
27
|
+
});
|
|
28
|
+
if (!result.errors) {
|
|
29
|
+
if (!result.data) {
|
|
30
|
+
throw new Error(`Unexpected null or undefined value received for 'generateLongLivedToken' result.`);
|
|
48
31
|
}
|
|
32
|
+
const tokenResponse = result.data.generateLongLivedToken;
|
|
33
|
+
const longLivedToken = {
|
|
34
|
+
accessToken: tokenResponse.accessToken,
|
|
35
|
+
tokenType: tokenResponse.tokenType,
|
|
36
|
+
expiresInSeconds: tokenResponse.expiresInSeconds,
|
|
37
|
+
};
|
|
38
|
+
return longLivedToken;
|
|
49
39
|
}
|
|
50
|
-
|
|
51
|
-
(
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
});
|
|
56
|
-
throw error;
|
|
40
|
+
else {
|
|
41
|
+
const aggregatedErrorMessage = result.errors.reduce((aggregatedError, gqlError) => {
|
|
42
|
+
return (aggregatedError += gqlError.message);
|
|
43
|
+
}, '');
|
|
44
|
+
throw new Error(aggregatedErrorMessage);
|
|
57
45
|
}
|
|
58
46
|
};
|
|
59
47
|
exports.generateLongLivedToken = generateLongLivedToken;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/long-lived-token/index.ts"],"names":[],"mappings":";;;AACA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/long-lived-token/index.ts"],"names":[],"mappings":";;;AACA,qDAAoD;AACpD,8DAIoC;AACpC,kEAAgE;AAEhE;;;;;;;GAOG;AACI,MAAM,sBAAsB,GAAG,KAAK,EACzC,YAAoB,EACpB,mBAA2B,EAC3B,eAAuB,EACvB,yBAAkC,EACZ,EAAE;IACxB,MAAM,MAAM,GAAG,IAAA,yBAAY,EACzB,CAAC,MAAM,IAAA,4CAAqB,EAAC,YAAY,CAAC,CAAC,CAAC,mBAAmB,EAC/D,mBAAmB,CACpB,CAAC;IAEF,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,MAAM,CAGhC;QACA,QAAQ,EAAE,8CAA8B;QACxC,SAAS,EAAE;YACT,KAAK,EAAE;gBACL,SAAS,EAAE,eAAe;gBAC1B,yBAAyB;aAC1B;SACF;QACD,WAAW,EAAE,KAAK;QAClB,WAAW,EAAE,UAAU;KACxB,CAAC,CAAC;IAEH,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE;QAClB,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE;YAChB,MAAM,IAAI,KAAK,CACb,kFAAkF,CACnF,CAAC;SACH;QACD,MAAM,aAAa,GAAG,MAAM,CAAC,IAAI,CAAC,sBAAsB,CAAC;QAEzD,MAAM,cAAc,GAAG;YACrB,WAAW,EAAE,aAAa,CAAC,WAAW;YACtC,SAAS,EAAE,aAAa,CAAC,SAAS;YAClC,gBAAgB,EAAE,aAAa,CAAC,gBAAgB;SACjD,CAAC;QAEF,OAAO,cAAc,CAAC;KACvB;SAAM;QACL,MAAM,sBAAsB,GAAG,MAAM,CAAC,MAAM,CAAC,MAAM,CACjD,CAAC,eAAe,EAAE,QAAQ,EAAE,EAAE;YAC5B,OAAO,CAAC,eAAe,IAAI,QAAQ,CAAC,OAAO,CAAC,CAAC;QAC/C,CAAC,EACD,EAAE,CACH,CAAC;QAEF,MAAM,IAAI,KAAK,CAAC,sBAAsB,CAAC,CAAC;KACzC;AACH,CAAC,CAAC;AAnDW,QAAA,sBAAsB,0BAmDjC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/service-account-token/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/service-account-token/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAiBtD;;;;;;GAMG;AACH,eAAO,MAAM,sBAAsB,iBACnB,MAAM,YACV,MAAM,gBACF,MAAM,KACnB,QAAQ,WAAW,CA2CrB,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,6BAA6B,iBAC1B,MAAM,YACV,MAAM,gBACF,MAAM,mBACH,MAAM,wBACD,MAAM,KAC3B,QAAQ,WAAW,CA4CrB,CAAC;AAEF;;;;;;;;;;GAUG;AACH,eAAO,MAAM,mCAAmC,iBAChC,MAAM,YACV,MAAM,gBACF,MAAM,iBACL,MAAM,KACpB,QAAQ,WAAW,CA4CrB,CAAC"}
|
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getScopedManagedServiceAccountToken = exports.getManagedServiceAccountToken = exports.getServiceAccountToken = void 0;
|
|
4
|
-
const mosaic_service_common_1 = require("@axinom/mosaic-service-common");
|
|
5
4
|
const gql_client_1 = require("../common/gql-client");
|
|
6
5
|
const graphql_types_1 = require("../generated/graphql.types");
|
|
7
|
-
|
|
8
|
-
// TODO: Once we merge authenticateServiceAccount & authenticateManagedServiceAccount mutaitons,
|
|
6
|
+
// TODO: Once we merge authenticateServiceAccount & authenticateManagedServiceAccount mutations,
|
|
9
7
|
// these functions can also be merged into one.
|
|
10
8
|
/**
|
|
11
9
|
* This function authenticates a service account.
|
|
@@ -15,44 +13,34 @@ const logger = new mosaic_service_common_1.Logger({ context: 'get-service-accoun
|
|
|
15
13
|
* @returns {TokenResult} AccessToken for the service account.
|
|
16
14
|
*/
|
|
17
15
|
const getServiceAccountToken = async (authEndpoint, clientId, clientSecret) => {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
if (!result.
|
|
31
|
-
|
|
32
|
-
throw new Error(`Unexpected null or undefined value received for 'getServiceAccountToken' result.`);
|
|
33
|
-
}
|
|
34
|
-
const tokenResponse = result.data.authenticateServiceAccount;
|
|
35
|
-
serviceAccountAccessToken = {
|
|
36
|
-
accessToken: tokenResponse.accessToken,
|
|
37
|
-
tokenType: tokenResponse.tokenType,
|
|
38
|
-
expiresInSeconds: tokenResponse.expiresInSeconds,
|
|
39
|
-
};
|
|
40
|
-
return serviceAccountAccessToken;
|
|
41
|
-
}
|
|
42
|
-
else {
|
|
43
|
-
const aggregatedErrorMessage = result.errors.reduce((aggregatedError, gqlError) => {
|
|
44
|
-
return (aggregatedError += gqlError.message);
|
|
45
|
-
}, '');
|
|
46
|
-
throw new Error(aggregatedErrorMessage);
|
|
16
|
+
const client = (0, gql_client_1.getGqlClient)(new URL(`/graphql`, authEndpoint).href);
|
|
17
|
+
let serviceAccountAccessToken;
|
|
18
|
+
const result = await client.mutate({
|
|
19
|
+
mutation: graphql_types_1.GetServiceTokenDocument,
|
|
20
|
+
variables: {
|
|
21
|
+
clientId: clientId,
|
|
22
|
+
clientSecret: clientSecret,
|
|
23
|
+
},
|
|
24
|
+
errorPolicy: 'all',
|
|
25
|
+
fetchPolicy: 'no-cache',
|
|
26
|
+
});
|
|
27
|
+
if (!result.errors) {
|
|
28
|
+
if (!result.data) {
|
|
29
|
+
throw new Error(`Unexpected null or undefined value received for 'getServiceAccountToken' result.`);
|
|
47
30
|
}
|
|
31
|
+
const tokenResponse = result.data.authenticateServiceAccount;
|
|
32
|
+
serviceAccountAccessToken = {
|
|
33
|
+
accessToken: tokenResponse.accessToken,
|
|
34
|
+
tokenType: tokenResponse.tokenType,
|
|
35
|
+
expiresInSeconds: tokenResponse.expiresInSeconds,
|
|
36
|
+
};
|
|
37
|
+
return serviceAccountAccessToken;
|
|
48
38
|
}
|
|
49
|
-
|
|
50
|
-
(
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
});
|
|
55
|
-
throw error;
|
|
39
|
+
else {
|
|
40
|
+
const aggregatedErrorMessage = result.errors.reduce((aggregatedError, gqlError) => {
|
|
41
|
+
return (aggregatedError += gqlError.message);
|
|
42
|
+
}, '');
|
|
43
|
+
throw new Error(aggregatedErrorMessage);
|
|
56
44
|
}
|
|
57
45
|
};
|
|
58
46
|
exports.getServiceAccountToken = getServiceAccountToken;
|
|
@@ -66,44 +54,36 @@ exports.getServiceAccountToken = getServiceAccountToken;
|
|
|
66
54
|
* @returns {TokenResult} AccessToken for the managed service account.
|
|
67
55
|
*/
|
|
68
56
|
const getManagedServiceAccountToken = async (authEndpoint, clientId, clientSecret, targetTenantId, targetEnvironmentId) => {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
const tokenResponse = result.data.authenticateManagedServiceAccount;
|
|
86
|
-
serviceAccountAccessToken = {
|
|
87
|
-
accessToken: tokenResponse.accessToken,
|
|
88
|
-
tokenType: tokenResponse.tokenType,
|
|
89
|
-
expiresInSeconds: tokenResponse.expiresInSeconds,
|
|
90
|
-
};
|
|
91
|
-
return serviceAccountAccessToken;
|
|
92
|
-
}
|
|
93
|
-
else {
|
|
94
|
-
const aggregatedErrorMessage = (_a = result.errors) === null || _a === void 0 ? void 0 : _a.reduce((aggregatedError, gqlError) => {
|
|
95
|
-
return (aggregatedError += gqlError.message);
|
|
96
|
-
}, '');
|
|
97
|
-
throw new Error(aggregatedErrorMessage);
|
|
57
|
+
const client = (0, gql_client_1.getGqlClient)(new URL(`/graphql`, authEndpoint).href);
|
|
58
|
+
let serviceAccountAccessToken;
|
|
59
|
+
const result = await client.mutate({
|
|
60
|
+
mutation: graphql_types_1.GetManagedServiceTokenDocument,
|
|
61
|
+
variables: {
|
|
62
|
+
clientId: clientId,
|
|
63
|
+
clientSecret: clientSecret,
|
|
64
|
+
targetTenantId,
|
|
65
|
+
targetEnvironmentId: targetEnvironmentId,
|
|
66
|
+
},
|
|
67
|
+
errorPolicy: 'all',
|
|
68
|
+
fetchPolicy: 'no-cache',
|
|
69
|
+
});
|
|
70
|
+
if (!result.errors) {
|
|
71
|
+
if (!result.data) {
|
|
72
|
+
throw new Error(`Unexpected null or undefined value received for 'getManagedServiceAccountToken' result.`);
|
|
98
73
|
}
|
|
74
|
+
const tokenResponse = result.data.authenticateManagedServiceAccount;
|
|
75
|
+
serviceAccountAccessToken = {
|
|
76
|
+
accessToken: tokenResponse.accessToken,
|
|
77
|
+
tokenType: tokenResponse.tokenType,
|
|
78
|
+
expiresInSeconds: tokenResponse.expiresInSeconds,
|
|
79
|
+
};
|
|
80
|
+
return serviceAccountAccessToken;
|
|
99
81
|
}
|
|
100
|
-
|
|
101
|
-
(
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
});
|
|
106
|
-
throw error;
|
|
82
|
+
else {
|
|
83
|
+
const aggregatedErrorMessage = result.errors.reduce((aggregatedError, gqlError) => {
|
|
84
|
+
return (aggregatedError += gqlError.message);
|
|
85
|
+
}, '');
|
|
86
|
+
throw new Error(aggregatedErrorMessage);
|
|
107
87
|
}
|
|
108
88
|
};
|
|
109
89
|
exports.getManagedServiceAccountToken = getManagedServiceAccountToken;
|
|
@@ -119,43 +99,35 @@ exports.getManagedServiceAccountToken = getManagedServiceAccountToken;
|
|
|
119
99
|
* @returns
|
|
120
100
|
*/
|
|
121
101
|
const getScopedManagedServiceAccountToken = async (authEndpoint, clientId, clientSecret, managementJWT) => {
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
const tokenResponse = result.data.authenticateManagedServiceAccountWithEnvironmentScope;
|
|
138
|
-
serviceAccountAccessToken = {
|
|
139
|
-
accessToken: tokenResponse.accessToken,
|
|
140
|
-
tokenType: tokenResponse.tokenType,
|
|
141
|
-
expiresInSeconds: tokenResponse.expiresInSeconds,
|
|
142
|
-
};
|
|
143
|
-
return serviceAccountAccessToken;
|
|
144
|
-
}
|
|
145
|
-
else {
|
|
146
|
-
const aggregatedErrorMessage = (_a = result.errors) === null || _a === void 0 ? void 0 : _a.reduce((aggregatedError, gqlError) => {
|
|
147
|
-
return (aggregatedError += gqlError.message);
|
|
148
|
-
}, '');
|
|
149
|
-
throw new Error(aggregatedErrorMessage);
|
|
102
|
+
const client = (0, gql_client_1.getGqlClient)(new URL(`/graphql`, authEndpoint).href);
|
|
103
|
+
let serviceAccountAccessToken;
|
|
104
|
+
const result = await client.mutate({
|
|
105
|
+
mutation: graphql_types_1.GetManagedServiceTokenWithEnvironmentScopeDocument,
|
|
106
|
+
variables: {
|
|
107
|
+
clientId: clientId,
|
|
108
|
+
clientSecret: clientSecret,
|
|
109
|
+
managementJWT,
|
|
110
|
+
},
|
|
111
|
+
errorPolicy: 'all',
|
|
112
|
+
fetchPolicy: 'no-cache',
|
|
113
|
+
});
|
|
114
|
+
if (!result.errors) {
|
|
115
|
+
if (!result.data) {
|
|
116
|
+
throw new Error(`Unexpected null or undefined value received for 'getScopedManagedServiceAccountToken' result.`);
|
|
150
117
|
}
|
|
118
|
+
const tokenResponse = result.data.authenticateManagedServiceAccountWithEnvironmentScope;
|
|
119
|
+
serviceAccountAccessToken = {
|
|
120
|
+
accessToken: tokenResponse.accessToken,
|
|
121
|
+
tokenType: tokenResponse.tokenType,
|
|
122
|
+
expiresInSeconds: tokenResponse.expiresInSeconds,
|
|
123
|
+
};
|
|
124
|
+
return serviceAccountAccessToken;
|
|
151
125
|
}
|
|
152
|
-
|
|
153
|
-
(
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
});
|
|
158
|
-
throw error;
|
|
126
|
+
else {
|
|
127
|
+
const aggregatedErrorMessage = result.errors.reduce((aggregatedError, gqlError) => {
|
|
128
|
+
return (aggregatedError += gqlError.message);
|
|
129
|
+
}, '');
|
|
130
|
+
throw new Error(aggregatedErrorMessage);
|
|
159
131
|
}
|
|
160
132
|
};
|
|
161
133
|
exports.getScopedManagedServiceAccountToken = getScopedManagedServiceAccountToken;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/service-account-token/index.ts"],"names":[],"mappings":";;;AACA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/service-account-token/index.ts"],"names":[],"mappings":"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"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/well-known-endpoints/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/well-known-endpoints/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAErD;;;;GAIG;AACH,wBAAsB,qBAAqB,CACzC,YAAY,EAAE,MAAM,GACnB,OAAO,CAAC,kBAAkB,CAAC,CAO7B"}
|
|
@@ -4,52 +4,17 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.getWellKnownEndpoints = void 0;
|
|
7
|
-
const mosaic_service_common_1 = require("@axinom/mosaic-service-common");
|
|
8
7
|
const axios_1 = __importDefault(require("axios"));
|
|
9
|
-
const common_1 = require("../common");
|
|
10
8
|
/**
|
|
11
9
|
* This function returns the well known endpoints of id-service.
|
|
12
10
|
* @param authEndpoint URL for id-service authEndpoint.
|
|
13
11
|
* @returns {WellKnownEndpoints} Well known endpoints of id-service.
|
|
14
12
|
*/
|
|
15
13
|
async function getWellKnownEndpoints(authEndpoint) {
|
|
16
|
-
const logger = new mosaic_service_common_1.Logger({ context: getWellKnownEndpoints.name });
|
|
17
14
|
const wellKnownEndpointUrl = new URL(`/.well-known`, `${authEndpoint}`).href;
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
return result;
|
|
22
|
-
}
|
|
23
|
-
catch (error) {
|
|
24
|
-
const message = 'Error occurred while requesting /.well-known endpoint';
|
|
25
|
-
(0, common_1.assertAxiosError)(error);
|
|
26
|
-
if (error.response) {
|
|
27
|
-
// Received an error response (5xx, 4xx) from the server
|
|
28
|
-
logger.error({
|
|
29
|
-
message,
|
|
30
|
-
details: {
|
|
31
|
-
responseStatus: error.response.status,
|
|
32
|
-
responseData: error.response.data,
|
|
33
|
-
responseHeaders: error.response.headers,
|
|
34
|
-
stack: error.stack,
|
|
35
|
-
},
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
else if (error.request) {
|
|
39
|
-
// Did not receive a response, or request never left
|
|
40
|
-
logger.error({
|
|
41
|
-
message: `${message}. Did not receive a response from the server.`,
|
|
42
|
-
details: { requestPath: error.request.path, stack: error.stack },
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
else {
|
|
46
|
-
logger.error({
|
|
47
|
-
message,
|
|
48
|
-
details: { error: error.message, stack: error.stack },
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
throw new Error(message);
|
|
52
|
-
}
|
|
15
|
+
const result = (await axios_1.default.get(wellKnownEndpointUrl))
|
|
16
|
+
.data;
|
|
17
|
+
return result;
|
|
53
18
|
}
|
|
54
19
|
exports.getWellKnownEndpoints = getWellKnownEndpoints;
|
|
55
20
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/well-known-endpoints/index.ts"],"names":[],"mappings":";;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/well-known-endpoints/index.ts"],"names":[],"mappings":";;;;;;AAAA,kDAA0B;AAG1B;;;;GAIG;AACI,KAAK,UAAU,qBAAqB,CACzC,YAAoB;IAEpB,MAAM,oBAAoB,GAAG,IAAI,GAAG,CAAC,cAAc,EAAE,GAAG,YAAY,EAAE,CAAC,CAAC,IAAI,CAAC;IAE7E,MAAM,MAAM,GAAuB,CAAC,MAAM,eAAK,CAAC,GAAG,CAAC,oBAAoB,CAAC,CAAC;SACvE,IAAI,CAAC;IAER,OAAO,MAAM,CAAC;AAChB,CAAC;AATD,sDASC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@axinom/mosaic-id-link-be",
|
|
3
|
-
"version": "0.13.4-rc.
|
|
3
|
+
"version": "0.13.4-rc.25",
|
|
4
4
|
"description": "Integration utilities from id-service for Axinom Mosaic services",
|
|
5
5
|
"author": "Axinom",
|
|
6
6
|
"license": "PROPRIETARY",
|
|
@@ -32,9 +32,9 @@
|
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"@apollo/client": "^3.7.9",
|
|
35
|
-
"@axinom/mosaic-core": "^0.4.7-rc.
|
|
36
|
-
"@axinom/mosaic-id-utils": "^0.15.4-rc.
|
|
37
|
-
"@axinom/mosaic-service-common": "^0.35.0-rc.
|
|
35
|
+
"@axinom/mosaic-core": "^0.4.7-rc.25",
|
|
36
|
+
"@axinom/mosaic-id-utils": "^0.15.4-rc.25",
|
|
37
|
+
"@axinom/mosaic-service-common": "^0.35.0-rc.25",
|
|
38
38
|
"axios": "^0.19.2",
|
|
39
39
|
"cross-fetch": "^3.0.4",
|
|
40
40
|
"graphql": "^15.4.0",
|
|
@@ -52,5 +52,5 @@
|
|
|
52
52
|
"publishConfig": {
|
|
53
53
|
"access": "public"
|
|
54
54
|
},
|
|
55
|
-
"gitHead": "
|
|
55
|
+
"gitHead": "d33b49a724bf610720b18da69c26c40cdfd7f2ab"
|
|
56
56
|
}
|
|
@@ -1,8 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
assertError,
|
|
3
|
-
Logger,
|
|
4
|
-
skipMaskTag,
|
|
5
|
-
} from '@axinom/mosaic-service-common';
|
|
6
1
|
import { getGqlClient } from '../common/gql-client';
|
|
7
2
|
import {
|
|
8
3
|
DevCreateServiceAccountDocument,
|
|
@@ -36,54 +31,43 @@ export const devCreateServiceAccount = async (
|
|
|
36
31
|
permissions?: string[];
|
|
37
32
|
}[],
|
|
38
33
|
): Promise<DevServiceAccount> => {
|
|
39
|
-
const
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
'Bearer token-not-needed-for-DEV-endpoints',
|
|
44
|
-
);
|
|
34
|
+
const client = getGqlClient(
|
|
35
|
+
(await getWellKnownEndpoints(authEndpoint)).authGraphQlEndpoint,
|
|
36
|
+
'Bearer token-not-needed-for-DEV-endpoints',
|
|
37
|
+
);
|
|
45
38
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
},
|
|
39
|
+
const result = await client.mutate<
|
|
40
|
+
DevCreateServiceAccountMutation,
|
|
41
|
+
DevCreateServiceAccountMutationVariables
|
|
42
|
+
>({
|
|
43
|
+
mutation: DevCreateServiceAccountDocument,
|
|
44
|
+
variables: {
|
|
45
|
+
input: {
|
|
46
|
+
serviceAccountName,
|
|
47
|
+
tenantId,
|
|
48
|
+
environmentId: environmentId,
|
|
49
|
+
permissionStructure: permissions,
|
|
58
50
|
},
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
if (!result.errors) {
|
|
64
|
-
if (result.data?._DEV_createServiceAccount) {
|
|
65
|
-
return result.data._DEV_createServiceAccount;
|
|
66
|
-
}
|
|
67
|
-
throw new Error(
|
|
68
|
-
`Unexpected null or undefined value received for '_DEV_createServiceAccount' result.`,
|
|
69
|
-
);
|
|
70
|
-
} else {
|
|
71
|
-
const aggregatedErrorMessage = result.errors?.reduce(
|
|
72
|
-
(aggregatedError, gqlError) => {
|
|
73
|
-
return (aggregatedError += gqlError.message);
|
|
74
|
-
},
|
|
75
|
-
'',
|
|
76
|
-
);
|
|
51
|
+
},
|
|
52
|
+
errorPolicy: 'all',
|
|
53
|
+
fetchPolicy: 'no-cache',
|
|
54
|
+
});
|
|
77
55
|
|
|
78
|
-
|
|
56
|
+
if (!result.errors) {
|
|
57
|
+
if (result.data?._DEV_createServiceAccount) {
|
|
58
|
+
return result.data._DEV_createServiceAccount;
|
|
79
59
|
}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
60
|
+
throw new Error(
|
|
61
|
+
`Unexpected null or undefined value received for '_DEV_createServiceAccount' result.`,
|
|
62
|
+
);
|
|
63
|
+
} else {
|
|
64
|
+
const aggregatedErrorMessage = result.errors.reduce(
|
|
65
|
+
(aggregatedError, gqlError) => {
|
|
66
|
+
return (aggregatedError += gqlError.message);
|
|
67
|
+
},
|
|
68
|
+
'',
|
|
69
|
+
);
|
|
86
70
|
|
|
87
|
-
throw
|
|
71
|
+
throw new Error(aggregatedErrorMessage);
|
|
88
72
|
}
|
|
89
73
|
};
|
|
@@ -1,9 +1,4 @@
|
|
|
1
1
|
import { TokenResult } from '@axinom/mosaic-id-utils';
|
|
2
|
-
import {
|
|
3
|
-
assertError,
|
|
4
|
-
Logger,
|
|
5
|
-
skipMaskTag,
|
|
6
|
-
} from '@axinom/mosaic-service-common';
|
|
7
2
|
import { getGqlClient } from '../common/gql-client';
|
|
8
3
|
import {
|
|
9
4
|
GenerateLongLivedTokenDocument,
|
|
@@ -26,60 +21,49 @@ export const generateLongLivedToken = async (
|
|
|
26
21
|
userAccessToken: string,
|
|
27
22
|
validityDurationInSeconds?: number,
|
|
28
23
|
): Promise<TokenResult> => {
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
serviceAccountToken,
|
|
34
|
-
);
|
|
24
|
+
const client = getGqlClient(
|
|
25
|
+
(await getWellKnownEndpoints(authEndpoint)).authGraphQlEndpoint,
|
|
26
|
+
serviceAccountToken,
|
|
27
|
+
);
|
|
35
28
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
},
|
|
29
|
+
const result = await client.mutate<
|
|
30
|
+
GenerateLongLivedTokenMutation,
|
|
31
|
+
GenerateLongLivedTokenMutationVariables
|
|
32
|
+
>({
|
|
33
|
+
mutation: GenerateLongLivedTokenDocument,
|
|
34
|
+
variables: {
|
|
35
|
+
input: {
|
|
36
|
+
userToken: userAccessToken,
|
|
37
|
+
validityDurationInSeconds,
|
|
46
38
|
},
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
if (!result.errors) {
|
|
52
|
-
if (!result.data) {
|
|
53
|
-
throw new Error(
|
|
54
|
-
`Unexpected null or undefined value received for 'generateLongLivedToken' result.`,
|
|
55
|
-
);
|
|
56
|
-
}
|
|
57
|
-
const tokenResponse = result.data.generateLongLivedToken;
|
|
39
|
+
},
|
|
40
|
+
errorPolicy: 'all',
|
|
41
|
+
fetchPolicy: 'no-cache',
|
|
42
|
+
});
|
|
58
43
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
return longLivedToken;
|
|
66
|
-
} else {
|
|
67
|
-
const aggregatedErrorMessage = result.errors.reduce(
|
|
68
|
-
(aggregatedError, gqlError) => {
|
|
69
|
-
return (aggregatedError += gqlError.message);
|
|
70
|
-
},
|
|
71
|
-
'',
|
|
44
|
+
if (!result.errors) {
|
|
45
|
+
if (!result.data) {
|
|
46
|
+
throw new Error(
|
|
47
|
+
`Unexpected null or undefined value received for 'generateLongLivedToken' result.`,
|
|
72
48
|
);
|
|
73
|
-
|
|
74
|
-
throw new Error(aggregatedErrorMessage);
|
|
75
49
|
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
50
|
+
const tokenResponse = result.data.generateLongLivedToken;
|
|
51
|
+
|
|
52
|
+
const longLivedToken = {
|
|
53
|
+
accessToken: tokenResponse.accessToken,
|
|
54
|
+
tokenType: tokenResponse.tokenType,
|
|
55
|
+
expiresInSeconds: tokenResponse.expiresInSeconds,
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
return longLivedToken;
|
|
59
|
+
} else {
|
|
60
|
+
const aggregatedErrorMessage = result.errors.reduce(
|
|
61
|
+
(aggregatedError, gqlError) => {
|
|
62
|
+
return (aggregatedError += gqlError.message);
|
|
63
|
+
},
|
|
64
|
+
'',
|
|
65
|
+
);
|
|
82
66
|
|
|
83
|
-
throw
|
|
67
|
+
throw new Error(aggregatedErrorMessage);
|
|
84
68
|
}
|
|
85
69
|
};
|
|
@@ -1,9 +1,4 @@
|
|
|
1
1
|
import { TokenResult } from '@axinom/mosaic-id-utils';
|
|
2
|
-
import {
|
|
3
|
-
assertError,
|
|
4
|
-
Logger,
|
|
5
|
-
skipMaskTag,
|
|
6
|
-
} from '@axinom/mosaic-service-common';
|
|
7
2
|
import { getGqlClient } from '../common/gql-client';
|
|
8
3
|
import {
|
|
9
4
|
GetManagedServiceTokenDocument,
|
|
@@ -17,9 +12,7 @@ import {
|
|
|
17
12
|
GetServiceTokenMutationVariables,
|
|
18
13
|
} from '../generated/graphql.types';
|
|
19
14
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
// TODO: Once we merge authenticateServiceAccount & authenticateManagedServiceAccount mutaitons,
|
|
15
|
+
// TODO: Once we merge authenticateServiceAccount & authenticateManagedServiceAccount mutations,
|
|
23
16
|
// these functions can also be merged into one.
|
|
24
17
|
|
|
25
18
|
/**
|
|
@@ -34,57 +27,47 @@ export const getServiceAccountToken = async (
|
|
|
34
27
|
clientId: string,
|
|
35
28
|
clientSecret: string,
|
|
36
29
|
): Promise<TokenResult> => {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
if (!result.
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
`Unexpected null or undefined value received for 'getServiceAccountToken' result.`,
|
|
59
|
-
);
|
|
60
|
-
}
|
|
61
|
-
const tokenResponse = result.data.authenticateServiceAccount;
|
|
62
|
-
|
|
63
|
-
serviceAccountAccessToken = {
|
|
64
|
-
accessToken: tokenResponse.accessToken,
|
|
65
|
-
tokenType: tokenResponse.tokenType,
|
|
66
|
-
expiresInSeconds: tokenResponse.expiresInSeconds,
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
return serviceAccountAccessToken;
|
|
70
|
-
} else {
|
|
71
|
-
const aggregatedErrorMessage = result.errors.reduce(
|
|
72
|
-
(aggregatedError, gqlError) => {
|
|
73
|
-
return (aggregatedError += gqlError.message);
|
|
74
|
-
},
|
|
75
|
-
'',
|
|
30
|
+
const client = getGqlClient(new URL(`/graphql`, authEndpoint).href);
|
|
31
|
+
|
|
32
|
+
let serviceAccountAccessToken: TokenResult;
|
|
33
|
+
|
|
34
|
+
const result = await client.mutate<
|
|
35
|
+
GetServiceTokenMutation,
|
|
36
|
+
GetServiceTokenMutationVariables
|
|
37
|
+
>({
|
|
38
|
+
mutation: GetServiceTokenDocument,
|
|
39
|
+
variables: {
|
|
40
|
+
clientId: clientId,
|
|
41
|
+
clientSecret: clientSecret,
|
|
42
|
+
},
|
|
43
|
+
errorPolicy: 'all',
|
|
44
|
+
fetchPolicy: 'no-cache',
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
if (!result.errors) {
|
|
48
|
+
if (!result.data) {
|
|
49
|
+
throw new Error(
|
|
50
|
+
`Unexpected null or undefined value received for 'getServiceAccountToken' result.`,
|
|
76
51
|
);
|
|
77
|
-
|
|
78
|
-
throw new Error(aggregatedErrorMessage);
|
|
79
52
|
}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
53
|
+
const tokenResponse = result.data.authenticateServiceAccount;
|
|
54
|
+
|
|
55
|
+
serviceAccountAccessToken = {
|
|
56
|
+
accessToken: tokenResponse.accessToken,
|
|
57
|
+
tokenType: tokenResponse.tokenType,
|
|
58
|
+
expiresInSeconds: tokenResponse.expiresInSeconds,
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
return serviceAccountAccessToken;
|
|
62
|
+
} else {
|
|
63
|
+
const aggregatedErrorMessage = result.errors.reduce(
|
|
64
|
+
(aggregatedError, gqlError) => {
|
|
65
|
+
return (aggregatedError += gqlError.message);
|
|
66
|
+
},
|
|
67
|
+
'',
|
|
68
|
+
);
|
|
69
|
+
|
|
70
|
+
throw new Error(aggregatedErrorMessage);
|
|
88
71
|
}
|
|
89
72
|
};
|
|
90
73
|
|
|
@@ -104,53 +87,48 @@ export const getManagedServiceAccountToken = async (
|
|
|
104
87
|
targetTenantId?: string,
|
|
105
88
|
targetEnvironmentId?: string,
|
|
106
89
|
): Promise<TokenResult> => {
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
if (!result.
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
serviceAccountAccessToken = {
|
|
131
|
-
accessToken: tokenResponse.accessToken,
|
|
132
|
-
tokenType: tokenResponse.tokenType,
|
|
133
|
-
expiresInSeconds: tokenResponse.expiresInSeconds,
|
|
134
|
-
};
|
|
135
|
-
|
|
136
|
-
return serviceAccountAccessToken;
|
|
137
|
-
} else {
|
|
138
|
-
const aggregatedErrorMessage = result.errors?.reduce(
|
|
139
|
-
(aggregatedError, gqlError) => {
|
|
140
|
-
return (aggregatedError += gqlError.message);
|
|
141
|
-
},
|
|
142
|
-
'',
|
|
90
|
+
const client = getGqlClient(new URL(`/graphql`, authEndpoint).href);
|
|
91
|
+
|
|
92
|
+
let serviceAccountAccessToken: TokenResult;
|
|
93
|
+
|
|
94
|
+
const result = await client.mutate<
|
|
95
|
+
GetManagedServiceTokenMutation,
|
|
96
|
+
GetManagedServiceTokenMutationVariables
|
|
97
|
+
>({
|
|
98
|
+
mutation: GetManagedServiceTokenDocument,
|
|
99
|
+
variables: {
|
|
100
|
+
clientId: clientId,
|
|
101
|
+
clientSecret: clientSecret,
|
|
102
|
+
targetTenantId,
|
|
103
|
+
targetEnvironmentId: targetEnvironmentId,
|
|
104
|
+
},
|
|
105
|
+
errorPolicy: 'all',
|
|
106
|
+
fetchPolicy: 'no-cache',
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
if (!result.errors) {
|
|
110
|
+
if (!result.data) {
|
|
111
|
+
throw new Error(
|
|
112
|
+
`Unexpected null or undefined value received for 'getManagedServiceAccountToken' result.`,
|
|
143
113
|
);
|
|
144
|
-
throw new Error(aggregatedErrorMessage);
|
|
145
114
|
}
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
115
|
+
const tokenResponse = result.data.authenticateManagedServiceAccount;
|
|
116
|
+
|
|
117
|
+
serviceAccountAccessToken = {
|
|
118
|
+
accessToken: tokenResponse.accessToken,
|
|
119
|
+
tokenType: tokenResponse.tokenType,
|
|
120
|
+
expiresInSeconds: tokenResponse.expiresInSeconds,
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
return serviceAccountAccessToken;
|
|
124
|
+
} else {
|
|
125
|
+
const aggregatedErrorMessage = result.errors.reduce(
|
|
126
|
+
(aggregatedError, gqlError) => {
|
|
127
|
+
return (aggregatedError += gqlError.message);
|
|
128
|
+
},
|
|
129
|
+
'',
|
|
130
|
+
);
|
|
131
|
+
throw new Error(aggregatedErrorMessage);
|
|
154
132
|
}
|
|
155
133
|
};
|
|
156
134
|
|
|
@@ -171,52 +149,47 @@ export const getScopedManagedServiceAccountToken = async (
|
|
|
171
149
|
clientSecret: string,
|
|
172
150
|
managementJWT: string,
|
|
173
151
|
): Promise<TokenResult> => {
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
if (!result.
|
|
194
|
-
|
|
195
|
-
result
|
|
196
|
-
|
|
197
|
-
serviceAccountAccessToken = {
|
|
198
|
-
accessToken: tokenResponse.accessToken,
|
|
199
|
-
tokenType: tokenResponse.tokenType,
|
|
200
|
-
expiresInSeconds: tokenResponse.expiresInSeconds,
|
|
201
|
-
};
|
|
202
|
-
|
|
203
|
-
return serviceAccountAccessToken;
|
|
204
|
-
} else {
|
|
205
|
-
const aggregatedErrorMessage = result.errors?.reduce(
|
|
206
|
-
(aggregatedError, gqlError) => {
|
|
207
|
-
return (aggregatedError += gqlError.message);
|
|
208
|
-
},
|
|
209
|
-
'',
|
|
152
|
+
const client = getGqlClient(new URL(`/graphql`, authEndpoint).href);
|
|
153
|
+
|
|
154
|
+
let serviceAccountAccessToken: TokenResult;
|
|
155
|
+
|
|
156
|
+
const result = await client.mutate<
|
|
157
|
+
GetManagedServiceTokenWithEnvironmentScopeMutation,
|
|
158
|
+
GetManagedServiceTokenWithEnvironmentScopeMutationVariables
|
|
159
|
+
>({
|
|
160
|
+
mutation: GetManagedServiceTokenWithEnvironmentScopeDocument,
|
|
161
|
+
variables: {
|
|
162
|
+
clientId: clientId,
|
|
163
|
+
clientSecret: clientSecret,
|
|
164
|
+
managementJWT,
|
|
165
|
+
},
|
|
166
|
+
errorPolicy: 'all',
|
|
167
|
+
fetchPolicy: 'no-cache',
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
if (!result.errors) {
|
|
171
|
+
if (!result.data) {
|
|
172
|
+
throw new Error(
|
|
173
|
+
`Unexpected null or undefined value received for 'getScopedManagedServiceAccountToken' result.`,
|
|
210
174
|
);
|
|
211
|
-
throw new Error(aggregatedErrorMessage);
|
|
212
175
|
}
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
176
|
+
const tokenResponse =
|
|
177
|
+
result.data.authenticateManagedServiceAccountWithEnvironmentScope;
|
|
178
|
+
|
|
179
|
+
serviceAccountAccessToken = {
|
|
180
|
+
accessToken: tokenResponse.accessToken,
|
|
181
|
+
tokenType: tokenResponse.tokenType,
|
|
182
|
+
expiresInSeconds: tokenResponse.expiresInSeconds,
|
|
183
|
+
};
|
|
184
|
+
|
|
185
|
+
return serviceAccountAccessToken;
|
|
186
|
+
} else {
|
|
187
|
+
const aggregatedErrorMessage = result.errors.reduce(
|
|
188
|
+
(aggregatedError, gqlError) => {
|
|
189
|
+
return (aggregatedError += gqlError.message);
|
|
190
|
+
},
|
|
191
|
+
'',
|
|
192
|
+
);
|
|
193
|
+
throw new Error(aggregatedErrorMessage);
|
|
221
194
|
}
|
|
222
195
|
};
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import { Logger } from '@axinom/mosaic-service-common';
|
|
2
1
|
import axios from 'axios';
|
|
3
|
-
import { assertAxiosError } from '../common';
|
|
4
2
|
import { WellKnownEndpoints } from '../common/types';
|
|
5
3
|
|
|
6
4
|
/**
|
|
@@ -11,40 +9,10 @@ import { WellKnownEndpoints } from '../common/types';
|
|
|
11
9
|
export async function getWellKnownEndpoints(
|
|
12
10
|
authEndpoint: string,
|
|
13
11
|
): Promise<WellKnownEndpoints> {
|
|
14
|
-
const logger = new Logger({ context: getWellKnownEndpoints.name });
|
|
15
12
|
const wellKnownEndpointUrl = new URL(`/.well-known`, `${authEndpoint}`).href;
|
|
16
13
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
.data;
|
|
20
|
-
return result;
|
|
21
|
-
} catch (error) {
|
|
22
|
-
const message = 'Error occurred while requesting /.well-known endpoint';
|
|
23
|
-
assertAxiosError(error);
|
|
24
|
-
if (error.response) {
|
|
25
|
-
// Received an error response (5xx, 4xx) from the server
|
|
26
|
-
logger.error({
|
|
27
|
-
message,
|
|
28
|
-
details: {
|
|
29
|
-
responseStatus: error.response.status,
|
|
30
|
-
responseData: error.response.data,
|
|
31
|
-
responseHeaders: error.response.headers,
|
|
32
|
-
stack: error.stack,
|
|
33
|
-
},
|
|
34
|
-
});
|
|
35
|
-
} else if (error.request) {
|
|
36
|
-
// Did not receive a response, or request never left
|
|
37
|
-
logger.error({
|
|
38
|
-
message: `${message}. Did not receive a response from the server.`,
|
|
39
|
-
details: { requestPath: error.request.path, stack: error.stack },
|
|
40
|
-
});
|
|
41
|
-
} else {
|
|
42
|
-
logger.error({
|
|
43
|
-
message,
|
|
44
|
-
details: { error: error.message, stack: error.stack },
|
|
45
|
-
});
|
|
46
|
-
}
|
|
14
|
+
const result: WellKnownEndpoints = (await axios.get(wellKnownEndpointUrl))
|
|
15
|
+
.data;
|
|
47
16
|
|
|
48
|
-
|
|
49
|
-
}
|
|
17
|
+
return result;
|
|
50
18
|
}
|