@frontegg/rest-api 7.101.0-alpha.2 → 7.101.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/auth/index.d.ts +1 -0
- package/auth/index.js +24 -8
- package/index.js +1 -1
- package/node/auth/index.js +24 -8
- package/node/index.js +1 -1
- package/package.json +1 -1
package/auth/index.d.ts
CHANGED
|
@@ -23,6 +23,7 @@ export declare class AuthenticationApi extends BaseApiClient {
|
|
|
23
23
|
*/
|
|
24
24
|
shouldLoadMeAuthorization(): boolean;
|
|
25
25
|
generateLoginResponseV3: (loginResponse: ILoginResponse) => Promise<ILoginResponseV3>;
|
|
26
|
+
private resolveSessionTenant;
|
|
26
27
|
generateLoginResponseFromOAuthResponse: (oauthResponse: IOAuthTokenResponse) => Promise<ILoginResponse>;
|
|
27
28
|
generateLoginResponseFromOAuthResponseV2: (oauthResponse: IOAuthTokenResponse) => Promise<ILoginResponseV3>;
|
|
28
29
|
/**
|
package/auth/index.js
CHANGED
|
@@ -67,14 +67,12 @@ export class AuthenticationApi extends BaseApiClient {
|
|
|
67
67
|
const [me, currentUserTenants] = await Promise.all([this.getMeAndEntitlements(), getCurrentUserTenantsFunction(this.appName)()]);
|
|
68
68
|
const decodedContent = accessToken ? jwtDecode(accessToken) : {};
|
|
69
69
|
const user = _extends({}, loginResponse, decodedContent, me);
|
|
70
|
-
|
|
71
|
-
setTabTenantInSessionStorage(user.tenantId);
|
|
72
|
-
}
|
|
70
|
+
const activeTenant = this.resolveSessionTenant(contextHolder, user, decodedContent, currentUserTenants);
|
|
73
71
|
contextHolder.setUser(user);
|
|
74
72
|
return {
|
|
75
73
|
user,
|
|
76
74
|
tenants: currentUserTenants.tenants,
|
|
77
|
-
activeTenant
|
|
75
|
+
activeTenant
|
|
78
76
|
};
|
|
79
77
|
};
|
|
80
78
|
this.generateLoginResponseFromOAuthResponse = async oauthResponse => {
|
|
@@ -104,14 +102,12 @@ export class AuthenticationApi extends BaseApiClient {
|
|
|
104
102
|
}, decodedContent, me, {
|
|
105
103
|
expiresIn: oauthResponse.expires_in || 300
|
|
106
104
|
});
|
|
107
|
-
|
|
108
|
-
setTabTenantInSessionStorage(user.tenantId);
|
|
109
|
-
}
|
|
105
|
+
const activeTenant = this.resolveSessionTenant(contextHolder, user, decodedContent, currentUserTenants);
|
|
110
106
|
contextHolder.setUser(user);
|
|
111
107
|
return {
|
|
112
108
|
user,
|
|
113
109
|
tenants: currentUserTenants.tenants,
|
|
114
|
-
activeTenant
|
|
110
|
+
activeTenant
|
|
115
111
|
};
|
|
116
112
|
};
|
|
117
113
|
this.preLogin = async body => {
|
|
@@ -824,5 +820,25 @@ export class AuthenticationApi extends BaseApiClient {
|
|
|
824
820
|
const [shouldLoadAuthorization] = FeatureFlags.getFeatureFlags([LOAD_AUTHORIZATION_FF], this.appName);
|
|
825
821
|
return shouldLoadAuthorization;
|
|
826
822
|
}
|
|
823
|
+
resolveSessionTenant(contextHolder, user, decodedContent, currentUserTenants) {
|
|
824
|
+
let {
|
|
825
|
+
activeTenant
|
|
826
|
+
} = currentUserTenants;
|
|
827
|
+
if (contextHolder.isSessionPerTenantEnabled()) {
|
|
828
|
+
if (decodedContent.tenantId) {
|
|
829
|
+
user.tenantId = decodedContent.tenantId;
|
|
830
|
+
}
|
|
831
|
+
if (user.tenantId) {
|
|
832
|
+
setTabTenantInSessionStorage(user.tenantId);
|
|
833
|
+
// The server's activeTenant may reflect a different tab's tenant switch.
|
|
834
|
+
// Correct it to match the JWT's tenant for this tab.
|
|
835
|
+
const matchingTenant = currentUserTenants.tenants.find(t => t.tenantId === user.tenantId);
|
|
836
|
+
if (matchingTenant) {
|
|
837
|
+
activeTenant = matchingTenant;
|
|
838
|
+
}
|
|
839
|
+
}
|
|
840
|
+
}
|
|
841
|
+
return activeTenant;
|
|
842
|
+
}
|
|
827
843
|
}
|
|
828
844
|
export default new AuthenticationApi('default');
|
package/index.js
CHANGED
package/node/auth/index.js
CHANGED
|
@@ -132,14 +132,12 @@ class AuthenticationApi extends _BaseApiClient.BaseApiClient {
|
|
|
132
132
|
const [me, currentUserTenants] = await Promise.all([this.getMeAndEntitlements(), (0, _utils.getCurrentUserTenantsFunction)(this.appName)()]);
|
|
133
133
|
const decodedContent = accessToken ? (0, _jwt.jwtDecode)(accessToken) : {};
|
|
134
134
|
const user = (0, _extends2.default)({}, loginResponse, decodedContent, me);
|
|
135
|
-
|
|
136
|
-
(0, _utils.setTabTenantInSessionStorage)(user.tenantId);
|
|
137
|
-
}
|
|
135
|
+
const activeTenant = this.resolveSessionTenant(contextHolder, user, decodedContent, currentUserTenants);
|
|
138
136
|
contextHolder.setUser(user);
|
|
139
137
|
return {
|
|
140
138
|
user,
|
|
141
139
|
tenants: currentUserTenants.tenants,
|
|
142
|
-
activeTenant
|
|
140
|
+
activeTenant
|
|
143
141
|
};
|
|
144
142
|
};
|
|
145
143
|
this.generateLoginResponseFromOAuthResponse = async oauthResponse => {
|
|
@@ -169,14 +167,12 @@ class AuthenticationApi extends _BaseApiClient.BaseApiClient {
|
|
|
169
167
|
}, decodedContent, me, {
|
|
170
168
|
expiresIn: oauthResponse.expires_in || 300
|
|
171
169
|
});
|
|
172
|
-
|
|
173
|
-
(0, _utils.setTabTenantInSessionStorage)(user.tenantId);
|
|
174
|
-
}
|
|
170
|
+
const activeTenant = this.resolveSessionTenant(contextHolder, user, decodedContent, currentUserTenants);
|
|
175
171
|
contextHolder.setUser(user);
|
|
176
172
|
return {
|
|
177
173
|
user,
|
|
178
174
|
tenants: currentUserTenants.tenants,
|
|
179
|
-
activeTenant
|
|
175
|
+
activeTenant
|
|
180
176
|
};
|
|
181
177
|
};
|
|
182
178
|
this.preLogin = async body => {
|
|
@@ -889,6 +885,26 @@ class AuthenticationApi extends _BaseApiClient.BaseApiClient {
|
|
|
889
885
|
const [shouldLoadAuthorization] = _featureFlags.FeatureFlags.getFeatureFlags([_interfaces.LOAD_AUTHORIZATION_FF], this.appName);
|
|
890
886
|
return shouldLoadAuthorization;
|
|
891
887
|
}
|
|
888
|
+
resolveSessionTenant(contextHolder, user, decodedContent, currentUserTenants) {
|
|
889
|
+
let {
|
|
890
|
+
activeTenant
|
|
891
|
+
} = currentUserTenants;
|
|
892
|
+
if (contextHolder.isSessionPerTenantEnabled()) {
|
|
893
|
+
if (decodedContent.tenantId) {
|
|
894
|
+
user.tenantId = decodedContent.tenantId;
|
|
895
|
+
}
|
|
896
|
+
if (user.tenantId) {
|
|
897
|
+
(0, _utils.setTabTenantInSessionStorage)(user.tenantId);
|
|
898
|
+
// The server's activeTenant may reflect a different tab's tenant switch.
|
|
899
|
+
// Correct it to match the JWT's tenant for this tab.
|
|
900
|
+
const matchingTenant = currentUserTenants.tenants.find(t => t.tenantId === user.tenantId);
|
|
901
|
+
if (matchingTenant) {
|
|
902
|
+
activeTenant = matchingTenant;
|
|
903
|
+
}
|
|
904
|
+
}
|
|
905
|
+
}
|
|
906
|
+
return activeTenant;
|
|
907
|
+
}
|
|
892
908
|
}
|
|
893
909
|
exports.AuthenticationApi = AuthenticationApi;
|
|
894
910
|
var _default = new AuthenticationApi('default');
|
package/node/index.js
CHANGED