Repository navigation
Use urlsafe variant of base64 #463
Description
Activity
Definitely, if it's important to do that for the API. Do you have any API documentation that I can look at that advises to use url-safe?
A quick search turned up https://github.com/RGBboy/urlsafe-base64 if we decide to implement.
Some APIs expect base64url (like Task Queues or GMail). The example for pubsub here specifically shows an example using base64 (not url variant) being encoded so that's strange. I'd hope that the url variant would still work. That being said, having a
utils#base64urlencodeandutils#base64decodeused across the library would be great to consolidate this functionality across all libraries, regardless of what variant we use.Do you have any API documentation that I can look at that advises to use url-safe?
It's Python, but the implementation is simple (uses '-' instead of '+' and '_' instead of '/'.):
def b64encode(s, altchars=None): """Encode a string using Base64. s is the string to encode. Optional altchars must be a string of at least length 2 (additional characters are ignored) which specifies an alternative alphabet for the '+' and '/' characters. This allows an application to e.g. generate url or filesystem safe Base64 strings. The encoded string is returned. """ # Strip off the trailing newline encoded = binascii.b2a_base64(s)[:-1] if altchars is not None: return _translate(encoded, {'+': altchars[0], '/': altchars[1]}) return encoded def urlsafe_b64encode(s): """Encode a string using a url-safe Base64 alphabet. s is the string to encode. The encoded string is returned. The alphabet uses '-' instead of '+' and '_' instead of '/'. """ return b64encode(s, '-_')
The example for pubsub here specifically shows an example using base64 (not url variant) being encoded so that's strange.
Which part is showing it?
Java library (pubsubMessage.encodeData) uses the urlsafe variant under the cover, Python uses base64.urlsafe_b64encode.
The = are removed in the url variant as well
so the data field of the example has = leading me to believe it's not the url variant
Aha, I found there is a discrepancy between the Java implementation and the Python implementation.
Only the Python implementation adds the padding at the end, and I used the value from the Python's base64.urlsafe_b64encode for that protocol example.
Then I would say, yes, please use the one that @stephenplusplus mentioned.
Oh! it's padding, cool! I didn't know that. :)
It turned out that, we should just use the standard Base64 variant, so I'm just going to close this bug. I'm very sorry if you've already worked on this. Please ask me for more details if you're interested in.
No problem, thanks for the update!
- added🚨This issue needs some love.This issue needs some love.triage meI really want to be triaged.I really want to be triaged.
on Apr 6, 2020 - added a commit that references this issue
on Aug 22, 2022 27 remaining items
- added a commit that references this issue
on Feb 23, 2026 - added a commit that references this issue
on Feb 25, 2026 - added a commit that references this issue
on Mar 5, 2026 - added a commit that references this issue
on Mar 5, 2026 - added a commit that references this issue
on Mar 18, 2026 - added a commit that references this issue
on Mar 27, 2026 - added a commit that references this issue
on May 5, 2026
For a historical reason, all the other samples and client libraries are using the url safe variant of base64 encode/decode.
Is it possible to use the url safe variant?