Skip to content

Commit 17bba3e

Browse files
committed
Improve notification logging
1 parent 83cb092 commit 17bba3e

4 files changed

Lines changed: 72 additions & 4 deletions

File tree

README.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,47 @@ const App = () => {
428428
export default App;
429429
```
430430

431+
#### Android Networking Configuration
432+
433+
> **Platform Support:** Android only.
434+
435+
You can configure the native networking client used by Auth0.Android for all requests (web auth, credential renewal, MFA, passkeys, etc.) by passing `networkingOptions`:
436+
437+
```js
438+
import { Auth0Provider } from 'react-native-auth0';
439+
440+
const App = () => {
441+
return (
442+
<Auth0Provider
443+
domain="YOUR_AUTH0_DOMAIN"
444+
clientId="YOUR_AUTH0_CLIENT_ID"
445+
networkingOptions={{
446+
connectTimeout: 30,
447+
readTimeout: 30,
448+
defaultHeaders: { 'X-App-Version': '1.2.3' },
449+
}}
450+
>
451+
{/* YOUR APP */}
452+
</Auth0Provider>
453+
);
454+
};
455+
456+
export default App;
457+
```
458+
459+
Available options:
460+
- `connectTimeout` (seconds, default 10)
461+
- `readTimeout` (seconds, default 10)
462+
- `writeTimeout` (seconds, default 10)
463+
- `callTimeout` (seconds, default 0 - no limit)
464+
- `defaultHeaders` (key-value pairs sent on every request)
465+
- `enableLogging` (boolean, default false - **debug-only**, logs full request/response bodies including tokens)
466+
467+
> [!WARNING]
468+
> Never enable `enableLogging` in production builds. Auth0.Android logs full HTTP bodies including access, refresh, and ID tokens in plaintext.
469+
470+
For detailed examples, see the [Android Networking Configuration](EXAMPLES.md#android-networking-configuration) section in EXAMPLES.md.
471+
431472
<details>
432473
<summary>Using the `Auth0` class</summary>
433474

@@ -456,6 +497,21 @@ const auth0 = new Auth0({
456497
});
457498
```
458499

500+
You can also configure Android networking options:
501+
502+
```js
503+
import Auth0 from 'react-native-auth0';
504+
505+
const auth0 = new Auth0({
506+
domain: 'YOUR_AUTH0_DOMAIN',
507+
clientId: 'YOUR_AUTH0_CLIENT_ID',
508+
networkingOptions: {
509+
connectTimeout: 30,
510+
readTimeout: 30,
511+
},
512+
});
513+
```
514+
459515
</details>
460516

461517
Then import the hook into a component where you want to get access to the properties and methods for integrating with Auth0:

android/src/main/java/com/auth0/react/A0Auth0Module.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ class A0Auth0Module(private val reactContext: ReactApplicationContext) : A0Auth0
8282
options.getMap("defaultHeaders")?.let { headers ->
8383
builder.defaultHeaders(headers.toHashMap().mapValues { it.value?.toString() ?: "" })
8484
}
85+
// Only honor enableLogging on debug builds: Auth0.Android logs full request/response
86+
// bodies at this level, including plaintext access/refresh/ID tokens from token-endpoint
87+
// responses. Test coverage in A0Auth0ModuleNetworkingOptionsTest ensures this gate holds.
8588
if (isDebuggable && options.hasKey("enableLogging")) {
8689
builder.enableLogging(options.getBoolean("enableLogging"))
8790
}

android/src/test/java/com/auth0/react/A0Auth0ModuleNetworkingOptionsTest.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,10 @@ class A0Auth0ModuleNetworkingOptionsTest {
8080
fun `enableLogging is ignored on a non-debuggable build even when requested`() {
8181
server.enqueue(MockResponse().setBody("{}"))
8282

83-
// If the debuggable gate is ever removed, Auth0.Android attaches its logging
84-
// interceptor and this request crashes ("Method ... not mocked") because
85-
// android.util.Log isn't stubbed in this unit test environment - that crash is
86-
// exactly the regression this test is meant to catch.
83+
// SECURITY: If the isDebuggable gate is ever removed, Auth0.Android attaches its
84+
// logging interceptor which logs full request/response bodies (including tokens).
85+
// This test would crash ("Method android.util.Log not mocked") if that happens,
86+
// catching the security regression before it ships.
8787
val client = A0Auth0Module.buildNetworkingClient(
8888
JavaOnlyMap.of("enableLogging", true),
8989
isDebuggable = false

src/types/common.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,15 @@ export interface Auth0Options {
228228
* Mirrors `DefaultClient.Builder` from the Auth0.Android SDK.
229229
*
230230
* @remarks Android only. Has no effect on iOS or web.
231+
*
232+
* @example
233+
* ```ts
234+
* networkingOptions: {
235+
* connectTimeout: 30,
236+
* readTimeout: 30,
237+
* defaultHeaders: { 'X-App-Version': '1.2.3' }
238+
* }
239+
* ```
231240
*/
232241
export interface NetworkingOptions {
233242
/** Connection timeout, in seconds. @default 10 */

0 commit comments

Comments
 (0)