-
Notifications
You must be signed in to change notification settings - Fork 84
Auth Tab, Close listener functionality #409
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
kgangineni
wants to merge
32
commits into
develop
Choose a base branch
from
closeAuthTab
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
9eff7bc
Migrate BrowserSwitch files to new branch to avoid rebase/merge confl…
sshropshire c87c477
Restore compilation.
sshropshire 7b326c0
Fix some broken unit tests.
sshropshire c095f65
Move finish function out of BrowserSwitchClient and into BrowserSwitc…
sshropshire 105c682
Implement capture deep link for PayPalWebLauncher.
sshropshire 5bc5eef
Implement CardAuthLauncher deep linking refactor.
sshropshire ce15f0f
Fix cyclomatic complexity in captureDeepLink class.
sshropshire 04d3d07
Fix detekt errors.
sshropshire 9599637
Remove obselete unit tests.
sshropshire 8d38719
Address additional detekt linter errors.
sshropshire a7afad6
Suppress detekt lint error about too many returns.
sshropshire 960f6f9
Restrict all deep link utils.
sshropshire b818eb8
Add additional restrict annotations.
sshropshire bebfcf3
Add proper restrict annotations to browser switch api.
sshropshire a3aa3b4
Update static analysis workflow mac os version.
sshropshire 808e312
Simplify deep link capture logic.
sshropshire baa7f42
Make helper methods private.
sshropshire ed72989
Add comment to BrowserSwitchRequestCodes.
sshropshire 3597042
Remove V2 suffixes from deep link parsing classes.
sshropshire ad2a22d
Fix api breakage.
sshropshire d7e896a
Modify return types of capture deep link.
sshropshire 4b1122c
Add auth tab launcher support for PayPal checkout
kgangineni cfc38c2
Add unit tests for auth tab launcher functionality
kgangineni af9f06d
Merge branch 'develop' into closeAuthTab
kgangineni 3ae0902
fix static analysis and API check
kgangineni 49f58a4
⏺ Fallback scenarios when auth tab is not supported
kgangineni 68adbb9
Fix Unit tests
kgangineni fc2c282
check default browser when checking for auth tab support instead of j…
kgangineni 23fe558
add info and documentation
kgangineni 4fc4040
fix PR feedback
kgangineni e18f486
- updates androidTargetVersion
kgangineni eb68e8a
fix unit tests
kgangineni File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
CorePayments/src/main/java/com/paypal/android/corepayments/browserswitch/AuthTabClient.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| package com.paypal.android.corepayments.browserswitch | ||
|
|
||
| import android.content.Intent | ||
| import androidx.activity.result.ActivityResultLauncher | ||
| import androidx.browser.auth.AuthTabIntent | ||
| import androidx.core.net.toUri | ||
|
|
||
| class AuthTabClient { | ||
| fun launchAuthTab( | ||
| options: ChromeCustomTabOptions, | ||
| activityResultLauncher: ActivityResultLauncher<Intent>, | ||
| appLinkUrl: String? = null, | ||
| returnUrlScheme: String? = null | ||
| ) { | ||
| val appLinkUri = appLinkUrl?.toUri() | ||
| val redirectHost = appLinkUri?.host | ||
| val redirectPath = appLinkUri?.path | ||
| val authTabIntent = AuthTabIntent.Builder().build() | ||
|
|
||
| when { | ||
| redirectHost != null && redirectPath != null -> { | ||
| authTabIntent.launch( | ||
| activityResultLauncher, | ||
| options.launchUri, | ||
| redirectHost, | ||
| redirectPath | ||
| ) | ||
| } | ||
|
|
||
| returnUrlScheme != null -> { | ||
| authTabIntent.launch( | ||
| activityResultLauncher, | ||
| options.launchUri, | ||
| returnUrlScheme | ||
| ) | ||
| } | ||
|
|
||
| else -> { | ||
| throw IllegalArgumentException("Either appLinkUrl or returnUrlScheme must be provided") | ||
| } | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
135 changes: 135 additions & 0 deletions
135
...ents/src/test/java/com/paypal/android/corepayments/browserswitch/AuthTabClientUnitTest.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,135 @@ | ||
| package com.paypal.android.corepayments.browserswitch | ||
|
|
||
| import android.content.Intent | ||
| import androidx.activity.result.ActivityResultLauncher | ||
| import androidx.core.net.toUri | ||
| import io.mockk.mockk | ||
| import io.mockk.slot | ||
| import io.mockk.verify | ||
| import org.junit.Assert.assertEquals | ||
| import org.junit.Assert.assertNotNull | ||
| import org.junit.Assert.assertThrows | ||
| import org.junit.Before | ||
| import org.junit.Test | ||
| import org.junit.runner.RunWith | ||
| import org.robolectric.RobolectricTestRunner | ||
|
|
||
| @RunWith(RobolectricTestRunner::class) | ||
| class AuthTabClientUnitTest { | ||
|
|
||
| private lateinit var sut: AuthTabClient | ||
| private lateinit var activityResultLauncher: ActivityResultLauncher<Intent> | ||
| private lateinit var options: ChromeCustomTabOptions | ||
|
|
||
| @Before | ||
| fun beforeEach() { | ||
| sut = AuthTabClient() | ||
| activityResultLauncher = mockk(relaxed = true) | ||
| options = ChromeCustomTabOptions(launchUri = "https://example.com/auth".toUri()) | ||
| } | ||
|
|
||
| @Test | ||
| fun `launchAuthTab with appLinkUrl launches auth tab with host and path`() { | ||
| val appLinkUrl = "https://example.com/return/path" | ||
| val intentSlot = slot<Intent>() | ||
|
|
||
| sut.launchAuthTab( | ||
| options = options, | ||
| activityResultLauncher = activityResultLauncher, | ||
| appLinkUrl = appLinkUrl, | ||
| returnUrlScheme = null | ||
| ) | ||
|
|
||
| verify { activityResultLauncher.launch(capture(intentSlot)) } | ||
| val intent = intentSlot.captured | ||
| assertNotNull(intent) | ||
| assertEquals("https://example.com/auth", intent.data?.toString()) | ||
| } | ||
|
|
||
| @Test | ||
| fun `launchAuthTab with returnUrlScheme launches auth tab with scheme`() { | ||
| val returnUrlScheme = "com.example.app" | ||
| val intentSlot = slot<Intent>() | ||
|
|
||
| sut.launchAuthTab( | ||
| options = options, | ||
| activityResultLauncher = activityResultLauncher, | ||
| appLinkUrl = null, | ||
| returnUrlScheme = returnUrlScheme | ||
| ) | ||
|
|
||
| verify { activityResultLauncher.launch(capture(intentSlot)) } | ||
| val intent = intentSlot.captured | ||
| assertNotNull(intent) | ||
| assertEquals("https://example.com/auth", intent.data?.toString()) | ||
| } | ||
|
|
||
| @Test | ||
| fun `launchAuthTab throws when both appLinkUrl and returnUrlScheme are null`() { | ||
| val exception = assertThrows(IllegalArgumentException::class.java) { | ||
| sut.launchAuthTab( | ||
| options = options, | ||
| activityResultLauncher = activityResultLauncher, | ||
| appLinkUrl = null, | ||
| returnUrlScheme = null | ||
| ) | ||
| } | ||
|
|
||
| assert(exception.message == "Either appLinkUrl or returnUrlScheme must be provided") | ||
| } | ||
|
|
||
| @Test | ||
| fun `launchAuthTab with appLinkUrl with root path launches auth tab successfully`() { | ||
| val appLinkUrl = "https://example.com" | ||
| val intentSlot = slot<Intent>() | ||
|
|
||
| sut.launchAuthTab( | ||
| options = options, | ||
| activityResultLauncher = activityResultLauncher, | ||
| appLinkUrl = appLinkUrl, | ||
| returnUrlScheme = null | ||
| ) | ||
|
|
||
| verify { activityResultLauncher.launch(capture(intentSlot)) } | ||
| val intent = intentSlot.captured | ||
| assertNotNull(intent) | ||
| assertEquals("https://example.com/auth", intent.data?.toString()) | ||
| } | ||
|
|
||
| @Test | ||
| fun `launchAuthTab prefers appLinkUrl when both appLinkUrl and returnUrlScheme are provided`() { | ||
| val appLinkUrl = "https://example.com/return/path" | ||
| val returnUrlScheme = "com.example.app" | ||
| val intentSlot = slot<Intent>() | ||
|
|
||
| sut.launchAuthTab( | ||
| options = options, | ||
| activityResultLauncher = activityResultLauncher, | ||
| appLinkUrl = appLinkUrl, | ||
| returnUrlScheme = returnUrlScheme | ||
| ) | ||
|
|
||
| verify { activityResultLauncher.launch(capture(intentSlot)) } | ||
| val intent = intentSlot.captured | ||
| assertNotNull(intent) | ||
| assertEquals("https://example.com/auth", intent.data?.toString()) | ||
| } | ||
|
|
||
| @Test | ||
| fun `launchAuthTab with valid appLinkUrl parses host and path correctly`() { | ||
| val appLinkUrl = "https://paypal.com/checkoutnow/return" | ||
| val intentSlot = slot<Intent>() | ||
|
|
||
| sut.launchAuthTab( | ||
| options = options, | ||
| activityResultLauncher = activityResultLauncher, | ||
| appLinkUrl = appLinkUrl, | ||
| returnUrlScheme = null | ||
| ) | ||
|
|
||
| verify { activityResultLauncher.launch(capture(intentSlot)) } | ||
| val intent = intentSlot.captured | ||
| assertNotNull(intent) | ||
| assertEquals("https://example.com/auth", intent.data?.toString()) | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In a strict sense, this is technically a breaking change. Is there a way to prevent this change?