@asgardeo/javascript 0.22.0 → 0.23.1
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/AsgardeoJavaScriptClient.d.ts +85 -1
- package/dist/AsgardeoJavaScriptClient.d.ts.map +1 -1
- package/dist/cjs/index.js +236 -10
- package/dist/cjs/index.js.map +4 -4
- package/dist/edge/index.js +236 -9
- package/dist/edge/index.js.map +4 -4
- package/dist/index.d.ts +63 -44
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +236 -9
- package/dist/index.js.map +4 -4
- package/dist/models/agent.d.ts +3 -3
- package/dist/models/agent.d.ts.map +1 -1
- package/dist/models/organization.d.ts +11 -1
- package/dist/models/organization.d.ts.map +1 -1
- package/dist/models/token.d.ts +1 -1
- package/package.json +2 -2
|
@@ -23,17 +23,49 @@ import { Config, SignInOptions, SignOutOptions, SignUpOptions } from './models/c
|
|
|
23
23
|
import { Crypto } from './models/crypto';
|
|
24
24
|
import { EmbeddedFlowExecuteRequestPayload, EmbeddedFlowExecuteResponse } from './models/embedded-flow';
|
|
25
25
|
import { OIDCDiscoveryApiResponse } from './models/oidc-discovery';
|
|
26
|
-
import { AllOrganizationsApiResponse, Organization } from './models/organization';
|
|
26
|
+
import { AllOrganizationsApiResponse, Organization, OrgDiscoveryType } from './models/organization';
|
|
27
27
|
import { Storage } from './models/store';
|
|
28
28
|
import { TokenExchangeRequestConfig, TokenResponse } from './models/token';
|
|
29
29
|
import { User, UserProfile } from './models/user';
|
|
30
|
+
/**
|
|
31
|
+
* Options accepted by {@link AsgardeoJavaScriptClient.getOrgAuthorizationUrl}.
|
|
32
|
+
*/
|
|
33
|
+
export interface OrgAuthorizationUrlOptions {
|
|
34
|
+
/**
|
|
35
|
+
* Additional query parameters to append to the authorization URL.
|
|
36
|
+
*/
|
|
37
|
+
additionalParams?: Record<string, string>;
|
|
38
|
+
/**
|
|
39
|
+
* Optional agent configuration. When provided, the resulting URL is
|
|
40
|
+
* decorated with `requested_actor=<agentID>` so the issued user token is
|
|
41
|
+
* delegated on-behalf-of the agent.
|
|
42
|
+
*/
|
|
43
|
+
agentConfig?: AgentConfig;
|
|
44
|
+
/**
|
|
45
|
+
* When `true`, the `fidp=OrganizationSSO` query parameter is omitted so the
|
|
46
|
+
* enhanced organization authentication flow can take over discovery.
|
|
47
|
+
* Defaults to `false`.
|
|
48
|
+
*/
|
|
49
|
+
isEnhancedOrgAuth?: boolean;
|
|
50
|
+
/**
|
|
51
|
+
* Optional `resource` query parameter to forward to the authorize endpoint.
|
|
52
|
+
*/
|
|
53
|
+
resource?: string;
|
|
54
|
+
/**
|
|
55
|
+
* Optional `state` value to seed request correlation with. If omitted, the
|
|
56
|
+
* underlying SDK generates one.
|
|
57
|
+
*/
|
|
58
|
+
state?: string;
|
|
59
|
+
}
|
|
30
60
|
declare class AsgardeoJavaScriptClient<T = Config> implements AsgardeoClient<T> {
|
|
31
61
|
private cacheStore;
|
|
32
62
|
private cryptoUtils;
|
|
33
63
|
private auth;
|
|
34
64
|
private storageManager;
|
|
35
65
|
private baseURL;
|
|
66
|
+
private initPromise;
|
|
36
67
|
constructor(config?: AuthClientConfig<T>, cacheStore?: Storage, cryptoUtils?: Crypto);
|
|
68
|
+
protected ensureInitialized(): Promise<void>;
|
|
37
69
|
getDiscoveryResponse(): Promise<OIDCDiscoveryApiResponse | null>;
|
|
38
70
|
switchOrganization(_organization: Organization, _sessionId?: string): Promise<TokenResponse | Response>;
|
|
39
71
|
initialize(_config: T, _storage?: Storage): Promise<boolean>;
|
|
@@ -61,6 +93,58 @@ declare class AsgardeoJavaScriptClient<T = Config> implements AsgardeoClient<T>
|
|
|
61
93
|
getAgentToken(agentConfig: AgentConfig): Promise<TokenResponse>;
|
|
62
94
|
getOBOSignInURL(agentConfig: AgentConfig): Promise<string>;
|
|
63
95
|
getOBOToken(agentConfig: AgentConfig, authCodeResponse: AuthCodeResponse): Promise<TokenResponse>;
|
|
96
|
+
/**
|
|
97
|
+
* Builds a `/oauth2/authorize` URL targeting a specific child organization.
|
|
98
|
+
*
|
|
99
|
+
* The target organization can be identified by its UUID (`orgID`), handle
|
|
100
|
+
* (`orgHandle`), display name (`org`) or via email-domain based discovery
|
|
101
|
+
* (`emailDomain`).
|
|
102
|
+
*
|
|
103
|
+
* @param orgDiscoveryType - The organization discovery strategy to use.
|
|
104
|
+
* @param discoveryInput - The identifier whose meaning depends on
|
|
105
|
+
* `orgDiscoveryType` (UUID, handle, name or email).
|
|
106
|
+
* @param options - Optional state, resource, agent delegation and
|
|
107
|
+
* additional query parameters.
|
|
108
|
+
* @returns The fully-built authorization URL.
|
|
109
|
+
*/
|
|
110
|
+
getOrgAuthorizationUrl(orgDiscoveryType: OrgDiscoveryType, discoveryInput: string, options?: OrgAuthorizationUrlOptions): Promise<string>;
|
|
111
|
+
/**
|
|
112
|
+
* Exchanges an existing access token for one scoped to a target organization,
|
|
113
|
+
* using the `organization_switch` grant type.
|
|
114
|
+
*
|
|
115
|
+
* Unlike {@link AsgardeoJavaScriptClient.exchangeToken} this method does
|
|
116
|
+
* not require an active SDK session — the caller supplies the source
|
|
117
|
+
* access token directly. This makes it safe to use from server-side agent
|
|
118
|
+
* flows where there is no user session yet.
|
|
119
|
+
*
|
|
120
|
+
* @param token - The current access token to be switched.
|
|
121
|
+
* @param switchingOrganization - The ID/UUID of the target organization.
|
|
122
|
+
* @param scopes - Optional list of scopes to request for the switched token.
|
|
123
|
+
* @returns A normalized {@link TokenResponse} for the switched organization.
|
|
124
|
+
*/
|
|
125
|
+
switchTokenToOrganization(token: string, switchingOrganization: string, scopes?: string[]): Promise<TokenResponse>;
|
|
126
|
+
/**
|
|
127
|
+
* Resolves the OAuth2 token endpoint URL.
|
|
128
|
+
*
|
|
129
|
+
* Prefers the value advertised by the OIDC well-known document (when it
|
|
130
|
+
* has already been loaded into the storage manager) and falls back to
|
|
131
|
+
* `${baseURL}/oauth2/token` derived from the SDK configuration.
|
|
132
|
+
*/
|
|
133
|
+
private resolveTokenEndpoint;
|
|
134
|
+
/**
|
|
135
|
+
* Authenticates as the agent and switches the issued agent token into a
|
|
136
|
+
* target child organization in a single call.
|
|
137
|
+
*
|
|
138
|
+
* @param agentConfig - Agent credentials used to obtain the parent-org agent token.
|
|
139
|
+
* @param switchingOrganization - The ID/UUID of the target organization.
|
|
140
|
+
* @param orgScopes - Optional scopes to request for the organization-scoped token.
|
|
141
|
+
* @returns A normalized {@link TokenResponse} scoped to the target organization.
|
|
142
|
+
*/
|
|
143
|
+
getOrganizationAgentToken(agentConfig: AgentConfig, switchingOrganization: string, orgScopes?: string[]): Promise<TokenResponse>;
|
|
144
|
+
/**
|
|
145
|
+
* Builds the custom query-parameter map for an organization-scoped authorization request.
|
|
146
|
+
*/
|
|
147
|
+
private static buildOrgAuthorizationParams;
|
|
64
148
|
}
|
|
65
149
|
export default AsgardeoJavaScriptClient;
|
|
66
150
|
//# sourceMappingURL=AsgardeoJavaScriptClient.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AsgardeoJavaScriptClient.d.ts","sourceRoot":"","sources":["../src/AsgardeoJavaScriptClient.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAGH,OAAO,EAAC,gBAAgB,EAAC,MAAM,mCAAmC,CAAC;AAKnE,OAAO,EAAC,WAAW,EAAC,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAC,gBAAgB,EAAC,MAAM,6BAA6B,CAAC;AAC7D,OAAO,EAAC,cAAc,EAAC,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAC,MAAM,EAAE,aAAa,EAAE,cAAc,EAAE,aAAa,EAAC,MAAM,iBAAiB,CAAC;AACrF,OAAO,EAAC,MAAM,EAAC,MAAM,iBAAiB,CAAC;AACvC,OAAO,EAEL,iCAAiC,EACjC,2BAA2B,EAC5B,MAAM,wBAAwB,CAAC;AAOhC,OAAO,EAAC,wBAAwB,EAAC,MAAM,yBAAyB,CAAC;AAC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,CAAC,IAAI,CAAC;IAE9C,MAAM,CAAC,OAAO,EAAE,iCAAiC,GAAG,OAAO,CAAC,2BAA2B,CAAC;IAS3E,aAAa,CAAC,WAAW,EAAE,WAAW,GAAG,OAAO,CAAC,aAAa,CAAC;IA8D/D,eAAe,CAAC,WAAW,EAAE,WAAW,GAAG,OAAO,CAAC,MAAM,CAAC;IAe1D,WAAW,CAAC,WAAW,EAAE,WAAW,EAAE,gBAAgB,EAAE,gBAAgB,GAAG,OAAO,CAAC,aAAa,CAAC;IAkB9G;;;;;;;;;;;;;OAaG;IACU,sBAAsB,CACjC,gBAAgB,EAAE,gBAAgB,EAClC,cAAc,EAAE,MAAM,EACtB,OAAO,GAAE,0BAA+B,GACvC,OAAO,CAAC,MAAM,CAAC;IAiBlB;;;;;;;;;;;;;OAaG;IACU,yBAAyB,CACpC,KAAK,EAAE,MAAM,EACb,qBAAqB,EAAE,MAAM,EAC7B,MAAM,CAAC,EAAE,MAAM,EAAE,GAChB,OAAO,CAAC,aAAa,CAAC;IAsFzB;;;;;;OAMG;YACW,oBAAoB;IAmBlC;;;;;;;;OAQG;IACU,yBAAyB,CACpC,WAAW,EAAE,WAAW,EACxB,qBAAqB,EAAE,MAAM,EAC7B,SAAS,CAAC,EAAE,MAAM,EAAE,GACnB,OAAO,CAAC,aAAa,CAAC;IAUzB;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,2BAA2B;CAgE3C;AAED,eAAe,wBAAwB,CAAC"}
|
package/dist/cjs/index.js
CHANGED
|
@@ -31,7 +31,6 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
31
31
|
// src/index.ts
|
|
32
32
|
var index_exports = {};
|
|
33
33
|
__export(index_exports, {
|
|
34
|
-
AgentConfig: () => AgentConfig,
|
|
35
34
|
ApplicationNativeAuthenticationConstants: () => ApplicationNativeAuthenticationConstants_default,
|
|
36
35
|
AsgardeoAPIError: () => AsgardeoAPIError,
|
|
37
36
|
AsgardeoAuthClient: () => AsgardeoAuthClient,
|
|
@@ -4086,12 +4085,6 @@ var FlowMode = /* @__PURE__ */ ((FlowMode2) => {
|
|
|
4086
4085
|
return FlowMode2;
|
|
4087
4086
|
})(FlowMode || {});
|
|
4088
4087
|
|
|
4089
|
-
// src/models/agent.ts
|
|
4090
|
-
var AgentConfig;
|
|
4091
|
-
((AgentConfig2) => {
|
|
4092
|
-
AgentConfig2.DEFAULT_AUTHENTICATOR_NAME = "Username & Password";
|
|
4093
|
-
})(AgentConfig || (AgentConfig = {}));
|
|
4094
|
-
|
|
4095
4088
|
// src/models/scim2-schema.ts
|
|
4096
4089
|
var WellKnownSchemaIds = /* @__PURE__ */ ((WellKnownSchemaIds2) => {
|
|
4097
4090
|
WellKnownSchemaIds2["Core"] = "urn:ietf:params:scim:schemas:core:2.0";
|
|
@@ -4192,24 +4185,54 @@ var DefaultCrypto = class {
|
|
|
4192
4185
|
}
|
|
4193
4186
|
};
|
|
4194
4187
|
|
|
4188
|
+
// src/models/agent.ts
|
|
4189
|
+
var AgentConfig;
|
|
4190
|
+
((AgentConfig2) => {
|
|
4191
|
+
AgentConfig2.DEFAULT_AUTHENTICATOR_NAME = "Username & Password";
|
|
4192
|
+
})(AgentConfig || (AgentConfig = {}));
|
|
4193
|
+
|
|
4195
4194
|
// src/AsgardeoJavaScriptClient.ts
|
|
4196
|
-
var
|
|
4195
|
+
var RESERVED_AUTH_KEYS = /* @__PURE__ */ new Set([
|
|
4196
|
+
"client_id",
|
|
4197
|
+
"redirect_uri",
|
|
4198
|
+
"scope",
|
|
4199
|
+
"state",
|
|
4200
|
+
"response_type",
|
|
4201
|
+
"resource",
|
|
4202
|
+
"fidp",
|
|
4203
|
+
"requested_actor",
|
|
4204
|
+
"orgId",
|
|
4205
|
+
"orgHandle",
|
|
4206
|
+
"org",
|
|
4207
|
+
"login_hint",
|
|
4208
|
+
"orgDiscoveryType",
|
|
4209
|
+
"code_challenge",
|
|
4210
|
+
"code_challenge_method"
|
|
4211
|
+
]);
|
|
4212
|
+
var AsgardeoJavaScriptClient = class _AsgardeoJavaScriptClient {
|
|
4197
4213
|
constructor(config, cacheStore, cryptoUtils) {
|
|
4198
4214
|
__publicField(this, "cacheStore");
|
|
4199
4215
|
__publicField(this, "cryptoUtils");
|
|
4200
4216
|
__publicField(this, "auth");
|
|
4201
4217
|
__publicField(this, "storageManager");
|
|
4202
4218
|
__publicField(this, "baseURL");
|
|
4219
|
+
__publicField(this, "initPromise");
|
|
4203
4220
|
this.cacheStore = cacheStore ?? new DefaultCacheStore();
|
|
4204
4221
|
this.cryptoUtils = cryptoUtils ?? new DefaultCrypto();
|
|
4205
4222
|
this.auth = new AsgardeoAuthClient();
|
|
4206
4223
|
if (config) {
|
|
4207
|
-
this.auth.initialize(config, this.cacheStore, this.cryptoUtils);
|
|
4224
|
+
this.initPromise = this.auth.initialize(config, this.cacheStore, this.cryptoUtils);
|
|
4208
4225
|
this.storageManager = this.auth.getStorageManager();
|
|
4209
4226
|
}
|
|
4210
4227
|
this.baseURL = config?.baseUrl ?? "";
|
|
4211
4228
|
}
|
|
4229
|
+
async ensureInitialized() {
|
|
4230
|
+
if (this.initPromise) {
|
|
4231
|
+
await this.initPromise;
|
|
4232
|
+
}
|
|
4233
|
+
}
|
|
4212
4234
|
async getDiscoveryResponse() {
|
|
4235
|
+
await this.ensureInitialized();
|
|
4213
4236
|
if (!this.storageManager) {
|
|
4214
4237
|
return null;
|
|
4215
4238
|
}
|
|
@@ -4284,6 +4307,15 @@ var AsgardeoJavaScriptClient = class {
|
|
|
4284
4307
|
}
|
|
4285
4308
|
/* eslint-enable class-methods-use-this, @typescript-eslint/no-unused-vars */
|
|
4286
4309
|
async getAgentToken(agentConfig) {
|
|
4310
|
+
await this.ensureInitialized();
|
|
4311
|
+
if (!agentConfig?.agentID) {
|
|
4312
|
+
throw new Error("agentConfig.agentID is required for getAgentToken().");
|
|
4313
|
+
}
|
|
4314
|
+
if (!agentConfig.agentSecret) {
|
|
4315
|
+
throw new Error(
|
|
4316
|
+
"agentConfig.agentSecret is required for getAgentToken(). The agent must authenticate against the token endpoint."
|
|
4317
|
+
);
|
|
4318
|
+
}
|
|
4287
4319
|
const customParam = {
|
|
4288
4320
|
response_mode: "direct"
|
|
4289
4321
|
};
|
|
@@ -4323,6 +4355,7 @@ var AsgardeoJavaScriptClient = class {
|
|
|
4323
4355
|
);
|
|
4324
4356
|
}
|
|
4325
4357
|
async getOBOSignInURL(agentConfig) {
|
|
4358
|
+
await this.ensureInitialized();
|
|
4326
4359
|
const customParam = {
|
|
4327
4360
|
requested_actor: agentConfig.agentID
|
|
4328
4361
|
};
|
|
@@ -4347,6 +4380,200 @@ var AsgardeoJavaScriptClient = class {
|
|
|
4347
4380
|
tokenRequestConfig
|
|
4348
4381
|
);
|
|
4349
4382
|
}
|
|
4383
|
+
/**
|
|
4384
|
+
* Builds a `/oauth2/authorize` URL targeting a specific child organization.
|
|
4385
|
+
*
|
|
4386
|
+
* The target organization can be identified by its UUID (`orgID`), handle
|
|
4387
|
+
* (`orgHandle`), display name (`org`) or via email-domain based discovery
|
|
4388
|
+
* (`emailDomain`).
|
|
4389
|
+
*
|
|
4390
|
+
* @param orgDiscoveryType - The organization discovery strategy to use.
|
|
4391
|
+
* @param discoveryInput - The identifier whose meaning depends on
|
|
4392
|
+
* `orgDiscoveryType` (UUID, handle, name or email).
|
|
4393
|
+
* @param options - Optional state, resource, agent delegation and
|
|
4394
|
+
* additional query parameters.
|
|
4395
|
+
* @returns The fully-built authorization URL.
|
|
4396
|
+
*/
|
|
4397
|
+
async getOrgAuthorizationUrl(orgDiscoveryType, discoveryInput, options = {}) {
|
|
4398
|
+
await this.ensureInitialized();
|
|
4399
|
+
const customParam = _AsgardeoJavaScriptClient.buildOrgAuthorizationParams(
|
|
4400
|
+
orgDiscoveryType,
|
|
4401
|
+
discoveryInput,
|
|
4402
|
+
options
|
|
4403
|
+
);
|
|
4404
|
+
const authURL = await this.auth.getSignInUrl(customParam);
|
|
4405
|
+
if (!authURL) {
|
|
4406
|
+
throw new Error("Could not build organization authorization URL");
|
|
4407
|
+
}
|
|
4408
|
+
return authURL.toString();
|
|
4409
|
+
}
|
|
4410
|
+
/**
|
|
4411
|
+
* Exchanges an existing access token for one scoped to a target organization,
|
|
4412
|
+
* using the `organization_switch` grant type.
|
|
4413
|
+
*
|
|
4414
|
+
* Unlike {@link AsgardeoJavaScriptClient.exchangeToken} this method does
|
|
4415
|
+
* not require an active SDK session — the caller supplies the source
|
|
4416
|
+
* access token directly. This makes it safe to use from server-side agent
|
|
4417
|
+
* flows where there is no user session yet.
|
|
4418
|
+
*
|
|
4419
|
+
* @param token - The current access token to be switched.
|
|
4420
|
+
* @param switchingOrganization - The ID/UUID of the target organization.
|
|
4421
|
+
* @param scopes - Optional list of scopes to request for the switched token.
|
|
4422
|
+
* @returns A normalized {@link TokenResponse} for the switched organization.
|
|
4423
|
+
*/
|
|
4424
|
+
async switchTokenToOrganization(token, switchingOrganization, scopes) {
|
|
4425
|
+
await this.ensureInitialized();
|
|
4426
|
+
if (!token) {
|
|
4427
|
+
throw new Error("Token is required for organization switch.");
|
|
4428
|
+
}
|
|
4429
|
+
if (!switchingOrganization) {
|
|
4430
|
+
throw new Error("switchingOrganization is required.");
|
|
4431
|
+
}
|
|
4432
|
+
if (!this.storageManager) {
|
|
4433
|
+
throw new Error("Client is not initialized. Call initialize() before switching organizations.");
|
|
4434
|
+
}
|
|
4435
|
+
const configData = await this.storageManager.getConfigData();
|
|
4436
|
+
if (!configData) {
|
|
4437
|
+
throw new Error("Client configuration is unavailable. Initialize the client before switching organizations.");
|
|
4438
|
+
}
|
|
4439
|
+
const tokenEndpoint = await this.resolveTokenEndpoint();
|
|
4440
|
+
const body = new URLSearchParams();
|
|
4441
|
+
const { clientId, clientSecret } = configData;
|
|
4442
|
+
if (!clientId || clientId.trim().length === 0) {
|
|
4443
|
+
throw new Error("clientId is required in the client configuration for organization switch.");
|
|
4444
|
+
}
|
|
4445
|
+
const hasSecret = Boolean(clientSecret && clientSecret.trim().length > 0);
|
|
4446
|
+
body.set("grant_type", "organization_switch");
|
|
4447
|
+
body.set("token", token);
|
|
4448
|
+
body.set("switching_organization", switchingOrganization);
|
|
4449
|
+
body.set("client_id", clientId);
|
|
4450
|
+
if (hasSecret) {
|
|
4451
|
+
body.set("client_secret", clientSecret);
|
|
4452
|
+
}
|
|
4453
|
+
if (scopes && scopes.length > 0) {
|
|
4454
|
+
body.set("scope", scopes.join(" "));
|
|
4455
|
+
}
|
|
4456
|
+
let response;
|
|
4457
|
+
try {
|
|
4458
|
+
response = await fetch(tokenEndpoint, {
|
|
4459
|
+
body,
|
|
4460
|
+
headers: {
|
|
4461
|
+
Accept: "application/json",
|
|
4462
|
+
"Content-Type": "application/x-www-form-urlencoded"
|
|
4463
|
+
},
|
|
4464
|
+
method: "POST"
|
|
4465
|
+
});
|
|
4466
|
+
} catch (error2) {
|
|
4467
|
+
throw new Error(`Organization switch request failed: ${error2?.message ?? String(error2)}`);
|
|
4468
|
+
}
|
|
4469
|
+
if (!response.ok) {
|
|
4470
|
+
let errorBody;
|
|
4471
|
+
try {
|
|
4472
|
+
errorBody = JSON.stringify(await response.json());
|
|
4473
|
+
} catch {
|
|
4474
|
+
errorBody = response.statusText;
|
|
4475
|
+
}
|
|
4476
|
+
throw new Error(`Organization switch failed (${response.status}): ${errorBody}`);
|
|
4477
|
+
}
|
|
4478
|
+
const parsed = await response.json();
|
|
4479
|
+
return {
|
|
4480
|
+
accessToken: parsed.access_token,
|
|
4481
|
+
createdAt: parsed.created_at ?? Date.now(),
|
|
4482
|
+
expiresIn: parsed.expires_in,
|
|
4483
|
+
idToken: parsed.id_token,
|
|
4484
|
+
refreshToken: parsed.refresh_token,
|
|
4485
|
+
scope: parsed.scope,
|
|
4486
|
+
tokenType: parsed.token_type
|
|
4487
|
+
};
|
|
4488
|
+
}
|
|
4489
|
+
/**
|
|
4490
|
+
* Resolves the OAuth2 token endpoint URL.
|
|
4491
|
+
*
|
|
4492
|
+
* Prefers the value advertised by the OIDC well-known document (when it
|
|
4493
|
+
* has already been loaded into the storage manager) and falls back to
|
|
4494
|
+
* `${baseURL}/oauth2/token` derived from the SDK configuration.
|
|
4495
|
+
*/
|
|
4496
|
+
async resolveTokenEndpoint() {
|
|
4497
|
+
const discovery = this.storageManager ? await this.storageManager.loadOpenIDProviderConfiguration() : null;
|
|
4498
|
+
const discovered = discovery?.token_endpoint;
|
|
4499
|
+
if (discovered && discovered.trim().length > 0) {
|
|
4500
|
+
return discovered;
|
|
4501
|
+
}
|
|
4502
|
+
if (this.baseURL && this.baseURL.trim().length > 0) {
|
|
4503
|
+
return `${this.baseURL.replace(/\/$/, "")}/oauth2/token`;
|
|
4504
|
+
}
|
|
4505
|
+
throw new Error(
|
|
4506
|
+
"Unable to resolve the token endpoint. Provide a baseUrl in the client configuration or ensure OIDC discovery has been performed."
|
|
4507
|
+
);
|
|
4508
|
+
}
|
|
4509
|
+
/**
|
|
4510
|
+
* Authenticates as the agent and switches the issued agent token into a
|
|
4511
|
+
* target child organization in a single call.
|
|
4512
|
+
*
|
|
4513
|
+
* @param agentConfig - Agent credentials used to obtain the parent-org agent token.
|
|
4514
|
+
* @param switchingOrganization - The ID/UUID of the target organization.
|
|
4515
|
+
* @param orgScopes - Optional scopes to request for the organization-scoped token.
|
|
4516
|
+
* @returns A normalized {@link TokenResponse} scoped to the target organization.
|
|
4517
|
+
*/
|
|
4518
|
+
async getOrganizationAgentToken(agentConfig, switchingOrganization, orgScopes) {
|
|
4519
|
+
if (!switchingOrganization) {
|
|
4520
|
+
throw new Error("switchingOrganization is required.");
|
|
4521
|
+
}
|
|
4522
|
+
const agentToken = await this.getAgentToken(agentConfig);
|
|
4523
|
+
return this.switchTokenToOrganization(agentToken.accessToken, switchingOrganization, orgScopes);
|
|
4524
|
+
}
|
|
4525
|
+
/**
|
|
4526
|
+
* Builds the custom query-parameter map for an organization-scoped authorization request.
|
|
4527
|
+
*/
|
|
4528
|
+
static buildOrgAuthorizationParams(orgDiscoveryType, discoveryInput, options) {
|
|
4529
|
+
const trimmedValue = (discoveryInput ?? "").trim();
|
|
4530
|
+
if (!trimmedValue) {
|
|
4531
|
+
throw new Error("discoveryInput is required.");
|
|
4532
|
+
}
|
|
4533
|
+
const customParam = {};
|
|
4534
|
+
if (!options.isEnhancedOrgAuth) {
|
|
4535
|
+
customParam["fidp"] = "OrganizationSSO";
|
|
4536
|
+
}
|
|
4537
|
+
switch (orgDiscoveryType) {
|
|
4538
|
+
case "orgID":
|
|
4539
|
+
customParam["orgId"] = trimmedValue;
|
|
4540
|
+
break;
|
|
4541
|
+
case "orgHandle":
|
|
4542
|
+
customParam["orgHandle"] = trimmedValue;
|
|
4543
|
+
break;
|
|
4544
|
+
case "org":
|
|
4545
|
+
customParam["org"] = trimmedValue;
|
|
4546
|
+
break;
|
|
4547
|
+
case "emailDomain":
|
|
4548
|
+
customParam["login_hint"] = trimmedValue;
|
|
4549
|
+
customParam["orgDiscoveryType"] = "emailDomain";
|
|
4550
|
+
break;
|
|
4551
|
+
default:
|
|
4552
|
+
throw new Error(`Unsupported orgDiscoveryType: ${orgDiscoveryType}`);
|
|
4553
|
+
}
|
|
4554
|
+
if (options.resource) {
|
|
4555
|
+
customParam["resource"] = options.resource;
|
|
4556
|
+
}
|
|
4557
|
+
if (options.state) {
|
|
4558
|
+
customParam["state"] = options.state;
|
|
4559
|
+
}
|
|
4560
|
+
if (options.agentConfig) {
|
|
4561
|
+
if (!options.agentConfig.agentID || options.agentConfig.agentID.trim().length === 0) {
|
|
4562
|
+
throw new Error("agentConfig.agentID is required when agentConfig is provided.");
|
|
4563
|
+
}
|
|
4564
|
+
customParam["requested_actor"] = options.agentConfig.agentID;
|
|
4565
|
+
}
|
|
4566
|
+
if (options.additionalParams) {
|
|
4567
|
+
const conflicts = Object.keys(options.additionalParams).filter(
|
|
4568
|
+
(key) => RESERVED_AUTH_KEYS.has(key)
|
|
4569
|
+
);
|
|
4570
|
+
if (conflicts.length > 0) {
|
|
4571
|
+
throw new Error(`Reserved authorization parameters cannot be overridden: ${conflicts.sort().join(", ")}`);
|
|
4572
|
+
}
|
|
4573
|
+
Object.assign(customParam, options.additionalParams);
|
|
4574
|
+
}
|
|
4575
|
+
return customParam;
|
|
4576
|
+
}
|
|
4350
4577
|
};
|
|
4351
4578
|
var AsgardeoJavaScriptClient_default = AsgardeoJavaScriptClient;
|
|
4352
4579
|
|
|
@@ -5681,7 +5908,6 @@ __publicField(_HttpClient, "DEFAULT_HANDLER_DISABLE_TIMEOUT", 1e3);
|
|
|
5681
5908
|
var HttpClient = _HttpClient;
|
|
5682
5909
|
// Annotate the CommonJS export names for ESM import in node:
|
|
5683
5910
|
0 && (module.exports = {
|
|
5684
|
-
AgentConfig,
|
|
5685
5911
|
ApplicationNativeAuthenticationConstants,
|
|
5686
5912
|
AsgardeoAPIError,
|
|
5687
5913
|
AsgardeoAuthClient,
|