Skip to content

Commit

Permalink
fix: Remove Base64 padding in DefaultPKCEProvider (#1375)
Browse files Browse the repository at this point in the history
* fix: Remove Base64 padding in DefaultPKCEProvider

Fixes
#1373.
  • Loading branch information
clundin25 authored Mar 14, 2024
1 parent 3a546fb commit 1405378
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
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 @@ -52,10 +53,17 @@ public void testPkceExpected() throws NoSuchAlgorithmException {

byte[] digest = md.digest();

String expectedCodeChallenge = Base64.getUrlEncoder().encodeToString(digest);
String expectedCodeChallenge = Base64.getUrlEncoder().encodeToString(digest).replace("=", "");
String expectedCodeChallengeMethod = "S256";

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 1405378

Please sign in to comment.