Improve the callback uri format and customization. (#4664)
* Remove unused SUPPORT_EMAIL_ADDRESS * Improve the callback uri format and customization. Use io.element.android for the scheme of Oidc redirection for Element X. For nightly the scheme will be io.element.android.nightly For debug the scheme will be io.element.android.debug Element Pro is using `io.element`
This commit is contained in:
parent
024aa49e60
commit
9ea4853e88
20 changed files with 166 additions and 49 deletions
|
|
@ -27,13 +27,6 @@ android {
|
|||
name = "CLIENT_URI",
|
||||
value = BuildTimeConfig.URL_WEBSITE ?: "https://element.io"
|
||||
)
|
||||
buildConfigFieldStr(
|
||||
name = "REDIRECT_URI",
|
||||
value = buildString {
|
||||
append(BuildTimeConfig.METADATA_HOST_REVERSED ?: "io.element")
|
||||
append(":/callback")
|
||||
}
|
||||
)
|
||||
buildConfigFieldStr(
|
||||
name = "LOGO_URI",
|
||||
value = BuildTimeConfig.URL_LOGO ?: "https://element.io/mobile-icon.png"
|
||||
|
|
|
|||
|
|
@ -12,11 +12,6 @@ import io.element.android.libraries.matrix.api.BuildConfig
|
|||
object OidcConfig {
|
||||
const val CLIENT_URI = BuildConfig.CLIENT_URI
|
||||
|
||||
// Notes:
|
||||
// 1. the scheme must match the value declared in the AndroidManifest.xml
|
||||
// 2. the scheme must be the reverse of the host of CLIENT_URI
|
||||
const val REDIRECT_URI = BuildConfig.REDIRECT_URI
|
||||
|
||||
// Note: host must match with the host of CLIENT_URI
|
||||
const val LOGO_URI = BuildConfig.LOGO_URI
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,12 @@
|
|||
/*
|
||||
* Copyright 2025 New Vector Ltd.
|
||||
*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
|
||||
* Please see LICENSE files in the repository root for full details.
|
||||
*/
|
||||
|
||||
package io.element.android.libraries.matrix.api.auth
|
||||
|
||||
interface OidcRedirectUrlProvider {
|
||||
fun provide(): String
|
||||
}
|
||||
|
|
@ -9,15 +9,17 @@ package io.element.android.libraries.matrix.impl.auth
|
|||
|
||||
import io.element.android.libraries.core.meta.BuildMeta
|
||||
import io.element.android.libraries.matrix.api.auth.OidcConfig
|
||||
import io.element.android.libraries.matrix.api.auth.OidcRedirectUrlProvider
|
||||
import org.matrix.rustcomponents.sdk.OidcConfiguration
|
||||
import javax.inject.Inject
|
||||
|
||||
class OidcConfigurationProvider @Inject constructor(
|
||||
private val buildMeta: BuildMeta,
|
||||
private val oidcRedirectUrlProvider: OidcRedirectUrlProvider,
|
||||
) {
|
||||
fun get(): OidcConfiguration = OidcConfiguration(
|
||||
clientName = buildMeta.applicationName,
|
||||
redirectUri = OidcConfig.REDIRECT_URI,
|
||||
redirectUri = oidcRedirectUrlProvider.provide(),
|
||||
clientUri = OidcConfig.CLIENT_URI,
|
||||
logoUri = OidcConfig.LOGO_URI,
|
||||
tosUri = OidcConfig.TOS_URI,
|
||||
|
|
|
|||
|
|
@ -8,7 +8,8 @@
|
|||
package io.element.android.libraries.matrix.impl.auth
|
||||
|
||||
import com.google.common.truth.Truth.assertThat
|
||||
import io.element.android.libraries.matrix.api.auth.OidcConfig
|
||||
import io.element.android.libraries.matrix.test.auth.FAKE_REDIRECT_URL
|
||||
import io.element.android.libraries.matrix.test.auth.FakeOidcRedirectUrlProvider
|
||||
import io.element.android.libraries.matrix.test.core.aBuildMeta
|
||||
import org.junit.Test
|
||||
|
||||
|
|
@ -16,11 +17,12 @@ class OidcConfigurationProviderTest {
|
|||
@Test
|
||||
fun get() {
|
||||
val result = OidcConfigurationProvider(
|
||||
aBuildMeta(
|
||||
buildMeta = aBuildMeta(
|
||||
applicationName = "myName",
|
||||
)
|
||||
),
|
||||
oidcRedirectUrlProvider = FakeOidcRedirectUrlProvider(),
|
||||
).get()
|
||||
assertThat(result.clientName).isEqualTo("myName")
|
||||
assertThat(result.redirectUri).isEqualTo(OidcConfig.REDIRECT_URI)
|
||||
assertThat(result.redirectUri).isEqualTo(FAKE_REDIRECT_URL)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ import com.google.common.truth.Truth.assertThat
|
|||
import io.element.android.libraries.matrix.api.core.SessionId
|
||||
import io.element.android.libraries.matrix.impl.createRustMatrixClientFactory
|
||||
import io.element.android.libraries.matrix.impl.paths.SessionPathsFactory
|
||||
import io.element.android.libraries.matrix.test.auth.FakeOidcRedirectUrlProvider
|
||||
import io.element.android.libraries.matrix.test.core.aBuildMeta
|
||||
import io.element.android.libraries.sessionstorage.api.SessionStore
|
||||
import io.element.android.libraries.sessionstorage.impl.memory.InMemorySessionStore
|
||||
|
|
@ -49,7 +50,10 @@ class RustMatrixAuthenticationServiceTest {
|
|||
sessionStore = sessionStore,
|
||||
rustMatrixClientFactory = rustMatrixClientFactory,
|
||||
passphraseGenerator = FakePassphraseGenerator(),
|
||||
oidcConfigurationProvider = OidcConfigurationProvider(aBuildMeta()),
|
||||
oidcConfigurationProvider = OidcConfigurationProvider(
|
||||
buildMeta = aBuildMeta(),
|
||||
oidcRedirectUrlProvider = FakeOidcRedirectUrlProvider(),
|
||||
),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,18 @@
|
|||
/*
|
||||
* Copyright 2025 New Vector Ltd.
|
||||
*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
|
||||
* Please see LICENSE files in the repository root for full details.
|
||||
*/
|
||||
|
||||
package io.element.android.libraries.matrix.test.auth
|
||||
|
||||
import io.element.android.libraries.matrix.api.auth.OidcRedirectUrlProvider
|
||||
|
||||
const val FAKE_REDIRECT_URL = "io.element.android:/"
|
||||
|
||||
class FakeOidcRedirectUrlProvider(
|
||||
private val provideResult: String = FAKE_REDIRECT_URL,
|
||||
) : OidcRedirectUrlProvider {
|
||||
override fun provide() = provideResult
|
||||
}
|
||||
|
|
@ -39,5 +39,5 @@ fun aBuildMeta(
|
|||
gitRevision = gitRevision,
|
||||
gitBranchName = gitBranchName,
|
||||
flavorDescription = flavorDescription,
|
||||
flavorShortDescription = flavorShortDescription
|
||||
flavorShortDescription = flavorShortDescription,
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue