Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: multitenancy recipe #594

Merged
merged 7 commits into from
Jun 21, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion lib/build/recipe/multitenancy/api/implementation.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ function getAPIInterface() {
const providerInputsFromStatic = options.staticThirdPartyProviders;
const providerConfigsFromCore = tenantConfigRes.thirdParty.providers;
const mergedProviders = configUtils_1.mergeProvidersFromCoreAndStatic(
tenantId,
providerConfigsFromCore,
providerInputsFromStatic
);
Expand Down
8 changes: 6 additions & 2 deletions lib/build/recipe/multitenancy/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export default class Wrapper {
userContext?: any
): Promise<{
status: "OK";
tenantExisted: boolean;
didExist: boolean;
}>;
static getTenantConfig(
tenantId?: string,
Expand All @@ -48,6 +48,7 @@ export default class Wrapper {
tenants: string[];
}>;
static createOrUpdateThirdPartyConfig(
tenantId: string | undefined,
config: ProviderConfig,
skipValidation?: boolean,
userContext?: any
Expand All @@ -68,7 +69,10 @@ export default class Wrapper {
userContext?: any
): Promise<{
status: "OK";
providers: ProviderConfig[];
tenants: {
tenantId: string;
providers: ProviderConfig[];
}[];
}>;
}
export declare let init: typeof Recipe.init;
Expand Down
3 changes: 2 additions & 1 deletion lib/build/recipe/multitenancy/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,11 @@ class Wrapper {
});
});
}
static createOrUpdateThirdPartyConfig(config, skipValidation, userContext) {
static createOrUpdateThirdPartyConfig(tenantId, config, skipValidation, userContext) {
return __awaiter(this, void 0, void 0, function* () {
const recipeInstance = recipe_1.default.getInstanceOrThrowError();
return recipeInstance.recipeInterfaceImpl.createOrUpdateThirdPartyConfig({
tenantId,
config,
skipValidation,
userContext: userContext === undefined ? {} : userContext,
Expand Down
2 changes: 1 addition & 1 deletion lib/build/recipe/multitenancy/recipeImplementation.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// @ts-nocheck
import { RecipeInterface } from "./";
import { Querier } from "../../querier";
export default function getRecipeInterface(_: Querier): RecipeInterface;
export default function getRecipeInterface(querier: Querier): RecipeInterface;
119 changes: 88 additions & 31 deletions lib/build/recipe/multitenancy/recipeImplementation.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,66 +30,123 @@ var __awaiter =
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault =
(this && this.__importDefault) ||
function (mod) {
return mod && mod.__esModule ? mod : { default: mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
function getRecipeInterface(_) {
const normalisedURLPath_1 = __importDefault(require("../../normalisedURLPath"));
const constants_1 = require("./constants");
function getRecipeInterface(querier) {
return {
getTenantId: function ({ tenantIdFromFrontend }) {
return __awaiter(this, void 0, void 0, function* () {
// TODO
// TODO do we need this function?
return tenantIdFromFrontend;
});
},
createOrUpdateTenant: function () {
createOrUpdateTenant: function ({ tenantId, config }) {
return __awaiter(this, void 0, void 0, function* () {
// TODO
throw new Error("Not implemented");
let response = yield querier.sendPutRequest(
new normalisedURLPath_1.default(`/recipe/multitenancy/tenant`),
Object.assign({ tenantId }, config)
);
return response;
});
},
deleteTenant: function () {
deleteTenant: function ({ tenantId }) {
return __awaiter(this, void 0, void 0, function* () {
// TODO
throw new Error("Not implemented");
let response = yield querier.sendPostRequest(
new normalisedURLPath_1.default(`/recipe/multitenancy/tenant/remove`),
{
tenantId,
}
);
return response;
});
},
getTenantConfig: function () {
getTenantConfig: function ({ tenantId }) {
return __awaiter(this, void 0, void 0, function* () {
let response = yield querier.sendGetRequest(
new normalisedURLPath_1.default(
`/${
tenantId === undefined ? constants_1.DEFAULT_TENANT_ID : tenantId
}/recipe/multitenancy/tenant`
),
{}
);
return {
status: "OK",
emailPassword: {
enabled: true,
},
passwordless: {
enabled: true,
},
thirdParty: {
enabled: true,
providers: [],
},
status: response.status,
emailPassword: response.emailPassword,
passwordless: response.passwordless,
thirdParty: response.thirdParty,
};
});
},
listAllTenants: function () {
return __awaiter(this, void 0, void 0, function* () {
// TODO
throw new Error("Not implemented");
let response = yield querier.sendGetRequest(
new normalisedURLPath_1.default(`/recipe/multitenancy/tenant/list`),
{}
);
const tenants = response.tenants.map((item) => item.tenantId);
return {
status: "OK",
tenants,
};
});
},
createOrUpdateThirdPartyConfig: function () {
createOrUpdateThirdPartyConfig: function ({ tenantId, config, skipValidation }) {
return __awaiter(this, void 0, void 0, function* () {
// TODO
throw new Error("Not implemented");
let response = yield querier.sendPutRequest(
new normalisedURLPath_1.default(
`/${
tenantId === undefined ? constants_1.DEFAULT_TENANT_ID : tenantId
}/recipe/multitenancy/config/thirdparty`
),
{
config,
skipValidation,
}
);
return response;
});
},
deleteThirdPartyConfig: function () {
deleteThirdPartyConfig: function ({ tenantId, thirdPartyId }) {
return __awaiter(this, void 0, void 0, function* () {
// TODO
throw new Error("Not implemented");
let response = yield querier.sendPostRequest(
new normalisedURLPath_1.default(
`/${
tenantId === undefined ? constants_1.DEFAULT_TENANT_ID : tenantId
}/recipe/multitenancy/config/thirdparty/remove`
),
{
thirdPartyId,
}
);
return response;
});
},
listThirdPartyConfigsForThirdPartyId: function () {
listThirdPartyConfigsForThirdPartyId: function ({ thirdPartyId }) {
return __awaiter(this, void 0, void 0, function* () {
// TODO
throw new Error("Not implemented");
let response = yield querier.sendGetRequest(
new normalisedURLPath_1.default(`/recipe/multitenancy/tenant/list`),
{}
);
let result = {
status: "OK",
tenants: [],
};
for (const tenant of response.tenants) {
result.tenants.push({
tenantId: tenant.tenantId,
providers: tenant.thirdParty.providers.filter(
(provider) => provider.thirdPartyId === thirdPartyId
),
});
}
return result;
});
},
};
Expand Down
8 changes: 6 additions & 2 deletions lib/build/recipe/multitenancy/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export declare type RecipeInterface = {
userContext: any;
}) => Promise<{
status: "OK";
tenantExisted: boolean;
didExist: boolean;
}>;
getTenantConfig: (input: {
tenantId?: string;
Expand All @@ -95,6 +95,7 @@ export declare type RecipeInterface = {
tenants: string[];
}>;
createOrUpdateThirdPartyConfig: (input: {
tenantId?: string;
config: ProviderConfig;
skipValidation?: boolean;
userContext: any;
Expand All @@ -115,7 +116,10 @@ export declare type RecipeInterface = {
userContext: any;
}) => Promise<{
status: "OK";
providers: ProviderConfig[];
tenants: {
tenantId: string;
providers: ProviderConfig[];
}[];
}>;
};
export declare type APIOptions = {
Expand Down
1 change: 1 addition & 0 deletions lib/build/recipe/session/recipeImplementation.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ exports.protectedProps = [
"parentRefreshTokenHash1",
"refreshTokenHash1",
"antiCsrfToken",
"tId",
];
function getRecipeInterface(querier, config, appInfo, getRecipeImplAfterOverrides) {
const JWKS = querier.getAllCoreUrlsForPath("/.well-known/jwks.json").map((url) =>
Expand Down
2 changes: 1 addition & 1 deletion lib/build/recipe/thirdparty/providers/apple.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ function Apple(input) {
);
}
config.clientSecret = getClientSecret(
config.clientID,
config.clientId,
config.additionalConfig.keyId,
config.additionalConfig.teamId,
config.additionalConfig.privateKey
Expand Down
1 change: 0 additions & 1 deletion lib/build/recipe/thirdparty/providers/configUtils.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ export declare function findAndCreateProviderInstance(
): Promise<TypeProvider>;
export declare function mergeConfig(staticConfig: ProviderConfig, coreConfig: ProviderConfig): ProviderConfig;
export declare function mergeProvidersFromCoreAndStatic(
tenantId: string | undefined,
providerConfigsFromCore: ProviderConfig[],
providerInputsFromStatic: ProviderInput[]
): ProviderInput[];
3 changes: 1 addition & 2 deletions lib/build/recipe/thirdparty/providers/configUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,10 @@ function mergeConfig(staticConfig, coreConfig) {
return result;
}
exports.mergeConfig = mergeConfig;
function mergeProvidersFromCoreAndStatic(tenantId, providerConfigsFromCore, providerInputsFromStatic) {
function mergeProvidersFromCoreAndStatic(providerConfigsFromCore, providerInputsFromStatic) {
const mergedProviders = [];
if (providerConfigsFromCore.length === 0) {
for (const config of providerInputsFromStatic) {
config.config.tenantId = tenantId;
mergedProviders.push(config);
}
} else {
Expand Down
16 changes: 8 additions & 8 deletions lib/build/recipe/thirdparty/providers/custom.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ function NewProvider(input) {
}
let impl = {
id: input.config.thirdPartyId,
config: Object.assign(Object.assign({}, input.config), { clientID: "temp" }),
config: Object.assign(Object.assign({}, input.config), { clientId: "temp" }),
getConfigForClientType: function ({ clientType }) {
return __awaiter(this, void 0, void 0, function* () {
if (clientType === undefined) {
Expand All @@ -204,7 +204,7 @@ function NewProvider(input) {
getAuthorisationRedirectURL: function ({ redirectURIOnProviderDashboard }) {
return __awaiter(this, void 0, void 0, function* () {
const queryParams = {
client_id: impl.config.clientID,
client_id: impl.config.clientId,
redirect_uri: redirectURIOnProviderDashboard,
response_type: "code",
};
Expand Down Expand Up @@ -232,8 +232,8 @@ function NewProvider(input) {
}
let url = impl.config.authorizationEndpoint;
/* Transformation needed for dev keys BEGIN */
if (isUsingDevelopmentClientId(impl.config.clientID)) {
queryParams["client_id"] = getActualClientIdFromDevelopmentClientId(impl.config.clientID);
if (isUsingDevelopmentClientId(impl.config.clientId)) {
queryParams["client_id"] = getActualClientIdFromDevelopmentClientId(impl.config.clientId);
queryParams["actual_redirect_uri"] = url;
url = DEV_OAUTH_AUTHORIZATION_URL;
}
Expand All @@ -255,7 +255,7 @@ function NewProvider(input) {
}
const tokenAPIURL = impl.config.tokenEndpoint;
const accessTokenAPIParams = {
client_id: impl.config.clientID,
client_id: impl.config.clientId,
redirect_uri: redirectURIInfo.redirectURIOnProviderDashboard,
code: redirectURIInfo.redirectURIQueryParams["code"],
grant_type: "authorization_code",
Expand All @@ -274,8 +274,8 @@ function NewProvider(input) {
}
}
/* Transformation needed for dev keys BEGIN */
if (isUsingDevelopmentClientId(impl.config.clientID)) {
accessTokenAPIParams["client_id"] = getActualClientIdFromDevelopmentClientId(impl.config.clientID);
if (isUsingDevelopmentClientId(impl.config.clientId)) {
accessTokenAPIParams["client_id"] = getActualClientIdFromDevelopmentClientId(impl.config.clientId);
accessTokenAPIParams["redirect_uri"] = DEV_OAUTH_REDIRECT_URL;
}
/* Transformation needed for dev keys END */
Expand All @@ -295,7 +295,7 @@ function NewProvider(input) {
idToken,
impl.config.jwksURI,
{
audience: getActualClientIdFromDevelopmentClientId(impl.config.clientID),
audience: getActualClientIdFromDevelopmentClientId(impl.config.clientId),
}
);
if (impl.config.validateIdTokenPayload !== undefined) {
Expand Down
1 change: 0 additions & 1 deletion lib/build/recipe/thirdparty/recipeImplementation.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ function getRecipeImplementation(querier, providers) {
const mtRecipe = recipe_1.default.getInstanceOrThrowError();
const tenantConfig = yield mtRecipe.recipeInterfaceImpl.getTenantConfig({ tenantId, userContext });
const mergedProviders = configUtils_1.mergeProvidersFromCoreAndStatic(
tenantId,
tenantConfig.thirdParty.providers,
providers
);
Expand Down
3 changes: 1 addition & 2 deletions lib/build/recipe/thirdparty/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export declare type UserInfoMap = {
};
export declare type ProviderClientConfig = {
clientType?: string;
clientID: string;
clientId: string;
clientSecret?: string;
scope?: string[];
forcePKCE?: boolean;
Expand All @@ -43,7 +43,6 @@ export declare type ProviderClientConfig = {
};
declare type CommonProviderConfig = {
thirdPartyId: string;
tenantId?: string;
name?: string;
authorizationEndpoint?: string;
authorizationEndpointQueryParams?: {
Expand Down
2 changes: 1 addition & 1 deletion lib/build/version.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 1 addition & 5 deletions lib/ts/recipe/multitenancy/api/implementation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,7 @@ export default function getAPIInterface(): APIInterface {
const providerInputsFromStatic = options.staticThirdPartyProviders;
const providerConfigsFromCore = tenantConfigRes.thirdParty.providers;

const mergedProviders = mergeProvidersFromCoreAndStatic(
tenantId,
providerConfigsFromCore,
providerInputsFromStatic
);
const mergedProviders = mergeProvidersFromCoreAndStatic(providerConfigsFromCore, providerInputsFromStatic);

const finalProviderList: {
id: string;
Expand Down
Loading