-
Notifications
You must be signed in to change notification settings - Fork 164
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
When creating an account with MAS, change the prompt
parameter to create
#3635
Closed
Closed
Changes from all commits
Commits
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 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 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 |
---|---|---|
|
@@ -12,3 +12,16 @@ import android.net.Uri | |
const val IGNORED_SCHEMA = "ignored" | ||
|
||
fun createIgnoredUri(path: String): Uri = Uri.parse("$IGNORED_SCHEMA://$path") | ||
|
||
fun Uri.setQueryParameter(key: String, value: String): Uri { | ||
val existingParams = queryParameterNames | ||
return buildUpon().apply { | ||
clearQuery() | ||
existingParams.forEach { existingKey -> | ||
if (existingKey != key) { | ||
appendQueryParameter(existingKey, getQueryParameter(existingKey)) | ||
} | ||
} | ||
appendQueryParameter(key, value) | ||
}.build() | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Only |
74 changes: 74 additions & 0 deletions
74
...idutils/src/test/kotlin/io/element/android/libraries/androidutils/uri/UriExtensionTest.kt
This file contains 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,74 @@ | ||
/* | ||
* Copyright 2024 New Vector Ltd. | ||
* | ||
* SPDX-License-Identifier: AGPL-3.0-only | ||
* Please see LICENSE in the repository root for full details. | ||
*/ | ||
|
||
package io.element.android.libraries.androidutils.uri | ||
|
||
import androidx.core.net.toUri | ||
import com.google.common.truth.Truth.assertThat | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
import org.robolectric.RobolectricTestRunner | ||
|
||
@RunWith(RobolectricTestRunner::class) | ||
class UriExtensionTest { | ||
@Test | ||
fun `url with prompt parameter should replace existing value`() { | ||
val url = "https://beta.element.io/account/authorize" + | ||
"?response_type=code" + | ||
"&client_id=01J9RB9MEJCMVHWNYYHTVDNBVJ" + | ||
"&redirect_uri=io.element%3A%2Fcallback" + | ||
"&scope=scope" + | ||
"&state=x61ILblUF6BwOTUA" + | ||
"&nonce=N7TdVfDhyVNF9PbH" + | ||
"&prompt=consent" + | ||
"&code_challenge_method=S256" + | ||
"&code_challenge=bDV2DWX0j0U-QtewSUJeXr3DEmvFxlHfQN_1UxXpOUk" | ||
val result = url.toUri() | ||
.setQueryParameter("prompt", "create") | ||
.toString() | ||
assertThat(result).isEqualTo( | ||
"https://beta.element.io/account/authorize" + | ||
"?response_type=code" + | ||
"&client_id=01J9RB9MEJCMVHWNYYHTVDNBVJ" + | ||
"&redirect_uri=io.element%3A%2Fcallback" + | ||
"&scope=scope" + | ||
"&state=x61ILblUF6BwOTUA" + | ||
"&nonce=N7TdVfDhyVNF9PbH" + | ||
"&code_challenge_method=S256" + | ||
"&code_challenge=bDV2DWX0j0U-QtewSUJeXr3DEmvFxlHfQN_1UxXpOUk" + | ||
"&prompt=create" | ||
) | ||
} | ||
|
||
@Test | ||
fun `url without prompt parameter should add the parameter`() { | ||
val url = "https://beta.element.io/account/authorize" + | ||
"?response_type=code" + | ||
"&client_id=01J9RB9MEJCMVHWNYYHTVDNBVJ" + | ||
"&redirect_uri=io.element%3A%2Fcallback" + | ||
"&scope=scope" + | ||
"&state=x61ILblUF6BwOTUA" + | ||
"&nonce=N7TdVfDhyVNF9PbH" + | ||
"&code_challenge_method=S256" + | ||
"&code_challenge=bDV2DWX0j0U-QtewSUJeXr3DEmvFxlHfQN_1UxXpOUk" | ||
val result = url.toUri() | ||
.setQueryParameter("prompt", "create") | ||
.toString() | ||
assertThat(result).isEqualTo( | ||
"https://beta.element.io/account/authorize" + | ||
"?response_type=code" + | ||
"&client_id=01J9RB9MEJCMVHWNYYHTVDNBVJ" + | ||
"&redirect_uri=io.element%3A%2Fcallback" + | ||
"&scope=scope" + | ||
"&state=x61ILblUF6BwOTUA" + | ||
"&nonce=N7TdVfDhyVNF9PbH" + | ||
"&code_challenge_method=S256" + | ||
"&code_challenge=bDV2DWX0j0U-QtewSUJeXr3DEmvFxlHfQN_1UxXpOUk" + | ||
"&prompt=create" | ||
) | ||
} | ||
} |
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.
Note that the provided value for the "prompt" parameter on beta.matrix.org is "consent".