codemie-sdk 0.1.397 → 0.1.399

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.cts CHANGED
@@ -1944,6 +1944,8 @@ interface CodeMieClientConfig {
1944
1944
  auth_client_secret?: string;
1945
1945
  username?: string;
1946
1946
  password?: string;
1947
+ external_token?: string;
1948
+ external_idp?: string;
1947
1949
  cookies?: Record<string, string>;
1948
1950
  verify_ssl?: boolean;
1949
1951
  }
package/dist/index.d.ts CHANGED
@@ -1944,6 +1944,8 @@ interface CodeMieClientConfig {
1944
1944
  auth_client_secret?: string;
1945
1945
  username?: string;
1946
1946
  password?: string;
1947
+ external_token?: string;
1948
+ external_idp?: string;
1947
1949
  cookies?: Record<string, string>;
1948
1950
  verify_ssl?: boolean;
1949
1951
  }
package/dist/index.js CHANGED
@@ -13,13 +13,31 @@ var KeycloakCredentials = class {
13
13
  async getToken() {
14
14
  const { serverUrl, realmName } = this.config;
15
15
  const url = `${serverUrl}/realms/${realmName}/protocol/openid-connect/token`;
16
- const payload = this.config.username && this.config.password ? this.createResourceOwnerCredentialsPayload() : this.createClientCredentialsPayload();
16
+ let payload;
17
+ if (this.config.externalToken && this.config.externalIdp) {
18
+ payload = this.createTokenExchangePayload();
19
+ } else if (this.config.username && this.config.password) {
20
+ payload = this.createResourceOwnerCredentialsPayload();
21
+ } else {
22
+ payload = this.createClientCredentialsPayload();
23
+ }
17
24
  const { data } = await axios.post(url, this.createSearchParams(payload), {
18
25
  headers: { "Content-Type": "application/x-www-form-urlencoded" },
19
26
  httpsAgent: this.httpAgent
20
27
  });
21
28
  return data.access_token;
22
29
  }
30
+ createTokenExchangePayload() {
31
+ const { clientId, clientSecret, externalToken, externalIdp } = this.config;
32
+ return {
33
+ grant_type: "urn:ietf:params:oauth:grant-type:token-exchange",
34
+ client_id: clientId || DEFAULT_CLIENT_ID,
35
+ client_secret: clientSecret,
36
+ subject_token: externalToken,
37
+ subject_issuer: externalIdp,
38
+ requested_token_type: "urn:ietf:params:oauth:token-type:access_token"
39
+ };
40
+ }
23
41
  createResourceOwnerCredentialsPayload() {
24
42
  const { username, password, clientId } = this.config;
25
43
  return {
@@ -43,9 +61,12 @@ var KeycloakCredentials = class {
43
61
  );
44
62
  }
45
63
  validateConfigCredentials(config) {
46
- if (!(config.clientId && config.clientSecret || config.username && config.password)) {
64
+ const hasClientCredentials = !!(config.clientId && config.clientSecret);
65
+ const hasUserCredentials = !!(config.username && config.password);
66
+ const hasExternalTokenCredentials = !!(config.externalToken && config.externalIdp);
67
+ if (!hasClientCredentials && !hasUserCredentials && !hasExternalTokenCredentials) {
47
68
  throw new Error(
48
- "Either client credentials (clientId, clientSecret) or user credentials (username, password) must be provided"
69
+ "Either client credentials (clientId, clientSecret), user credentials (username, password), or external token credentials (externalToken, externalIdp) must be provided"
49
70
  );
50
71
  }
51
72
  }
@@ -1461,6 +1482,8 @@ var CodeMieClient = class {
1461
1482
  auth_client_secret,
1462
1483
  username,
1463
1484
  password,
1485
+ external_token,
1486
+ external_idp,
1464
1487
  cookies,
1465
1488
  verify_ssl = true
1466
1489
  } = config;
@@ -1481,6 +1504,8 @@ var CodeMieClient = class {
1481
1504
  clientSecret: auth_client_secret,
1482
1505
  username,
1483
1506
  password,
1507
+ externalToken: external_token,
1508
+ externalIdp: external_idp,
1484
1509
  verifySSL: verify_ssl
1485
1510
  });
1486
1511
  this.token = "";