diff --git a/CONTRIBUTORS b/CONTRIBUTORS index 225c16b9..034bee8b 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -13,3 +13,4 @@ Alex Chau Benjamin Franz Rebecka Gulliksson Rahul Ravikumar +Henning Nielsen Lund diff --git a/library/java/net/openid/appauth/AuthorizationService.java b/library/java/net/openid/appauth/AuthorizationService.java index 5b9d90fd..adc12d7d 100644 --- a/library/java/net/openid/appauth/AuthorizationService.java +++ b/library/java/net/openid/appauth/AuthorizationService.java @@ -130,6 +130,15 @@ public CustomTabsIntent.Builder createCustomTabsIntentBuilder(Uri... possibleUri return mCustomTabManager.createTabBuilder(possibleUris); } + /** + * Creates a CustomTabsIntent, where the package is set to the one of the BrowserDescriptor. + */ + public CustomTabsIntent createCustomTabsIntent(Uri... possibleUris) { + CustomTabsIntent customTabsIntent = createCustomTabsIntentBuilder(possibleUris).build(); + customTabsIntent.intent.setPackage(mBrowser.packageName); + return customTabsIntent; + } + /** * Sends an authorization request to the authorization service, using a * [custom tab](https://developer.chrome.com/multidevice/android/customtabs) diff --git a/library/javatests/net/openid/appauth/AuthorizationServiceTest.java b/library/javatests/net/openid/appauth/AuthorizationServiceTest.java index bfda6b87..80a73d7a 100644 --- a/library/javatests/net/openid/appauth/AuthorizationServiceTest.java +++ b/library/javatests/net/openid/appauth/AuthorizationServiceTest.java @@ -27,6 +27,7 @@ import net.openid.appauth.AppAuthConfiguration.Builder; import net.openid.appauth.AuthorizationException.GeneralErrors; +import net.openid.appauth.browser.BrowserDescriptor; import net.openid.appauth.browser.Browsers; import net.openid.appauth.browser.CustomTabManager; import net.openid.appauth.connectivity.ConnectionBuilder; @@ -220,6 +221,36 @@ public void testGetAuthorizationRequestIntent_withCustomTabs_preservesTabSetting .isEqualTo(CustomTabsIntent.SHOW_PAGE_TITLE); } + @Test + public void testCreateCustomTabsIntent_Chrome() { + BrowserDescriptor browser = Browsers.Chrome.customTab("46"); + mService = new AuthorizationService( + mContext, + new Builder() + .setConnectionBuilder(mConnectionBuilder) + .build(), + browser, + mCustomTabManager); + CustomTabsIntent customTabsIntent = mService.createCustomTabsIntent(); + assertNotNull(customTabsIntent.intent.getPackage()); + assertTrue(customTabsIntent.intent.getPackage().equals(browser.packageName)); + } + + @Test + public void testCreateCustomTabsIntent_Samsung() { + BrowserDescriptor browser = Browsers.SBrowser.customTab("7.2.10.33"); + mService = new AuthorizationService( + mContext, + new Builder() + .setConnectionBuilder(mConnectionBuilder) + .build(), + browser, + mCustomTabManager); + CustomTabsIntent customTabsIntent = mService.createCustomTabsIntent(); + assertNotNull(customTabsIntent.intent.getPackage()); + assertTrue(customTabsIntent.intent.getPackage().equals(browser.packageName)); + } + @Test public void testTokenRequest() throws Exception { InputStream is = new ByteArrayInputStream(AUTH_CODE_EXCHANGE_RESPONSE_JSON.getBytes());