Skip to content

Fix/base64 encoding#21

Merged
sbaiahmed1 merged 3 commits intosbaiahmed1:mainfrom
RickyJam:fix/base64_encoding
Mar 5, 2026
Merged

Fix/base64 encoding#21
sbaiahmed1 merged 3 commits intosbaiahmed1:mainfrom
RickyJam:fix/base64_encoding

Conversation

@RickyJam
Copy link
Copy Markdown

@RickyJam RickyJam commented Feb 17, 2026

Summary

This PR replaces the usage of java.util.Base64 with android.util.Base64 to ensure full compatibility across all supported Android API levels.

Problem

  • java.util.Base64 is not available to android SDK < 26, but the minSdk is 24. This results in java.lang.NoClassDefFoundError: java.util.Base64 that stops google auth process.

Proposed Solution

  • replace the current java.util.Base64 with the most appropriate andorid.util.Base64 in order to grant backwards compatibility to < 26 android versions.

Testing

  • Tested on devices/emulators with API < 26 and API ≥ 26

Summary by CodeRabbit

  • Refactor
    • Authentication module optimized for improved platform compatibility.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Feb 17, 2026

📝 Walkthrough

Walkthrough

Replaced Base64 decoding implementation in Android module from java.util.Base64.getUrlDecoder() to android.util.Base64.decode() with URL_SAFE flag. Updated corresponding imports accordingly.

Changes

Cohort / File(s) Summary
Base64 Decoding Refactor
android/src/main/java/com/googleauth/GoogleAuthModule.kt
Replaced java.util.Base64.getUrlDecoder().decode() calls with android.util.Base64.decode(..., Base64.URL_SAFE) for token parsing and email extraction. Updated imports by removing java.util.Date, java.util.concurrent.TimeUnit, and java.util.Base64; added android.util.Base64. No public API signature changes.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 A decoder's journey from Java's grand base,
To Android's swift embrace,
URL_SAFE flags now guard the token's flight,
One file transformed—the imports aligned just right,
No API breaks, just cleaner ways to decode! ✨

🚥 Pre-merge checks | ✅ 1 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title 'Fix/base64 encoding' is vague and generic, using non-descriptive phrasing that doesn't clearly convey what was fixed or why it matters. Consider using a more specific title that explains the actual fix, such as 'Replace java.util.Base64 with android.util.Base64 for API level compatibility' or 'Fix Android API level compatibility by switching to android.util.Base64'.
✅ Passed checks (1 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@RickyJam RickyJam marked this pull request as ready for review February 17, 2026 10:59
Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
android/src/main/java/com/googleauth/GoogleAuthModule.kt (1)

867-867: Specify UTF-8 charset explicitly when decoding JWT payload.

String(ByteArray) uses the platform default charset. JWT payloads are defined as UTF-8 JSON. While the default is almost always UTF-8 on Android, it's safer to be explicit.

Proposed fix
-        val payload = String(Base64.decode(parts[1], Base64.URL_SAFE))
+        val payload = String(Base64.decode(parts[1], Base64.URL_SAFE), Charsets.UTF_8)

Apply in both parseTokenExpiration (Line 867) and extractEmailFromIdToken (Line 883).

Also applies to: 883-883

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@android/src/main/java/com/googleauth/GoogleAuthModule.kt` at line 867, The
JWT payload is decoded using the platform default charset; update both
parseTokenExpiration and extractEmailFromIdToken to construct the String from
the decoded bytes with an explicit UTF-8 charset (use the result of
Base64.decode(parts[1], Base64.URL_SAFE) and pass it to String(...,
Charsets.UTF_8)) so the JWT JSON is always interpreted as UTF-8.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@android/src/main/java/com/googleauth/GoogleAuthModule.kt`:
- Line 867: The JWT payload is decoded using the platform default charset;
update both parseTokenExpiration and extractEmailFromIdToken to construct the
String from the decoded bytes with an explicit UTF-8 charset (use the result of
Base64.decode(parts[1], Base64.URL_SAFE) and pass it to String(...,
Charsets.UTF_8)) so the JWT JSON is always interpreted as UTF-8.

@RickyJam
Copy link
Copy Markdown
Author

RickyJam commented Mar 4, 2026

@sbaiahmed1

@sbaiahmed1 sbaiahmed1 merged commit 3f5a6c8 into sbaiahmed1:main Mar 5, 2026
5 of 6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants