@axinom/mosaic-id-link-be 0.13.4-rc.9 → 0.13.5-rc.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/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/generated/graphql.types.d.ts +2151 -2147
- package/dist/generated/graphql.types.d.ts.map +1 -1
- package/dist/generated/graphql.types.js +230 -226
- package/dist/generated/graphql.types.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 +6 -6
- package/src/dev/dev-create-service-account.ts +33 -49
- package/src/generated/graphql.types.ts +2349 -2345
- 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,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
|
}
|