Duplicating an application held in 'Tenant1' to 'Tenant2' stays in 'Tenant1'
-
Hi,
I'm trying to duplicate an application (TemplateApp) held in a tenant (TemplateTenant) using the 'sourceApplicationId' parameter but the clone always end up in the source tenant (TemplateTenant)
Here's what I'm doing
const newApplication = {}; newApplication.name = 'Cloned app'; newApplication.tenantId = newTenantResponse.id; //this is from a duplicated tenant, which works. //tenantTemplateId is the id of TemplateTenant const newApplicationResponse = await fusionAuthService.createApplication(tenantTemplateId, applicationTemplateId, newApplication); //Also trying to set the tenant in the patch call, no go. await fusionAuthService.updateApplication(newApplicationResponse.id, { oauthConfiguration: { authorizedRedirectURLs: [ `https://www.website.com/*`, `https://backend.com/api/auth/callback` ] }, tenantId: newTenantResponse.id }); async createApplication(tenantTemplateId, sourceApplicationId, applicationRequest) { const client = new FusionAuthClient( this.apiKey, this.url, tenantTemplateId ); try { return (await client.createApplication(null, { sourceApplicationId: sourceApplicationId, application: applicationRequest })).response.application; } catch (err) { this.logError(err); } } async updateApplication(applicationId, values) { try { await this.client.patchApplication(applicationId, { application: values }); } catch (err) { this.logError(err); } }
I'm not entirely sure about tenant scoping here. The client has to be initiated with the id of TemplateTenant, otherwise the call to createApplication fails saying the source application doesn't exist.
Is that even possible?
Thanks.
-
@francis-ducharme-0 It looks like you can do it through the AdminUI and generally if you can do it through the AdminUI, you can do it through the APIs. I should have some time later this week to test this out. If anyone else gets a chance to before then, please let us know.
-
@mark-robustelli thanks. I've also tried by retrieving the template application and then changing some of its properties as such
//Use same object for next request (creating application), assign new values appTemplate.jwtConfiguration.accessTokenKeyId = primaryDefaultJwtKeyId; appTemplate.jwtConfiguration.idTokenKeyId = secondaryDefaultJwtKeyId; appTemplate.tenantId = newTenant.id; appTemplate.name = `Portal (${env.toUpperCase()})`; appTemplate.oauthConfiguration.authorizedRedirectURLs = [ `https://frontend.com/*`, `https://backend.com/api/auth/callback` ] delete appTemplate.id; delete appTemplate.oauthConfiguration.clientSecret; delete appTemplate.oauthConfiguration.clientId; //assign new ID to roles... appTemplate.roles.forEach(role => role.id = crypto.randomUUID()); const newApplication = await fusionAuthService.createApplication(appTemplate); async createApplication(applicationRequest) { const client = new FusionAuthClient( this.apiKey, this.url, applicationRequest.tenantId ); try { return (await client.createApplication(null, { application: applicationRequest})).response.application; } catch (err) { this.logError(err); } }
While this works API and UI wise any user trying to authenticate will receive no
successResponse
fromExchangeRefreshTokenForAccessTokenAsync
and I have no further details inerrorReponse
either.So maybe something else needs to be zapped/modified before using the
appTemplate
to create the clone ? -
@francis-ducharme-0 I was unable to tinker with this last week, but didn't want you to think I forgot about it. It is still on my list when I have some availability. Will post if/when I find something.
-
@francis-ducharme-0 Hey, after taking a look, it seems the only way to do it is to get the application you want to use, parse the JSON for the things you want to keep and then format new json for the create. So you can do it, it is just going to take a little extra work. Sorry for the inconvenience.
I'm not sure exactly what you are trying to accomplish, but have you checked out Universal Applications? A bit more documentation on them is available here.
-
@mark-robustelli said in Duplicating an application held in 'Tenant1' to 'Tenant2' stays in 'Tenant1':
@francis-ducharme-0 Hey, after taking a look, it seems the only way to do it is to get the application you want to use, parse the JSON for the things you want to keep and then format new json for the create. So you can do it, it is just going to take a little extra work. Sorry for the inconvenience.
I'm not sure exactly what you are trying to accomplish, but have you checked out Universal Applications? A bit more documentation on them is available here.
I have tried copying an existing template, but the resulting application isn't functional. In your tests, have you tried to use the cloned application for actual authentication? I explained the issue above.
I will look into Universal Applications, but so far, I don't seem to have that feature in our instance (1.57.1). When adding an application, there is no "universal" toggle.
EDIT: Apparently, this is a 1.58 feature. Will look into upgrading.
-
@francis-ducharme-0 You may have to parse the json returned from the get and modify a few things. Does the application get created but not work or does the application not get created? I would think you would need to take the relevant parts from the returned application then create the application under a new tenant? Remember you will have to use the new TenantId in the Request Header. If you are not supplying the TenantId, it will use the default.
On a side note: If you are still interested in a duplicate application across tenant feature in the API, you might want to put a request in.