FusionAuth / go-client

FusionAuth Go Client Library!
https://fusionauth.io/
Apache License 2.0
29 stars 32 forks source link

CreateTenant with SourceTenantId does not behave as expected #62

Open josedelrio85 opened 2 years ago

josedelrio85 commented 2 years ago

I have created a tenant using Tenant APIs using the Default Tenant as a base, but trying to add customisations, in this case email settings.

POST api/tenant

{
  "tenant": {
    "sourceTenantId": "1477a639-1027-1fdb-b6cc-f19a162865a9",
    "name": "foo",
    "issuer":"foobar.com",
    "emailConfiguration":{
      "defaultFromEmail":"no-reply@foobar.com",
      "defaultFromName":"FooBar",
      "host":"smtp.foobar.com",
      "implicitEmailVerificationAllowed":false,
      "password":"password",
      "port":465,
      "security":"SSL",
      "username":"foobar"
    },
    "passwordEncryptionConfiguration":{
      "encryptionScheme":"bcrypt",
      "encryptionSchemeFactor":6
    }
  }
}

The result is satisfactory, as I get the new Tenant with the default configuration plus the customisations specified in the request.

On the other hand, when using the CreateTenant method of the client, if I specify in the SourceTenantId property the identifier of the base Tenant, the resulting Tenant does not have the custom properties.

func (h *Handler) CreateTenant(name string) (*fusionauth.TenantResponse, *fusionauth.Errors, error) {
    tr := fusionauth.TenantRequest{
                // if this property is uncommented, the result is the configuration of DefaultTenant
        // SourceTenantId: "1477a639-1027-1fdb-b6cc-f19a162865a9",
        Tenant: fusionauth.Tenant{
            Name:   name,
            Issuer: "udrafter.com",
            EmailConfiguration: fusionauth.EmailConfiguration{
                DefaultFromEmail:                 "no-reply-dev@foobar.com",
                DefaultFromName:                  "foobar",
                Host:                             "smt.foobar.com",
                ImplicitEmailVerificationAllowed: false,
                Password:                         "password",
                Port:                             465,
                Security:                         "SSL",
                Username:                         "foobar",
            },
            PasswordEncryptionConfiguration: fusionauth.PasswordEncryptionConfiguration{
                EncryptionScheme:       "bcrypt",
                EncryptionSchemeFactor: 6,
            },
        },
    }
    r, faerrors, err := h.FusionAuth.CreateTenant("", tr)
    if err != nil {
        return nil, faerrors, err
    }
    return r, faerrors, nil
}

I understand that this behaviour does not correspond to the behaviour obtained using Tenant APIs and to what is discussed in this section of the documentation:

sourceTenantId [UUID] OPTIONAL AVAILABLE SINCE 1.14.0
The optional Id of an existing Tenant to make a copy of. A unique tenant.name is required. If present, the tenant.id value will used for the new Tenant. All other values will be copied from the source Tenant to the new Tenant.
mooreds commented 2 years ago

@josedelrio85 hmmm. So re-reading the issue, it appears that the client and the tenant API have different behavior when additional fields are added to a sourceTenantId call.

Is that correct?

One workaround is to create the tenant in two steps. Will that not work for you for some reason?

josedelrio85 commented 2 years ago

@mooreds Yes, the behaviour differs between a direct API call and the use of the library.

From my point of view, and following the indication in the documentation, I understand that the behaviour of the library function should be corrected.

I really opened the issue to comment on this difference so that you would be aware of it.