codemie-sdk 0.1.397 → 0.1.398

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.cjs CHANGED
@@ -103,13 +103,31 @@ var KeycloakCredentials = class {
103
103
  async getToken() {
104
104
  const { serverUrl, realmName } = this.config;
105
105
  const url = `${serverUrl}/realms/${realmName}/protocol/openid-connect/token`;
106
- const payload = this.config.username && this.config.password ? this.createResourceOwnerCredentialsPayload() : this.createClientCredentialsPayload();
106
+ let payload;
107
+ if (this.config.externalToken && this.config.externalIdp) {
108
+ payload = this.createTokenExchangePayload();
109
+ } else if (this.config.username && this.config.password) {
110
+ payload = this.createResourceOwnerCredentialsPayload();
111
+ } else {
112
+ payload = this.createClientCredentialsPayload();
113
+ }
107
114
  const { data } = await import_axios.default.post(url, this.createSearchParams(payload), {
108
115
  headers: { "Content-Type": "application/x-www-form-urlencoded" },
109
116
  httpsAgent: this.httpAgent
110
117
  });
111
118
  return data.access_token;
112
119
  }
120
+ createTokenExchangePayload() {
121
+ const { clientId, clientSecret, externalToken, externalIdp } = this.config;
122
+ return {
123
+ grant_type: "urn:ietf:params:oauth:grant-type:token-exchange",
124
+ client_id: clientId || DEFAULT_CLIENT_ID,
125
+ client_secret: clientSecret,
126
+ subject_token: externalToken,
127
+ subject_issuer: externalIdp,
128
+ requested_token_type: "urn:ietf:params:oauth:token-type:access_token"
129
+ };
130
+ }
113
131
  createResourceOwnerCredentialsPayload() {
114
132
  const { username, password, clientId } = this.config;
115
133
  return {
@@ -133,9 +151,12 @@ var KeycloakCredentials = class {
133
151
  );
134
152
  }
135
153
  validateConfigCredentials(config) {
136
- if (!(config.clientId && config.clientSecret || config.username && config.password)) {
154
+ const hasClientCredentials = !!(config.clientId && config.clientSecret);
155
+ const hasUserCredentials = !!(config.username && config.password);
156
+ const hasExternalTokenCredentials = !!(config.externalToken && config.externalIdp);
157
+ if (!hasClientCredentials && !hasUserCredentials && !hasExternalTokenCredentials) {
137
158
  throw new Error(
138
- "Either client credentials (clientId, clientSecret) or user credentials (username, password) must be provided"
159
+ "Either client credentials (clientId, clientSecret), user credentials (username, password), or external token credentials (externalToken, externalIdp) must be provided"
139
160
  );
140
161
  }
141
162
  }
@@ -1551,6 +1572,8 @@ var CodeMieClient = class {
1551
1572
  auth_client_secret,
1552
1573
  username,
1553
1574
  password,
1575
+ external_token,
1576
+ external_idp,
1554
1577
  cookies,
1555
1578
  verify_ssl = true
1556
1579
  } = config;
@@ -1571,6 +1594,8 @@ var CodeMieClient = class {
1571
1594
  clientSecret: auth_client_secret,
1572
1595
  username,
1573
1596
  password,
1597
+ externalToken: external_token,
1598
+ externalIdp: external_idp,
1574
1599
  verifySSL: verify_ssl
1575
1600
  });
1576
1601
  this.token = "";