Skip to content

Commit

Permalink
Drop base64-js dependency from Keycloak JS (keycloak#26265)
Browse files Browse the repository at this point in the history
Closes keycloak#26264

Signed-off-by: Jon Koops <[email protected]>
  • Loading branch information
jonkoops authored Jan 17, 2024
1 parent 0307779 commit b597c02
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 7 deletions.
1 change: 0 additions & 1 deletion js/libs/keycloak-js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@
"shx": "^0.3.4"
},
"dependencies": {
"base64-js": "^1.5.1",
"js-sha256": "^0.10.1",
"jwt-decode": "^4.0.0"
}
Expand Down
2 changes: 1 addition & 1 deletion js/libs/keycloak-js/rollup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ function defineOptions({
file: path.join(targetDir, `${file}.mjs`),
},
],
external: ["base64-js", "js-sha256", "jwt-decode"],
external: ["js-sha256", "jwt-decode"],
},
// Legacy Universal Module Definition, or “UMD”, with inlined dependencies.
{
Expand Down
9 changes: 7 additions & 2 deletions js/libs/keycloak-js/src/keycloak.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import base64 from 'base64-js';
import sha256 from 'js-sha256';
import { jwtDecode } from 'jwt-decode';

Expand Down Expand Up @@ -380,7 +379,7 @@ function Keycloak (config) {
case "S256":
// hash codeVerifier, then encode as url-safe base64 without padding
var hashBytes = new Uint8Array(sha256.arrayBuffer(codeVerifier));
var encodedHash = base64.fromByteArray(hashBytes)
var encodedHash = bytesToBase64(hashBytes)
.replace(/\+/g, '-')
.replace(/\//g, '_')
.replace(/\=/g, '');
Expand Down Expand Up @@ -1756,3 +1755,9 @@ function Keycloak (config) {
}

export default Keycloak;

// See: https://developer.mozilla.org/en-US/docs/Glossary/Base64#the_unicode_problem
function bytesToBase64(bytes) {
const binString = String.fromCodePoint(...bytes);
return btoa(binString);
}
4 changes: 1 addition & 3 deletions js/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit b597c02

Please sign in to comment.