@zetra/citrineos-util 1.8.3-fork.37 → 1.8.3-fork.39
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.
|
@@ -1,15 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export interface OidcTokenProviderConfig {
|
|
4
|
-
tokenUrl: string;
|
|
5
|
-
clientId: string;
|
|
6
|
-
clientSecret: string;
|
|
7
|
-
audience: string;
|
|
8
|
-
}
|
|
9
|
-
export declare class OidcTokenProvider {
|
|
10
|
-
private config;
|
|
11
|
-
private oidcToken?;
|
|
12
|
-
private readonly _logger;
|
|
13
|
-
constructor(config: OidcTokenProviderConfig, logger?: Logger<ILogObj>);
|
|
14
|
-
getToken(): Promise<string>;
|
|
15
|
-
}
|
|
1
|
+
export { OidcTokenProvider } from '@zetra/citrineos-base';
|
|
2
|
+
export type { OidcTokenProviderConfig } from '@zetra/citrineos-base';
|
|
@@ -1,47 +1,8 @@
|
|
|
1
1
|
// SPDX-FileCopyrightText: 2025 Contributors to the CitrineOS Project
|
|
2
2
|
//
|
|
3
3
|
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
_logger;
|
|
9
|
-
constructor(config, logger) {
|
|
10
|
-
this.config = config;
|
|
11
|
-
this._logger = logger
|
|
12
|
-
? logger.getSubLogger({ name: this.constructor.name })
|
|
13
|
-
: new Logger({ name: this.constructor.name });
|
|
14
|
-
}
|
|
15
|
-
async getToken() {
|
|
16
|
-
if (this.oidcToken && this.oidcToken.expiresAt > Date.now()) {
|
|
17
|
-
this._logger.debug('Returning cached OIDC token');
|
|
18
|
-
return this.oidcToken.accessToken;
|
|
19
|
-
}
|
|
20
|
-
this._logger.debug('Fetching new OIDC token');
|
|
21
|
-
const response = await fetch(this.config.tokenUrl, {
|
|
22
|
-
method: 'POST',
|
|
23
|
-
headers: {
|
|
24
|
-
'Content-Type': 'application/x-www-form-urlencoded',
|
|
25
|
-
},
|
|
26
|
-
body: new URLSearchParams({
|
|
27
|
-
grant_type: 'client_credentials',
|
|
28
|
-
client_id: this.config.clientId,
|
|
29
|
-
client_secret: this.config.clientSecret,
|
|
30
|
-
audience: this.config.audience,
|
|
31
|
-
}),
|
|
32
|
-
});
|
|
33
|
-
if (!response.ok) {
|
|
34
|
-
const errorText = await response.text();
|
|
35
|
-
this._logger.error('Failed to fetch OIDC token:', errorText);
|
|
36
|
-
throw new Error(`Failed to fetch OIDC token: ${response.statusText}`);
|
|
37
|
-
}
|
|
38
|
-
const tokenData = await response.json();
|
|
39
|
-
this.oidcToken = {
|
|
40
|
-
accessToken: tokenData.access_token,
|
|
41
|
-
// Set expiry to 1 minute before actual expiration to be safe
|
|
42
|
-
expiresAt: Date.now() + (tokenData.expires_in - 60) * 1000,
|
|
43
|
-
};
|
|
44
|
-
return this.oidcToken.accessToken;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
4
|
+
// The OidcTokenProvider now lives in @zetra/citrineos-base so that base-level modules
|
|
5
|
+
// (e.g. AbstractModule message API callbacks) can authenticate callbacks as well.
|
|
6
|
+
// Re-exported here to preserve existing import paths.
|
|
7
|
+
export { OidcTokenProvider } from '@zetra/citrineos-base';
|
|
47
8
|
//# sourceMappingURL=OidcTokenProvider.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OidcTokenProvider.js","sourceRoot":"","sources":["../../src/authorization/OidcTokenProvider.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,EAAE;AACF,sCAAsC;
|
|
1
|
+
{"version":3,"file":"OidcTokenProvider.js","sourceRoot":"","sources":["../../src/authorization/OidcTokenProvider.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,EAAE;AACF,sCAAsC;AAEtC,gFAAgF;AAChF,kFAAkF;AAClF,sDAAsD;AACtD,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zetra/citrineos-util",
|
|
3
|
-
"version": "1.8.3-fork.
|
|
3
|
+
"version": "1.8.3-fork.39",
|
|
4
4
|
"description": "The OCPP util module which supplies helpful utilities like cache and queue connectors, etc.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -24,8 +24,8 @@
|
|
|
24
24
|
"@types/jsrsasign": "10.5.14"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@zetra/citrineos-base": "1.8.3-fork.
|
|
28
|
-
"@zetra/citrineos-data": "1.8.3-fork.
|
|
27
|
+
"@zetra/citrineos-base": "1.8.3-fork.39",
|
|
28
|
+
"@zetra/citrineos-data": "1.8.3-fork.39",
|
|
29
29
|
"@fastify/swagger": "9.4.0",
|
|
30
30
|
"@fastify/swagger-ui": "5.2.0",
|
|
31
31
|
"@google-cloud/storage": "7.18.0",
|