Skip to content

Commit b20561a

Browse files
authored
useNonce android support (#640)
* useNonce android support * Update tests with useNonce
1 parent 7bf86d9 commit b20561a

File tree

5 files changed

+10814
-2
lines changed

5 files changed

+10814
-2
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ with optional overrides.
132132
- **token** - (`{ [key: string]: value }`) headers to be passed during token retrieval request.
133133
- **register** - (`{ [key: string]: value }`) headers to be passed during registration request.
134134
- **additionalHeaders** - (`{ [key: string]: value }`) _IOS_ you can specify additional headers to be passed for all authorize, refresh, and register requests.
135-
- **useNonce** - (`boolean`) _IOS_ (default: true) optionally allows not sending the nonce parameter, to support non-compliant providers
135+
- **useNonce** - (`boolean`) (default: true) optionally allows not sending the nonce parameter, to support non-compliant providers
136136
- **usePKCE** - (`boolean`) (default: true) optionally allows not sending the code_challenge parameter and skipping PKCE code verification, to support non-compliant providers.
137137
- **skipCodeExchange** - (`boolean`) (default: false) just return the authorization response, instead of automatically exchanging the authorization code. This is useful if this exchange needs to be done manually (not client-side)
138138

android/src/main/java/com/rnappauth/RNAppAuthModule.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ public class RNAppAuthModule extends ReactContextBaseJavaModule implements Activ
6565
private boolean dangerouslyAllowInsecureHttpRequests;
6666
private Boolean skipCodeExchange;
6767
private Boolean usePKCE;
68+
private Boolean useNonce;
6869
private String codeVerifier;
6970
private String clientAuthMethod = "basic";
7071
private Map<String, String> registrationRequestHeaders = null;
@@ -221,6 +222,7 @@ public void authorize(
221222
final ReadableMap additionalParameters,
222223
final ReadableMap serviceConfiguration,
223224
final Boolean skipCodeExchange,
225+
final Boolean useNonce,
224226
final Boolean usePKCE,
225227
final String clientAuthMethod,
226228
final boolean dangerouslyAllowInsecureHttpRequests,
@@ -239,6 +241,7 @@ public void authorize(
239241
this.clientSecret = clientSecret;
240242
this.clientAuthMethod = clientAuthMethod;
241243
this.skipCodeExchange = skipCodeExchange;
244+
this.useNonce = useNonce;
242245
this.usePKCE = usePKCE;
243246

244247
// when serviceConfiguration is provided, we don't need to hit up the OpenID well-known id endpoint
@@ -251,6 +254,7 @@ public void authorize(
251254
clientId,
252255
scopes,
253256
redirectUrl,
257+
useNonce,
254258
usePKCE,
255259
additionalParametersMap
256260
);
@@ -281,6 +285,7 @@ public void onFetchConfigurationCompleted(
281285
clientId,
282286
scopes,
283287
redirectUrl,
288+
useNonce,
284289
usePKCE,
285290
additionalParametersMap
286291
);
@@ -532,6 +537,7 @@ private void authorizeWithConfiguration(
532537
final String clientId,
533538
final ReadableArray scopes,
534539
final String redirectUrl,
540+
final Boolean useNonce,
535541
final Boolean usePKCE,
536542
final Map<String, String> additionalParametersMap
537543
) {
@@ -557,7 +563,6 @@ private void authorizeWithConfiguration(
557563
authRequestBuilder.setScope(scopesString);
558564
}
559565

560-
561566
if (additionalParametersMap != null) {
562567
// handle additional parameters separately to avoid exceptions from AppAuth
563568
if (additionalParametersMap.containsKey("display")) {
@@ -587,6 +592,10 @@ private void authorizeWithConfiguration(
587592
authRequestBuilder.setCodeVerifier(this.codeVerifier);
588593
}
589594

595+
if(!useNonce) {
596+
authRequestBuilder.setNonce(null);
597+
}
598+
590599
AuthorizationRequest authRequest = authRequestBuilder.build();
591600

592601
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {

index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ export const authorize = ({
198198
];
199199

200200
if (Platform.OS === 'android') {
201+
nativeMethodArguments.push(useNonce);
201202
nativeMethodArguments.push(usePKCE);
202203
nativeMethodArguments.push(clientAuthMethod);
203204
nativeMethodArguments.push(dangerouslyAllowInsecureHttpRequests);

index.spec.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,7 @@ describe('AppAuth', () => {
582582
config.additionalParameters,
583583
config.serviceConfiguration,
584584
config.skipCodeExchange,
585+
config.useNonce,
585586
config.usePKCE,
586587
config.clientAuthMethod,
587588
false,
@@ -600,6 +601,7 @@ describe('AppAuth', () => {
600601
config.additionalParameters,
601602
config.serviceConfiguration,
602603
false,
604+
config.useNonce,
603605
config.usePKCE,
604606
config.clientAuthMethod,
605607
false,
@@ -618,6 +620,7 @@ describe('AppAuth', () => {
618620
config.additionalParameters,
619621
config.serviceConfiguration,
620622
false,
623+
config.useNonce,
621624
config.usePKCE,
622625
config.clientAuthMethod,
623626
true,
@@ -645,6 +648,7 @@ describe('AppAuth', () => {
645648
config.additionalParameters,
646649
config.serviceConfiguration,
647650
false,
651+
config.useNonce,
648652
config.usePKCE,
649653
config.clientAuthMethod,
650654
false,
@@ -838,6 +842,7 @@ describe('AppAuth', () => {
838842
config.additionalParameters,
839843
config.serviceConfiguration,
840844
false,
845+
config.useNonce,
841846
config.usePKCE,
842847
config.clientAuthMethod,
843848
false,

0 commit comments

Comments
 (0)