|
25 | 25 | import com.facebook.react.bridge.ReadableType; |
26 | 26 |
|
27 | 27 | import com.rnappauth.utils.MapUtil; |
| 28 | +import com.rnappauth.utils.MutableBrowserAllowList; |
28 | 29 | import com.rnappauth.utils.UnsafeConnectionBuilder; |
29 | 30 | import com.rnappauth.utils.RegistrationResponseFactory; |
30 | 31 | import com.rnappauth.utils.TokenResponseFactory; |
|
46 | 47 | import net.openid.appauth.ResponseTypeValues; |
47 | 48 | import net.openid.appauth.TokenResponse; |
48 | 49 | import net.openid.appauth.TokenRequest; |
| 50 | +import net.openid.appauth.browser.AnyBrowserMatcher; |
| 51 | +import net.openid.appauth.browser.BrowserMatcher; |
| 52 | +import net.openid.appauth.browser.VersionedBrowserMatcher; |
49 | 53 | import net.openid.appauth.EndSessionRequest; |
50 | 54 | import net.openid.appauth.EndSessionResponse; |
51 | 55 | import net.openid.appauth.connectivity.ConnectionBuilder; |
@@ -164,7 +168,7 @@ public void register( |
164 | 168 | ) { |
165 | 169 | this.parseHeaderMap(headers); |
166 | 170 | final ConnectionBuilder builder = createConnectionBuilder(dangerouslyAllowInsecureHttpRequests, this.registrationRequestHeaders, connectionTimeoutMillis); |
167 | | - final AppAuthConfiguration appAuthConfiguration = this.createAppAuthConfiguration(builder, dangerouslyAllowInsecureHttpRequests); |
| 171 | + final AppAuthConfiguration appAuthConfiguration = this.createAppAuthConfiguration(builder, dangerouslyAllowInsecureHttpRequests, null); |
168 | 172 | final HashMap<String, String> additionalParametersMap = MapUtil.readableMapToHashMap(additionalParameters); |
169 | 173 |
|
170 | 174 | // when serviceConfiguration is provided, we don't need to hit up the OpenID well-known id endpoint |
@@ -233,11 +237,12 @@ public void authorize( |
233 | 237 | final String clientAuthMethod, |
234 | 238 | final boolean dangerouslyAllowInsecureHttpRequests, |
235 | 239 | final ReadableMap headers, |
| 240 | + final ReadableArray androidAllowCustomBrowsers, |
236 | 241 | final Promise promise |
237 | 242 | ) { |
238 | 243 | this.parseHeaderMap(headers); |
239 | 244 | final ConnectionBuilder builder = createConnectionBuilder(dangerouslyAllowInsecureHttpRequests, this.authorizationRequestHeaders, connectionTimeoutMillis); |
240 | | - final AppAuthConfiguration appAuthConfiguration = this.createAppAuthConfiguration(builder, dangerouslyAllowInsecureHttpRequests); |
| 245 | + final AppAuthConfiguration appAuthConfiguration = this.createAppAuthConfiguration(builder, dangerouslyAllowInsecureHttpRequests, androidAllowCustomBrowsers); |
241 | 246 | final HashMap<String, String> additionalParametersMap = MapUtil.readableMapToHashMap(additionalParameters); |
242 | 247 |
|
243 | 248 | // store args in private fields for later use in onActivityResult handler |
@@ -325,11 +330,12 @@ public void refresh( |
325 | 330 | final String clientAuthMethod, |
326 | 331 | final boolean dangerouslyAllowInsecureHttpRequests, |
327 | 332 | final ReadableMap headers, |
| 333 | + final ReadableArray androidAllowCustomBrowsers, |
328 | 334 | final Promise promise |
329 | 335 | ) { |
330 | 336 | this.parseHeaderMap(headers); |
331 | 337 | final ConnectionBuilder builder = createConnectionBuilder(dangerouslyAllowInsecureHttpRequests, this.tokenRequestHeaders, connectionTimeoutMillis); |
332 | | - final AppAuthConfiguration appAuthConfiguration = createAppAuthConfiguration(builder, dangerouslyAllowInsecureHttpRequests); |
| 338 | + final AppAuthConfiguration appAuthConfiguration = createAppAuthConfiguration(builder, dangerouslyAllowInsecureHttpRequests, androidAllowCustomBrowsers); |
333 | 339 | final HashMap<String, String> additionalParametersMap = MapUtil.readableMapToHashMap(additionalParameters); |
334 | 340 |
|
335 | 341 | if (clientSecret != null) { |
@@ -409,10 +415,11 @@ public void logout( |
409 | 415 | final ReadableMap serviceConfiguration, |
410 | 416 | final ReadableMap additionalParameters, |
411 | 417 | final boolean dangerouslyAllowInsecureHttpRequests, |
| 418 | + final ReadableArray androidAllowCustomBrowsers, |
412 | 419 | final Promise promise |
413 | 420 | ) { |
414 | 421 | final ConnectionBuilder builder = createConnectionBuilder(dangerouslyAllowInsecureHttpRequests, null); |
415 | | - final AppAuthConfiguration appAuthConfiguration = this.createAppAuthConfiguration(builder, dangerouslyAllowInsecureHttpRequests); |
| 422 | + final AppAuthConfiguration appAuthConfiguration = this.createAppAuthConfiguration(builder, dangerouslyAllowInsecureHttpRequests, androidAllowCustomBrowsers); |
416 | 423 | final HashMap<String, String> additionalParametersMap = MapUtil.readableMapToHashMap(additionalParameters); |
417 | 424 |
|
418 | 425 | this.promise = promise; |
@@ -507,7 +514,8 @@ public void onActivityResult(Activity activity, int requestCode, int resultCode, |
507 | 514 | final Promise authorizePromise = this.promise; |
508 | 515 | final AppAuthConfiguration configuration = createAppAuthConfiguration( |
509 | 516 | createConnectionBuilder(this.dangerouslyAllowInsecureHttpRequests, this.tokenRequestHeaders), |
510 | | - this.dangerouslyAllowInsecureHttpRequests |
| 517 | + this.dangerouslyAllowInsecureHttpRequests, |
| 518 | + null |
511 | 519 | ); |
512 | 520 |
|
513 | 521 | AuthorizationService authService = new AuthorizationService(this.reactContext, configuration); |
@@ -885,10 +893,12 @@ private List<Uri> arrayToUriList(ReadableArray array) { |
885 | 893 | */ |
886 | 894 | private AppAuthConfiguration createAppAuthConfiguration( |
887 | 895 | ConnectionBuilder connectionBuilder, |
888 | | - Boolean skipIssuerHttpsCheck |
| 896 | + Boolean skipIssuerHttpsCheck, |
| 897 | + ReadableArray androidAllowCustomBrowsers |
889 | 898 | ) { |
890 | 899 | return new AppAuthConfiguration |
891 | 900 | .Builder() |
| 901 | + .setBrowserMatcher(getBrowserAllowList(androidAllowCustomBrowsers)) |
892 | 902 | .setConnectionBuilder(connectionBuilder) |
893 | 903 | .setSkipIssuerHttpsCheck(skipIssuerHttpsCheck) |
894 | 904 | .build(); |
@@ -1019,6 +1029,50 @@ private void setServiceConfiguration(@Nullable String issuer, AuthorizationServi |
1019 | 1029 | } |
1020 | 1030 | } |
1021 | 1031 |
|
| 1032 | + private BrowserMatcher getBrowserAllowList(ReadableArray androidAllowCustomBrowsers) { |
| 1033 | + if(androidAllowCustomBrowsers == null || androidAllowCustomBrowsers.size() == 0) { |
| 1034 | + return AnyBrowserMatcher.INSTANCE; |
| 1035 | + } |
| 1036 | + |
| 1037 | + MutableBrowserAllowList browserMatchers = new MutableBrowserAllowList(); |
| 1038 | + |
| 1039 | + for(int i = 0; i < androidAllowCustomBrowsers.size(); i++) { |
| 1040 | + String browser = androidAllowCustomBrowsers.getString(i); |
| 1041 | + |
| 1042 | + if(browser == null) { |
| 1043 | + continue; |
| 1044 | + } |
| 1045 | + |
| 1046 | + switch (browser) { |
| 1047 | + case "chrome": { |
| 1048 | + browserMatchers.add(VersionedBrowserMatcher.CHROME_BROWSER); |
| 1049 | + break; |
| 1050 | + } |
| 1051 | + case "chromeCustomTab": { |
| 1052 | + browserMatchers.add(VersionedBrowserMatcher.CHROME_CUSTOM_TAB); |
| 1053 | + break; |
| 1054 | + } |
| 1055 | + case "firefox": { |
| 1056 | + browserMatchers.add(VersionedBrowserMatcher.FIREFOX_BROWSER); |
| 1057 | + break; |
| 1058 | + } |
| 1059 | + case "firefoxCustomTab": { |
| 1060 | + browserMatchers.add(VersionedBrowserMatcher.FIREFOX_CUSTOM_TAB); |
| 1061 | + break; |
| 1062 | + } |
| 1063 | + case "samsung": { |
| 1064 | + browserMatchers.add(VersionedBrowserMatcher.SAMSUNG_BROWSER); |
| 1065 | + break; |
| 1066 | + } |
| 1067 | + case "samsungCustomTab": { |
| 1068 | + browserMatchers.add(VersionedBrowserMatcher.SAMSUNG_CUSTOM_TAB); |
| 1069 | + break; |
| 1070 | + } |
| 1071 | + } |
| 1072 | + } |
| 1073 | + return browserMatchers; |
| 1074 | + } |
| 1075 | + |
1022 | 1076 | @Override |
1023 | 1077 | public void onNewIntent(Intent intent) { |
1024 | 1078 |
|
|
0 commit comments