-
Notifications
You must be signed in to change notification settings - Fork 7
fix: Replace java.util.Base64 with android.util.Base64 for backwards compatibility #20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,7 +1,6 @@ | ||||||
| package com.googleauth | ||||||
|
|
||||||
| import android.app.Activity | ||||||
| import android.content.Context | ||||||
| import android.content.SharedPreferences | ||||||
| import android.util.Log | ||||||
| import androidx.lifecycle.Lifecycle | ||||||
|
|
@@ -32,10 +31,8 @@ import kotlinx.coroutines.Dispatchers | |||||
| import kotlinx.coroutines.delay | ||||||
| import kotlinx.coroutines.launch | ||||||
| import kotlinx.coroutines.withContext | ||||||
| import java.util.Date | ||||||
| import java.util.concurrent.TimeUnit | ||||||
| import org.json.JSONObject | ||||||
| import java.util.Base64 | ||||||
| import android.util.Base64 | ||||||
|
|
||||||
| @ReactModule(name = GoogleAuthModule.NAME) | ||||||
| class GoogleAuthModule(reactContext: ReactApplicationContext) : | ||||||
|
|
@@ -867,7 +864,7 @@ class GoogleAuthModule(reactContext: ReactApplicationContext) : | |||||
| try { | ||||||
| val parts = idToken.split(".") | ||||||
| if (parts.size >= 2) { | ||||||
| val payload = String(Base64.getUrlDecoder().decode(parts[1])) | ||||||
| val payload = String(Base64.decode(parts[1], Base64.NO_WRAP)) | ||||||
| val json = JSONObject(payload) | ||||||
| val exp = json.optLong("exp", 0) | ||||||
| if (exp > 0) { | ||||||
|
|
@@ -883,7 +880,7 @@ class GoogleAuthModule(reactContext: ReactApplicationContext) : | |||||
| try { | ||||||
| val parts = idToken.split(".") | ||||||
| if (parts.size >= 2) { | ||||||
| val payload = String(Base64.getUrlDecoder().decode(parts[1])) | ||||||
| val payload = String(Base64.decode(parts[1], Base64.NO_WRAP)) | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same base64url bug as Proposed fix- val payload = String(Base64.decode(parts[1], Base64.URL_SAFE))
+ val payload = String(Base64.decode(parts[1], Base64.URL_SAFE))(Ensure this line reads - val payload = String(Base64.decode(parts[1], Base64.NO_WRAP))
+ val payload = String(Base64.decode(parts[1], Base64.URL_SAFE))📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||
| val json = JSONObject(payload) | ||||||
| return json.optString("email", null) | ||||||
| } | ||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug:
Base64.NO_WRAPdoes not handle URL-safe Base64 — JWT payloads use base64url encoding.JWTs encode their payload using base64url (RFC 7515), which substitutes
+→-and/→_. The previous code correctly usedjava.util.Base64.getUrlDecoder(). Replacing it withandroid.util.Base64.decode(..., Base64.NO_WRAP)uses the standard alphabet and will silently produce corrupted output (or throw) whenever the payload contains-or_characters.Use
Base64.URL_SAFE(which also implies no wrap/padding handling) instead:Proposed fix
📝 Committable suggestion
🤖 Prompt for AI Agents