Skip to content

Commit

Permalink
fix: base64 encoding changes
Browse files Browse the repository at this point in the history
  • Loading branch information
tamassoltesz committed Jan 31, 2025
1 parent bf78593 commit c42ab45
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ public static Collection<? extends LoginMethod> getUsersInfoUsingIdList_Transact
"JOIN " + credentialTable + " as credentials ON webauthn.user_id = credentials.user_id " +
"JOIN " + usersTable + " as all_users ON webauthn.app_id = all_users.app_id AND webauthn.user_id = all_users.user_id " +
"JOIN " + userIdMappingTable + " as user_id_mapping ON webauthn.user_id = user_id_mapping.supertokens_user_id " +
"JOIN " + emailVerificationTable + " as email_verification ON webauthn.app_id = email_verification.app_id AND user_id_mapping.external_user_id = email_verification.user_id OR user_id_mapping.supertokens_user_id = email_verification.user_id" +
"JOIN " + emailVerificationTable + " as email_verification ON webauthn.app_id = email_verification.app_id AND user_id_mapping.external_user_id = email_verification.user_id OR user_id_mapping.supertokens_user_id = email_verification.user_id " +
"WHERE webauthn.app_id = ? AND webauthn.user_id IN (" + Utils.generateCommaSeperatedQuestionMarks(ids.size()) + ")";

return execute(connection, queryAll, pst -> {
Expand Down Expand Up @@ -386,7 +386,7 @@ public static AuthRecipeUserInfo getUserInfoByCredentialId_Transaction(Start sta
"JOIN " + getConfig(start).getWebAuthNCredentialsTable() + " as credentials ON webauthn.user_id = credentials.user_id " +
"JOIN " + getConfig(start).getUsersTable() + " as all_users ON webauthn.app_id = all_users.app_id AND webauthn.user_id = all_users.user_id " +
"JOIN " + getConfig(start).getUserIdMappingTable() + " as user_id_mapping ON webauthn.user_id = user_id_mapping.supertokens_user_id " +
"JOIN " + getConfig(start).getEmailVerificationTable() + " as email_verification ON webauthn.app_id = email_verification.app_id AND user_id_mapping.external_user_id = email_verification.user_id OR user_id_mapping.supertokens_user_id = email_verification.user_id" +
"JOIN " + getConfig(start).getEmailVerificationTable() + " as email_verification ON webauthn.app_id = email_verification.app_id AND user_id_mapping.external_user_id = email_verification.user_id OR user_id_mapping.supertokens_user_id = email_verification.user_id " +
"WHERE webauthn.app_id = ? AND credentials.id = ?";

return execute(start, QUERY, pst -> {
Expand Down
10 changes: 8 additions & 2 deletions src/main/java/io/supertokens/webauthn/utils/WebauthMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import io.supertokens.pluginInterface.webauthn.WebAuthNStoredCredential;
import io.supertokens.webauthn.WebauthNSaveCredentialResponse;

import java.nio.charset.StandardCharsets;
import java.util.Base64;

public class WebauthMapper {
Expand Down Expand Up @@ -67,13 +68,18 @@ public static JsonObject createResponseFromOptions(PublicKeyCredentialCreationOp
response.add("rp", rp);

JsonObject user = new JsonObject();
user.addProperty("id", Base64.getUrlEncoder().encodeToString(options.getUser().getId()));
user.addProperty("id", new String(Base64.getUrlEncoder().withoutPadding().encode(options.getUser().getId()), StandardCharsets.UTF_8));
user.addProperty("name", options.getUser().getName());
user.addProperty("displayName", options.getUser().getDisplayName());
response.add("user", user);

response.addProperty("timeout", options.getTimeout());
response.addProperty("challenge", Base64.getUrlEncoder().encodeToString(options.getChallenge().getValue()));
//response.addProperty("challenge", Base64.getUrlEncoder().encodeToString(options.getChallenge().getValue()));
//response.addProperty("challenge", new String(Base64.getUrlEncoder().encode(options.getChallenge().getValue()), StandardCharsets.UTF_8));
// String challenge = "c29tZS1iYXNlNjQtZW5jb2RlZC1zdHJpbmc";
// byte[] challengeBytes = Base64.getUrlDecoder().decode(challenge);
String encodedChallenge = Base64.getUrlEncoder().withoutPadding().encodeToString(options.getChallenge().getValue());
response.addProperty("challenge", encodedChallenge);
response.addProperty("attestation", options.getAttestation().getValue());

response.addProperty("createdAt", createdAt);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.google.gson.JsonObject;
import io.supertokens.ActiveUsers;
import io.supertokens.Main;
import io.supertokens.output.Logging;
import io.supertokens.pluginInterface.Storage;
import io.supertokens.pluginInterface.multitenancy.TenantIdentifier;
import io.supertokens.pluginInterface.multitenancy.exceptions.TenantOrAppNotFoundException;
Expand Down Expand Up @@ -50,13 +51,17 @@ protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws I
TenantIdentifier tenantIdentifier = getTenantIdentifier(req);
Storage storage = getTenantStorage(req);

Logging.info(this.main, tenantIdentifier, "SIGNUP_WITH_CREDENTIAL", true);

JsonObject input = InputParser.parseJsonObjectOrThrowError(req);
String webauthGeneratedOptionsId = InputParser.parseStringOrThrowError(input, "webauthGeneratedOptionsId",
String webauthGeneratedOptionsId = InputParser.parseStringOrThrowError(input, "webauthnGeneratedOptionsId",
false);
JsonObject credentialsData = InputParser.parseJsonObjectOrThrowError(input, "credential", false);
String credentialsDataString = new Gson().toJson(credentialsData);
String credentialId = InputParser.parseStringOrThrowError(credentialsData, "id", false);

Logging.info(this.main, tenantIdentifier, "input request " + input, true);

WebAuthNSignInUpResult signUpResult = WebAuthN.signUp(storage, tenantIdentifier, webauthGeneratedOptionsId,
credentialId, credentialsDataString);

Expand Down

0 comments on commit c42ab45

Please sign in to comment.