@sebspark/gcp-iam 0.4.0 → 1.0.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/index.d.mts +13 -2
- package/dist/index.d.ts +13 -2
- package/dist/index.js +21 -3
- package/dist/index.mjs +18 -2
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -8,11 +8,22 @@ import { Logger } from 'winston';
|
|
|
8
8
|
* @param logger An optional logger to use for logging.
|
|
9
9
|
* @returns A JWT.
|
|
10
10
|
*/
|
|
11
|
-
declare const
|
|
11
|
+
declare const getApiGatewayTokenByUrl: ({ apiURL, key, ttl, logger, }: {
|
|
12
12
|
apiURL: string;
|
|
13
13
|
key?: string;
|
|
14
14
|
ttl?: number;
|
|
15
15
|
logger?: Logger;
|
|
16
16
|
}) => Promise<string>;
|
|
17
|
+
/**
|
|
18
|
+
*
|
|
19
|
+
* @param key Clears a cached JWT by key.
|
|
20
|
+
*/
|
|
21
|
+
declare const clearCache: (key: string) => Promise<void>;
|
|
22
|
+
/**
|
|
23
|
+
* Generates a JWT for the API Gateway, using Client ID as audience.
|
|
24
|
+
* @param clientId OAUTH Client ID.
|
|
25
|
+
* @returns ID Token.
|
|
26
|
+
*/
|
|
27
|
+
declare const getApiGatewayTokenByClientId: (clientId: string) => Promise<string>;
|
|
17
28
|
|
|
18
|
-
export {
|
|
29
|
+
export { clearCache, getApiGatewayTokenByClientId, getApiGatewayTokenByUrl };
|
package/dist/index.d.ts
CHANGED
|
@@ -8,11 +8,22 @@ import { Logger } from 'winston';
|
|
|
8
8
|
* @param logger An optional logger to use for logging.
|
|
9
9
|
* @returns A JWT.
|
|
10
10
|
*/
|
|
11
|
-
declare const
|
|
11
|
+
declare const getApiGatewayTokenByUrl: ({ apiURL, key, ttl, logger, }: {
|
|
12
12
|
apiURL: string;
|
|
13
13
|
key?: string;
|
|
14
14
|
ttl?: number;
|
|
15
15
|
logger?: Logger;
|
|
16
16
|
}) => Promise<string>;
|
|
17
|
+
/**
|
|
18
|
+
*
|
|
19
|
+
* @param key Clears a cached JWT by key.
|
|
20
|
+
*/
|
|
21
|
+
declare const clearCache: (key: string) => Promise<void>;
|
|
22
|
+
/**
|
|
23
|
+
* Generates a JWT for the API Gateway, using Client ID as audience.
|
|
24
|
+
* @param clientId OAUTH Client ID.
|
|
25
|
+
* @returns ID Token.
|
|
26
|
+
*/
|
|
27
|
+
declare const getApiGatewayTokenByClientId: (clientId: string) => Promise<string>;
|
|
17
28
|
|
|
18
|
-
export {
|
|
29
|
+
export { clearCache, getApiGatewayTokenByClientId, getApiGatewayTokenByUrl };
|
package/dist/index.js
CHANGED
|
@@ -20,7 +20,9 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/index.ts
|
|
21
21
|
var index_exports = {};
|
|
22
22
|
__export(index_exports, {
|
|
23
|
-
|
|
23
|
+
clearCache: () => clearCache,
|
|
24
|
+
getApiGatewayTokenByClientId: () => getApiGatewayTokenByClientId,
|
|
25
|
+
getApiGatewayTokenByUrl: () => getApiGatewayTokenByUrl
|
|
24
26
|
});
|
|
25
27
|
module.exports = __toCommonJS(index_exports);
|
|
26
28
|
|
|
@@ -62,12 +64,15 @@ var LruCache = class {
|
|
|
62
64
|
ttl: ttl || this.defaultTTL
|
|
63
65
|
});
|
|
64
66
|
}
|
|
67
|
+
clear(key) {
|
|
68
|
+
this.values.delete(key);
|
|
69
|
+
}
|
|
65
70
|
};
|
|
66
71
|
|
|
67
72
|
// src/apiGatewayToken.ts
|
|
68
73
|
var expInSeconds = 60 * 60;
|
|
69
74
|
var apiGatewayJwtCache = new LruCache();
|
|
70
|
-
var
|
|
75
|
+
var getApiGatewayTokenByUrl = async ({
|
|
71
76
|
apiURL,
|
|
72
77
|
key,
|
|
73
78
|
ttl,
|
|
@@ -113,6 +118,7 @@ var getApiGatewayToken = async ({
|
|
|
113
118
|
"signBlob(...) returned an empty response. Cannot sign JWT."
|
|
114
119
|
);
|
|
115
120
|
}
|
|
121
|
+
console.log("IAM KeyID", response.keyId);
|
|
116
122
|
const signature = Buffer.from(response.signedBlob).toString("base64");
|
|
117
123
|
const signedJWT = `${unsignedJWT}.${signature}`;
|
|
118
124
|
apiGatewayJwtCache.put(key || apiURL, signedJWT, ttl);
|
|
@@ -126,7 +132,19 @@ var getApiGatewayToken = async ({
|
|
|
126
132
|
throw new Error(`Error generating system JWT: ${JSON.stringify(error)}`);
|
|
127
133
|
}
|
|
128
134
|
};
|
|
135
|
+
var clearCache = async (key) => {
|
|
136
|
+
apiGatewayJwtCache.clear(key);
|
|
137
|
+
};
|
|
138
|
+
var getApiGatewayTokenByClientId = async (clientId) => {
|
|
139
|
+
const auth = new import_google_auth_library.GoogleAuth({
|
|
140
|
+
scopes: "https://www.googleapis.com/auth/cloud-platform"
|
|
141
|
+
});
|
|
142
|
+
const client = await auth.getIdTokenClient(clientId);
|
|
143
|
+
return await client.idTokenProvider.fetchIdToken(clientId);
|
|
144
|
+
};
|
|
129
145
|
// Annotate the CommonJS export names for ESM import in node:
|
|
130
146
|
0 && (module.exports = {
|
|
131
|
-
|
|
147
|
+
clearCache,
|
|
148
|
+
getApiGatewayTokenByClientId,
|
|
149
|
+
getApiGatewayTokenByUrl
|
|
132
150
|
});
|
package/dist/index.mjs
CHANGED
|
@@ -36,12 +36,15 @@ var LruCache = class {
|
|
|
36
36
|
ttl: ttl || this.defaultTTL
|
|
37
37
|
});
|
|
38
38
|
}
|
|
39
|
+
clear(key) {
|
|
40
|
+
this.values.delete(key);
|
|
41
|
+
}
|
|
39
42
|
};
|
|
40
43
|
|
|
41
44
|
// src/apiGatewayToken.ts
|
|
42
45
|
var expInSeconds = 60 * 60;
|
|
43
46
|
var apiGatewayJwtCache = new LruCache();
|
|
44
|
-
var
|
|
47
|
+
var getApiGatewayTokenByUrl = async ({
|
|
45
48
|
apiURL,
|
|
46
49
|
key,
|
|
47
50
|
ttl,
|
|
@@ -87,6 +90,7 @@ var getApiGatewayToken = async ({
|
|
|
87
90
|
"signBlob(...) returned an empty response. Cannot sign JWT."
|
|
88
91
|
);
|
|
89
92
|
}
|
|
93
|
+
console.log("IAM KeyID", response.keyId);
|
|
90
94
|
const signature = Buffer.from(response.signedBlob).toString("base64");
|
|
91
95
|
const signedJWT = `${unsignedJWT}.${signature}`;
|
|
92
96
|
apiGatewayJwtCache.put(key || apiURL, signedJWT, ttl);
|
|
@@ -100,6 +104,18 @@ var getApiGatewayToken = async ({
|
|
|
100
104
|
throw new Error(`Error generating system JWT: ${JSON.stringify(error)}`);
|
|
101
105
|
}
|
|
102
106
|
};
|
|
107
|
+
var clearCache = async (key) => {
|
|
108
|
+
apiGatewayJwtCache.clear(key);
|
|
109
|
+
};
|
|
110
|
+
var getApiGatewayTokenByClientId = async (clientId) => {
|
|
111
|
+
const auth = new GoogleAuth({
|
|
112
|
+
scopes: "https://www.googleapis.com/auth/cloud-platform"
|
|
113
|
+
});
|
|
114
|
+
const client = await auth.getIdTokenClient(clientId);
|
|
115
|
+
return await client.idTokenProvider.fetchIdToken(clientId);
|
|
116
|
+
};
|
|
103
117
|
export {
|
|
104
|
-
|
|
118
|
+
clearCache,
|
|
119
|
+
getApiGatewayTokenByClientId,
|
|
120
|
+
getApiGatewayTokenByUrl
|
|
105
121
|
};
|