-
Notifications
You must be signed in to change notification settings - Fork 126
feat(auth): Prefer Private Session support for WebUI Sign In's #3108
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
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
b5b655a
private session support for hosted ui sign ins (Ephemeral CustomTabs)
tylerjroach 592aa11
Merge branch 'main' into tjroach/prefer-private-sessions
tylerjroach 3c9f81d
Update to stable version
tylerjroach 733f729
documentation
tylerjroach 1de08d6
tests
tylerjroach a89cdbc
Merge branch 'main' into tjroach/prefer-private-sessions
tylerjroach d910c29
update javadocs
tylerjroach 4db17e6
Merge branch 'main' into tjroach/prefer-private-sessions
tylerjroach d9a2642
Merge branch 'main' into tjroach/prefer-private-sessions
tylerjroach a818581
Merge branch 'main' into tjroach/prefer-private-sessions
tylerjroach 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
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
120 changes: 120 additions & 0 deletions
120
...uth-cognito/src/test/java/com/amplifyframework/auth/cognito/helpers/HostedUIHelperTest.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,120 @@ | ||
/* | ||
* Copyright 2025 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"). | ||
* You may not use this file except in compliance with the License. | ||
* A copy of the License is located at | ||
* | ||
* http://aws.amazon.com/apache2.0 | ||
* | ||
* or in the "license" file accompanying this file. This file is distributed | ||
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
* express or implied. See the License for the specific language governing | ||
* permissions and limitations under the License. | ||
*/ | ||
|
||
package com.amplifyframework.auth.cognito.helpers | ||
|
||
import android.app.Activity | ||
import com.amplifyframework.auth.AuthProvider | ||
import com.amplifyframework.auth.cognito.options.AWSCognitoAuthWebUISignInOptions | ||
import io.kotest.matchers.shouldBe | ||
import io.mockk.mockk | ||
import org.junit.Test | ||
|
||
class HostedUIHelperTest { | ||
|
||
private val mockActivity = mockk<Activity>() | ||
|
||
@Test | ||
fun `createHostedUIOptions with AWSCognitoAuthWebUISignInOptions and preferPrivateSession true`() { | ||
val scopes = listOf("openid", "profile") | ||
val options = AWSCognitoAuthWebUISignInOptions.builder() | ||
.scopes(scopes) | ||
.browserPackage("com.android.chrome") | ||
.preferPrivateSession(true) | ||
.build() | ||
|
||
val hostedUIOptions = HostedUIHelper.createHostedUIOptions( | ||
callingActivity = mockActivity, | ||
authProvider = AuthProvider.google(), | ||
options = options | ||
) | ||
|
||
hostedUIOptions.callingActivity shouldBe mockActivity | ||
hostedUIOptions.scopes shouldBe scopes | ||
hostedUIOptions.browserPackage shouldBe "com.android.chrome" | ||
hostedUIOptions.preferPrivateSession shouldBe true | ||
} | ||
|
||
@Test | ||
fun `createHostedUIOptions with AWSCognitoAuthWebUISignInOptions and preferPrivateSession false`() { | ||
val scopes = listOf("openid", "email") | ||
val options = AWSCognitoAuthWebUISignInOptions.builder() | ||
.scopes(scopes) | ||
.browserPackage("org.mozilla.firefox") | ||
.preferPrivateSession(false) | ||
.build() | ||
|
||
val hostedUIOptions = HostedUIHelper.createHostedUIOptions( | ||
callingActivity = mockActivity, | ||
authProvider = AuthProvider.facebook(), | ||
options = options | ||
) | ||
|
||
hostedUIOptions.callingActivity shouldBe mockActivity | ||
hostedUIOptions.scopes shouldBe scopes | ||
hostedUIOptions.browserPackage shouldBe "org.mozilla.firefox" | ||
hostedUIOptions.preferPrivateSession shouldBe false | ||
} | ||
|
||
@Test | ||
fun `createHostedUIOptions with AWSCognitoAuthWebUISignInOptions and preferPrivateSession null`() { | ||
val scopes = listOf("openid") | ||
val options = AWSCognitoAuthWebUISignInOptions.builder() | ||
.scopes(scopes) | ||
.browserPackage("com.android.chrome") | ||
.build() | ||
|
||
val hostedUIOptions = HostedUIHelper.createHostedUIOptions( | ||
callingActivity = mockActivity, | ||
authProvider = null, | ||
options = options | ||
) | ||
|
||
hostedUIOptions.callingActivity shouldBe mockActivity | ||
hostedUIOptions.scopes shouldBe scopes | ||
hostedUIOptions.browserPackage shouldBe "com.android.chrome" | ||
hostedUIOptions.preferPrivateSession shouldBe null | ||
} | ||
|
||
@Test | ||
fun `selectRedirectUri prefers non-HTTP scheme`() { | ||
val redirectUris = listOf( | ||
"https://example.com/callback", | ||
"myapp://auth/callback", | ||
"http://localhost:3000/callback" | ||
) | ||
|
||
val selectedUri = HostedUIHelper.selectRedirectUri(redirectUris) | ||
selectedUri shouldBe "myapp://auth/callback" | ||
} | ||
|
||
@Test | ||
fun `selectRedirectUri returns first URI when no non-HTTP scheme available`() { | ||
val redirectUris = listOf( | ||
"https://example.com/callback", | ||
"http://localhost:3000/callback" | ||
) | ||
|
||
val selectedUri = HostedUIHelper.selectRedirectUri(redirectUris) | ||
selectedUri shouldBe "https://example.com/callback" | ||
} | ||
|
||
@Test | ||
fun `selectRedirectUri returns null for empty list`() { | ||
val redirectUris = emptyList<String>() | ||
val selectedUri = HostedUIHelper.selectRedirectUri(redirectUris) | ||
selectedUri shouldBe null | ||
} | ||
} |
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
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
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.
Uh oh!
There was an error while loading. Please reload this page.