Skip to content

Commit e7468f1

Browse files
sebkkadikraman
authored andcommitted
Use pkce android (#284)
* Add usePKCE parameter for authorize method on Android * Applied usePKCE to the nativeMethodArguments * Updated Readme: Removed iOS only from usePKCE config description * Updated tests * Avoid disrupting the parameter order for iOS
1 parent 390df23 commit e7468f1

File tree

4 files changed

+20
-6
lines changed

4 files changed

+20
-6
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ with optional overrides.
103103
* **authorize** - (`{ [key: string]: value }`) headers to be passed during authorization request.
104104
* **token** - (`{ [key: string]: value }`) headers to be passed during token retrieval request.
105105
* **useNonce** - (`boolean`) _IOS_ (default: true) optionally allows not sending the nonce parameter, to support non-compliant providers
106-
* **usePKCE** - (`boolean`) _IOS_ (default: true) optionally allows not sending the code_challenge parameter and skipping PKCE code verification, to support non-compliant providers.
106+
* **usePKCE** - (`boolean`) (default: true) optionally allows not sending the code_challenge parameter and skipping PKCE code verification, to support non-compliant providers.
107107

108108
#### result
109109

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ public void authorize(
6666
final ReadableArray scopes,
6767
final ReadableMap additionalParameters,
6868
final ReadableMap serviceConfiguration,
69+
final Boolean usePKCE,
6970
final String clientAuthMethod,
7071
final Boolean dangerouslyAllowInsecureHttpRequests,
7172
final ReadableMap headers,
@@ -96,6 +97,7 @@ public void authorize(
9697
clientId,
9798
scopes,
9899
redirectUrl,
100+
usePKCE,
99101
additionalParametersMap
100102
);
101103
} catch (Exception e) {
@@ -120,6 +122,7 @@ public void onFetchConfigurationCompleted(
120122
clientId,
121123
scopes,
122124
redirectUrl,
125+
usePKCE,
123126
additionalParametersMap
124127
);
125128
}
@@ -268,6 +271,7 @@ private void authorizeWithConfiguration(
268271
final String clientId,
269272
final ReadableArray scopes,
270273
final String redirectUrl,
274+
final Boolean usePKCE,
271275
final Map<String, String> additionalParametersMap
272276
) {
273277

@@ -311,6 +315,10 @@ private void authorizeWithConfiguration(
311315
authRequestBuilder.setAdditionalParameters(additionalParametersMap);
312316
}
313317

318+
if (!usePKCE) {
319+
authRequestBuilder.setCodeVerifier(null);
320+
}
321+
314322
AuthorizationRequest authRequest = authRequestBuilder.build();
315323

316324
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
@@ -82,6 +82,7 @@ export const authorize = ({
8282
nativeMethodArguments.push(clientAuthMethod);
8383
nativeMethodArguments.push(dangerouslyAllowInsecureHttpRequests);
8484
nativeMethodArguments.push(customHeaders);
85+
nativeMethodArguments.push(usePKCE);
8586
}
8687

8788
if (Platform.OS === 'ios') {

index.spec.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,8 @@ describe('AppAuth', () => {
167167
config.serviceConfiguration,
168168
config.clientAuthMethod,
169169
false,
170-
config.customHeaders
170+
config.customHeaders,
171+
config.usePKCE
171172
);
172173
});
173174

@@ -183,7 +184,8 @@ describe('AppAuth', () => {
183184
config.serviceConfiguration,
184185
config.clientAuthMethod,
185186
false,
186-
config.customHeaders
187+
config.customHeaders,
188+
config.usePKCE
187189
);
188190
});
189191

@@ -199,7 +201,8 @@ describe('AppAuth', () => {
199201
config.serviceConfiguration,
200202
config.clientAuthMethod,
201203
true,
202-
config.customHeaders
204+
config.customHeaders,
205+
config.usePKCE
203206
);
204207
});
205208
});
@@ -219,7 +222,8 @@ describe('AppAuth', () => {
219222
config.serviceConfiguration,
220223
config.clientAuthMethod,
221224
false,
222-
customHeaders
225+
customHeaders,
226+
config.usePKCE
223227
);
224228
});
225229
});
@@ -372,7 +376,8 @@ describe('AppAuth', () => {
372376
config.serviceConfiguration,
373377
config.clientAuthMethod,
374378
false,
375-
customHeaders
379+
customHeaders,
380+
config.usePKCE
376381
);
377382
});
378383
});

0 commit comments

Comments
 (0)