Use native Base64 APIs for decoding when available
Checklist
- [X] I have looked into the Readme and have not found a suitable solution or answer.
- [X] I have searched the issues and have not found a suitable solution or answer.
- [X] I have searched the Auth0 Community forums and have not found a suitable solution or answer.
- [X] I agree to the terms within the Auth0 Code of Conduct.
Describe the problem you'd like to have solved
The proposal for native Base46 APIs that properly handle the Base64URL implementation has reached Stage 3 and has started being implemented in various engines and browsers. This provides an opportunity to use these APIs rather than the custom implementation now present in the package, and could possibly lead to improved performance as well.
Describe the ideal solution
Right now the ideal solution would be to use the built-in API if present and fall back to the custom internal implementation when not supported. Long term the best option would be to drop the internal implementation entirely.
Alternatives and current workarounds
No response
Additional context
No response
The required API has now landed in Chrome, Firefox and Safari. It might be time to consider implementing this.
I think this isn’t going to work for JWT decoding, because it usually expects a JSON string instead of a Uint8Array.
Not sure what you mean. A string can be converted into an Uint8Array, and back to a string. JSON is just string data.
const data = Uint8Array.fromBase64("SGVsbG8gV29ybGQh")
const decoder = new TextDecoder();
const result = decoder.decode(data);
console.log(result); // "Hello World"
I was thinking that compared to atob which already returning string, Uint8Array.fromBase64 return Uint8Array which need to be decoded first to string. But after looking through it, you're right, using Uint8Array.fromBase64 + TextDecoder is much simpler.