Skip to content

feat: allow configuring Auth0.Android's native networking client - #1637

Open
NandanPrabhu wants to merge 2 commits into
v6-developmentfrom
feat/sdk-10614-android-networking-config
Open

feat: allow configuring Auth0.Android's native networking client#1637
NandanPrabhu wants to merge 2 commits into
v6-developmentfrom
feat/sdk-10614-android-networking-config

Conversation

@NandanPrabhu

@NandanPrabhu NandanPrabhu commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Adds androidNetworkingOptions to Auth0Options, exposing Auth0.Android's DefaultClient.Builder (connect/read/write/call timeouts, default headers, debug-only request logging) for every native request the SDK makes (web auth, credential renewal, MFA, passkeys, My Account API).
  • Android only — accepted and ignored on iOS for API compatibility. enableLogging is intentionally debug-only since Auth0.Android logs full request/response bodies (including tokens) at that level.
  • Threaded through the core config signature (so the option triggers native re-init when changed), the TurboModule spec, the native bridge manager, and the native adapter.

Ref: SDK-10614

Test plan

  • yarn typecheck — clean
  • yarn test — 36/36 suites, 712/712 tests pass (new coverage in configSignature.spec.ts, NativeAuth0Client.spec.ts, NativeBridgeManager.spec.ts)
  • yarn lint — clean on all changed files
  • Android unit tests (./gradlew :react-native-auth0:testDebugUnitTest) — new A0Auth0ModuleNetworkingOptionsTest (2/2) verifies readTimeout and defaultHeaders are genuinely applied to the built DefaultClient against a real MockWebServer
  • EXAMPLES.md updated with a new "Android Networking Configuration" section

Summary by CodeRabbit

  • New Features

    • Added Android networking configuration for connection, read, write, and call timeouts.
    • Added support for default request headers and optional verbose network logging on Android.
    • Networking settings apply during initialization and trigger reinitialization when changed.
    • Added documentation, usage examples, platform-specific behavior details, and security guidance.
  • Tests

    • Added coverage for timeout behavior, default headers, option forwarding, and configuration updates.

@coderabbitai

coderabbitai Bot commented Aug 13, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 44ab9488-f5fd-49aa-9547-55031ff4c8c7

📥 Commits

Reviewing files that changed from the base of the PR and between 4b062f9 and fe1855c.

📒 Files selected for processing (1)
  • android/build.gradle
💤 Files with no reviewable changes (1)
  • android/build.gradle

📝 Walkthrough

Walkthrough

Added optional Android networking options for timeouts, default headers, and logging. The options flow through the TypeScript and native bridge layers into an Android DefaultClient. Configuration changes update client signatures. Android tests and documentation cover the behavior.

Changes

Android networking options

Layer / File(s) Summary
Networking configuration contract
src/types/common.ts, src/specs/NativeA0Auth0.ts, src/platforms/native/bridge/INativeBridge.ts, src/core/utils/configSignature.ts, src/core/utils/__tests__/configSignature.spec.ts
Adds the AndroidNetworkingOptions type and initialization parameter. Includes the options in configuration signatures and validates stable nested-key handling.
Native initialization propagation
src/platforms/native/adapters/*, src/platforms/native/bridge/*, ios/A0Auth0.mm
Forwards androidNetworkingOptions through native initialization. iOS accepts and ignores the Android-only parameter. Tests cover supplied and omitted values, including reinitialization paths.
Android client configuration and validation
android/src/main/java/com/auth0/react/A0Auth0Module.kt, android/src/test/java/com/auth0/react/*, android/build.gradle, EXAMPLES.md
Builds and applies an Android DefaultClient with configured timeouts, headers, and logging. Adds MockWebServer coverage and documents configuration and usage examples.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Merge Risk: 🟠 High · up to fe185

The new Android networking configuration can expose token-bearing request and response bodies in release logs, and later initializations may unexpectedly retain networking settings from an earlier initialization. These security and configuration-isolation risks should be fixed or explicitly accepted before merge.

Sequence Diagram(s)

sequenceDiagram
  participant NativeAuth0Client
  participant NativeBridgeManager
  participant A0Auth0Module
  participant DefaultClient
  NativeAuth0Client->>NativeBridgeManager: initialize(..., androidNetworkingOptions)
  NativeBridgeManager->>A0Auth0Module: initializeAuth0WithConfiguration(..., androidNetworkingOptions)
  A0Auth0Module->>DefaultClient: build client with timeouts, headers, and logging
  A0Auth0Module->>A0Auth0Module: apply DefaultClient when options are provided
Loading

Possibly related PRs

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 16.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: configurable networking for Auth0.Android's native client.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/sdk-10614-android-networking-config

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.

Adds `androidNetworkingOptions` to `Auth0Options`, letting apps tune the
OkHttp-based `DefaultClient` (connect/read/write/call timeouts, default
headers, and debug logging) that Auth0.Android uses for every native
request. Android only; accepted and ignored on iOS for API compatibility.

Ref: SDK-10614
@NandanPrabhu
NandanPrabhu force-pushed the feat/sdk-10614-android-networking-config branch from 01e7644 to 4b062f9 Compare August 13, 2026 04:12
@NandanPrabhu
NandanPrabhu marked this pull request as ready for review August 13, 2026 04:12
@NandanPrabhu
NandanPrabhu requested a review from a team as a code owner August 13, 2026 04:12
@NandanPrabhu
NandanPrabhu marked this pull request as draft August 13, 2026 04:13

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@android/src/main/java/com/auth0/react/A0Auth0Module.kt`:
- Line 313: Update the initialization flow around androidNetworkingOptions and
Auth0.getInstance(clientId, domain) so the Auth0 instance’s networkingClient is
explicitly reset to DefaultClient() when options are absent, while retaining
buildNetworkingClient(it) for provided options. Add a test covering
same-configuration re-initialization after custom networking options, verifying
the client is restored to the default.

In `@src/types/common.ts`:
- Around line 247-256: Update the Android native mapping of enableLogging so it
is forwarded to DefaultClient.Builder.enableLogging only when the Android debug
build flag is enabled; release builds must force logging off regardless of the
public option. Add a release-build test covering enableLogging=true and
confirming the native logger remains disabled.

Apply the same fix in `@android/src/main/java/com/auth0/react/A0Auth0Module.kt` at
line 83.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 64ea7502-a514-4d9e-a609-5dba9b89b706

📥 Commits

Reviewing files that changed from the base of the PR and between 3f04576 and 4b062f9.

📒 Files selected for processing (14)
  • EXAMPLES.md
  • android/build.gradle
  • android/src/main/java/com/auth0/react/A0Auth0Module.kt
  • android/src/test/java/com/auth0/react/A0Auth0ModuleNetworkingOptionsTest.kt
  • ios/A0Auth0.mm
  • src/core/utils/__tests__/configSignature.spec.ts
  • src/core/utils/configSignature.ts
  • src/platforms/native/adapters/NativeAuth0Client.ts
  • src/platforms/native/adapters/__tests__/NativeAuth0Client.spec.ts
  • src/platforms/native/bridge/INativeBridge.ts
  • src/platforms/native/bridge/NativeBridgeManager.ts
  • src/platforms/native/bridge/__tests__/NativeBridgeManager.spec.ts
  • src/specs/NativeA0Auth0.ts
  • src/types/common.ts


this.useDPoP = useDPoP ?: false
auth0 = Auth0.getInstance(clientId, domain)
androidNetworkingOptions?.let { auth0!!.networkingClient = buildNetworkingClient(it) }

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -e
printf '%s\n' '--- target context ---'
sed -n '260,340p' android/src/main/java/com/auth0/react/A0Auth0Module.kt
printf '%s\n' '--- Auth0 dependency declarations ---'
rg -n -i 'auth0.android|auth0-android|com.auth0' android gradle* build.gradle* settings.gradle* package.json yarn.lock 2>/dev/null | head -200
printf '%s\n' '--- initialization and networking usages ---'
rg -n 'initializeAuth0WithConfiguration|buildNetworkingClient|networkingClient|androidNetworkingOptions|Auth0\.getInstance' android/src android 2>/dev/null | head -250

Repository: auth0/react-native-auth0

Length of output: 22137


🏁 Script executed:

#!/bin/bash
set -e
printf '%s\n' '--- target context ---'
sed -n '260,340p' android/src/main/java/com/auth0/react/A0Auth0Module.kt
printf '%s\n' '--- Auth0 dependency declarations ---'
rg -n -i 'auth0.android|auth0-android|com.auth0' android gradle\* build.gradle\* settings.gradle\* package.json yarn.lock 2>/dev/null | head -200
printf '%s\n' '--- initialization and networking usages ---'
rg -n 'initializeAuth0WithConfiguration|buildNetworkingClient|networkingClient|androidNetworkingOptions|Auth0\.getInstance' android/src android 2>/dev/null | head -250

Repository: auth0/react-native-auth0

Length of output: 22137


🏁 Script executed:

#!/bin/bash
set -e
url='https://raw.githubusercontent.com/auth0/Auth0.Android/4.0.1/auth0/src/main/java/com/auth0/android/Auth0.kt'
python3 - "$url" <<'PY'
import sys
from urllib.request import urlopen
url = sys.argv[1]
text = urlopen(url, timeout=10).read().decode()
for i, line in enumerate(text.splitlines(), 1):
    if 'getInstance' in line or 'networkingClient' in line or 'companion object' in line:
        start = max(1, i - 8)
        end = min(len(text.splitlines()), i + 14)
        print(f'--- lines {start}-{end} ---')
        print('\n'.join(f'{n}: {text.splitlines()[n-1]}' for n in range(start, end + 1)))
PY

Repository: auth0/react-native-auth0

Length of output: 2448


🌐 Web query:

Auth0.Android 4.0.1 Auth0.getInstance networkingClient singleton source

💡 Result:

In the Auth0.Android SDK (including version 4.0.1), the Auth0.getInstance method acts as a factory that returns a singleton instance of the Auth0 class for a given configuration [1]. Regarding your query about the networkingClient: 1. Singleton Behavior: The Auth0 class is managed as a singleton per configuration [1]. When you call Auth0.getInstance, it checks if an instance with the specified client ID and domain already exists; if so, it returns that existing instance [1]. 2. NetworkingClient Property: The Auth0 instance contains a networkingClient property (type NetworkingClient) which is used for all HTTP requests made by the library's various API clients (e.g., AuthenticationAPIClient, UsersAPIClient) [2][3][4]. 3. Customization: By default, this property is initialized with a DefaultClient [3]. You can replace it with a custom implementation by setting the networkingClient property directly on your Auth0 singleton instance [2][3]. Example of configuring the networking client: val account = Auth0.getInstance("{YOUR_CLIENT_ID}", "{YOUR_DOMAIN}") account.networkingClient = CustomNetworkingClient // Replace with your implementation Note that because the Auth0 instance is a singleton, changing the networkingClient on that instance will affect all subsequent API operations that rely on that specific Auth0 account instance [4].

Citations:


🏁 Script executed:

#!/bin/bash
set -e
url='https://raw.githubusercontent.com/auth0/Auth0.Android/4.0.1/auth0/src/main/java/com/auth0/android/Auth0.kt'
curl -fsSLk "$url" | nl -ba | awk '
  /companion object|fun getInstance|networkingClient|private constructor|class Auth0/ {
    start = NR - 8; if (start < 1) start = 1
    end = NR + 14
    print "--- lines " start "-" end " ---"
    for (i = start; i <= end; i++) lines[i] = lines[i]
  }
  { lines[NR] = $0 }
  END {
    # Re-read is not possible in this one-pass filter; print source-focused matches instead.
    for (i = 1; i <= NR; i++)
      if (lines[i] ~ /companion object|fun getInstance|networkingClient|private constructor|class Auth0/)
        print i ":" lines[i]
  }'
printf '%s\n' '--- local client builder and imports ---'
sed -n '1,105p' android/src/main/java/com/auth0/react/A0Auth0Module.kt

Repository: auth0/react-native-auth0

Length of output: 6617


Reset the networking client when options are omitted.

Auth0.getInstance(clientId, domain) reuses the same instance. A later initialization without androidNetworkingOptions preserves the previous custom networkingClient. Assign DefaultClient() when the options are absent, and add a same-configuration re-initialization test.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@android/src/main/java/com/auth0/react/A0Auth0Module.kt` at line 313, Update
the initialization flow around androidNetworkingOptions and
Auth0.getInstance(clientId, domain) so the Auth0 instance’s networkingClient is
explicitly reset to DefaultClient() when options are absent, while retaining
buildNetworkingClient(it) for provided options. Add a test covering
same-configuration re-initialization after custom networking options, verifying
the client is restored to the default.

Source: MCP tools

Comment thread src/types/common.ts
Comment on lines +247 to +256
/**
* Enables verbose HTTP request/response logging to Logcat.
*
* @remarks
* **Debug-only.** Auth0.Android logs full request and response bodies at this level,
* which includes access, refresh, and ID tokens in plaintext for token-endpoint calls.
* Never enable this in production.
* @default false
*/
enableLogging?: boolean;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔒 Security & Privacy | 🟠 Major | ⚡ Quick win

Enforce debug-only logging in the native implementation.

enableLogging is a public boolean. The Android mapper forwards it directly to DefaultClient.Builder.enableLogging. Auth0.Android then installs a BODY logging interceptor, which logs token-endpoint request and response bodies. A release build can therefore log access, refresh, and ID tokens when an application sets this option. (raw.githubusercontent.com)

Gate this option with the Android debug build flag before enabling the logger. Add a release-build test that confirms the option cannot enable logging.

As per coding guidelines: “Never commit secrets, API keys, or tokens, and never log access, refresh, or ID tokens.”

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/types/common.ts` around lines 247 - 256, Update the Android native
mapping of enableLogging so it is forwarded to
DefaultClient.Builder.enableLogging only when the Android debug build flag is
enabled; release builds must force logging off regardless of the public option.
Add a release-build test covering enableLogging=true and confirming the native
logger remains disabled.

Apply the same fix in `@android/src/main/java/com/auth0/react/A0Auth0Module.kt` at
line 83.

Source: Coding guidelines

@NandanPrabhu
NandanPrabhu marked this pull request as ready for review August 14, 2026 03:16
…ild.gradle

Verified the new A0Auth0ModuleNetworkingOptionsTest suite passes identically
with or without this option — nothing in buildNetworkingClient()'s path
touches an unstubbed Android framework API, so the fallback is dead config.
@NandanPrabhu
NandanPrabhu force-pushed the feat/sdk-10614-android-networking-config branch from fe1855c to 312fbe0 Compare August 14, 2026 03:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants