Skip to content

Commit

Permalink
fix: Mfa changes (#135)
Browse files Browse the repository at this point in the history
* fix: remove totp config and rename fields in tenant config

* fix: updated json
  • Loading branch information
sattvikc authored Dec 20, 2023
1 parent c1fd974 commit 208e167
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 52 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
- AuthRecipeStorage interface changes
- Adds `getUsersCountWithMoreThanOneLoginMethodOrTOTPEnabled` function
- TenantConfig changes
- Adds `totpConfig`, `firstFactors` and `defaultRequiredFactorIds` fields
- Adds `firstFactors` and `requiredSecondaryFactors` fields
- Adds `createdAt` field to `TOTPDevice`
- TOTPSQLStorage interface changes
- Adds `getDeviceByName_Transaction` and `createDevice_Transaction` functions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,13 @@
package io.supertokens.pluginInterface.multitenancy;

import com.google.gson.Gson;
import com.google.gson.JsonNull;
import com.google.gson.JsonObject;
import com.google.gson.annotations.SerializedName;
import io.supertokens.pluginInterface.Storage;
import io.supertokens.pluginInterface.utils.Utils;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.Objects;

public class TenantConfig {

Expand All @@ -44,35 +42,29 @@ public class TenantConfig {
@SerializedName("passwordless")
public final PasswordlessConfig passwordlessConfig;

@Nonnull
@SerializedName("totp")
public final TotpConfig totpConfig;

@Nullable
@SerializedName("firstFactors")
public final String[] firstFactors;

@Nullable
@SerializedName("defaultRequiredFactorIds")
public final String[] defaultRequiredFactorIds;
@SerializedName("requiredSecondaryFactors")
public final String[] requiredSecondaryFactors;

@Nonnull
public final JsonObject coreConfig;

public TenantConfig(@Nonnull TenantIdentifier tenantIdentifier, @Nonnull EmailPasswordConfig emailPasswordConfig,
@Nonnull ThirdPartyConfig thirdPartyConfig,
@Nonnull PasswordlessConfig passwordlessConfig,
@Nonnull TotpConfig totpConfig,
@Nullable String[] firstFactors, @Nullable String[] defaultRequiredFactorIds,
@Nullable String[] firstFactors, @Nullable String[] requiredSecondaryFactors,
@Nullable JsonObject coreConfig) {
this.tenantIdentifier = tenantIdentifier;
this.coreConfig = coreConfig == null ? new JsonObject() : coreConfig;
this.emailPasswordConfig = emailPasswordConfig;
this.passwordlessConfig = passwordlessConfig;
this.thirdPartyConfig = thirdPartyConfig;
this.totpConfig = totpConfig;
this.firstFactors = firstFactors;
this.defaultRequiredFactorIds = defaultRequiredFactorIds;
this.firstFactors = firstFactors == null || firstFactors.length == 0 ? null : firstFactors;
this.requiredSecondaryFactors = requiredSecondaryFactors == null || requiredSecondaryFactors.length == 0 ? null : requiredSecondaryFactors;
}

public TenantConfig(TenantConfig other) {
Expand All @@ -83,9 +75,8 @@ public TenantConfig(TenantConfig other) {
this.emailPasswordConfig = new EmailPasswordConfig(other.emailPasswordConfig.enabled);
this.passwordlessConfig = new PasswordlessConfig(other.passwordlessConfig.enabled);
this.thirdPartyConfig = new ThirdPartyConfig(other.thirdPartyConfig.enabled, other.thirdPartyConfig.providers.clone());
this.totpConfig = new TotpConfig(other.totpConfig.enabled);
this.firstFactors = other.firstFactors == null ? null : other.firstFactors.clone();
this.defaultRequiredFactorIds = other.defaultRequiredFactorIds == null ? null : other.defaultRequiredFactorIds.clone();
this.requiredSecondaryFactors = other.requiredSecondaryFactors == null ? null : other.requiredSecondaryFactors.clone();
}

public boolean deepEquals(TenantConfig other) {
Expand All @@ -96,9 +87,8 @@ public boolean deepEquals(TenantConfig other) {
this.emailPasswordConfig.equals(other.emailPasswordConfig) &&
this.passwordlessConfig.equals(other.passwordlessConfig) &&
this.thirdPartyConfig.equals(other.thirdPartyConfig) &&
this.totpConfig.equals(other.totpConfig) &&
Utils.unorderedArrayEquals(this.firstFactors, other.firstFactors) && // order is not important
Objects.deepEquals(this.defaultRequiredFactorIds, other.defaultRequiredFactorIds) && // order is important
Utils.unorderedArrayEquals(this.requiredSecondaryFactors, other.requiredSecondaryFactors) && // order is not important
this.coreConfig.equals(other.coreConfig);
}

Expand All @@ -123,6 +113,14 @@ public JsonObject toJson(boolean shouldProtectDbConfig, Storage storage, String[
tenantConfigObject.add("thirdParty", this.thirdPartyConfig.toJson());
tenantConfigObject.addProperty("tenantId", this.tenantIdentifier.getTenantId());

if (tenantConfigObject.has("firstFactors") && tenantConfigObject.get("firstFactors").getAsJsonArray().size() == 0) {
tenantConfigObject.remove("firstFactors");
}

if (tenantConfigObject.has("requiredSecondaryFactors") && tenantConfigObject.get("requiredSecondaryFactors").getAsJsonArray().size() == 0) {
tenantConfigObject.remove("requiredSecondaryFactors");
}

if (shouldProtectDbConfig) {
String[] protectedConfigs = storage.getProtectedConfigsFromSuperTokensSaaSUsers();
for (String config : protectedConfigs) {
Expand Down

This file was deleted.

0 comments on commit 208e167

Please sign in to comment.