Skip to content

Commit

Permalink
fix: Remove Base64 padding in DefaultPKCEProvider
Browse files Browse the repository at this point in the history
Fixes
#1373.
  • Loading branch information
clundin25 committed Mar 11, 2024
1 parent 3a546fb commit e1098d2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ private class CodeChallenge {

byte[] digest = md.digest();

this.codeChallenge = Base64.getUrlEncoder().encodeToString(digest);
this.codeChallenge = Base64.getUrlEncoder().encodeToString(digest).replace("=", "");
this.codeChallengeMethod = "S256";
} catch (NoSuchAlgorithmException e) {
this.codeChallenge = codeVerifier;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
package com.google.auth.oauth2;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
Expand All @@ -58,4 +59,11 @@ public void testPkceExpected() throws NoSuchAlgorithmException {
assertEquals(pkce.getCodeChallenge(), expectedCodeChallenge);
assertEquals(pkce.getCodeChallengeMethod(), expectedCodeChallengeMethod);
}

@Test
public void testNoBase64Padding() throws NoSuchAlgorithmException {
PKCEProvider pkce = new DefaultPKCEProvider();
assertFalse(pkce.getCodeChallenge().endsWith("="));
assertFalse(pkce.getCodeChallenge().contains("="));
}
}

0 comments on commit e1098d2

Please sign in to comment.