Fix ID token verification (#87)
diff --git a/google/auth/_helpers.py b/google/auth/_helpers.py
index 5a6c3a8..de86bee 100644
--- a/google/auth/_helpers.py
+++ b/google/auth/_helpers.py
@@ -14,6 +14,7 @@
"""Helper functions for commonly used utilities."""
+import base64
import calendar
import datetime
@@ -194,3 +195,19 @@
return []
return scopes.split(' ')
+
+
+def padded_urlsafe_b64decode(value):
+ """Decodes base64 strings lacking padding characters.
+
+ Google infrastructure tends to omit the base64 padding characters.
+
+ Args:
+ value (Union[str, bytes]): The encoded value.
+
+ Returns:
+ bytes: The decoded value
+ """
+ b64string = to_bytes(value)
+ padded = b64string + b'=' * (-len(b64string) % 4)
+ return base64.urlsafe_b64decode(padded)