diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 14af2afc8..76a87511e 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -103,7 +103,7 @@ android { versionCode = 600000 // 6.00.000 versionName = "6.0.0" - manifestPlaceholders["appAuthRedirectScheme"] = "org.linphone" + manifestPlaceholders["appAuthRedirectScheme"] = packageName ndk { //noinspection ChromeOsAbiSupport @@ -155,6 +155,7 @@ android { } resValue("string", "linphone_app_version", gitVersion.trim()) resValue("string", "linphone_app_branch", gitBranch.toString().trim()) + resValue("string", "linphone_openid_callback_scheme", packageName) if (crashlyticsAvailable) { val path = File("$sdkPath/libs-debug/").toString() @@ -177,6 +178,7 @@ android { resValue("string", "file_provider", "$packageName.fileprovider") resValue("string", "linphone_app_version", gitVersion.trim()) resValue("string", "linphone_app_branch", gitBranch.toString().trim()) + resValue("string", "linphone_openid_callback_scheme", packageName) if (crashlyticsAvailable) { val path = File("$sdkPath/libs-debug/").toString() diff --git a/app/src/main/java/org/linphone/core/CorePreferences.kt b/app/src/main/java/org/linphone/core/CorePreferences.kt index 36eccce22..353129377 100644 --- a/app/src/main/java/org/linphone/core/CorePreferences.kt +++ b/app/src/main/java/org/linphone/core/CorePreferences.kt @@ -283,6 +283,10 @@ class CorePreferences val hideAssistantThirdPartySipAccount: Boolean get() = config.getBool("ui", "assistant_hide_third_party_account", false) + @get:WorkerThread + val singleSignOnClientId: String + get() = config.getString("app", "oidc_client_id", "linphone")!! + @get:WorkerThread val useUsernameAsSingleSignOnLoginHint: Boolean get() = config.getBool("ui", "use_username_as_sso_login_hint", false) diff --git a/app/src/main/java/org/linphone/ui/main/sso/viewmodel/SingleSignOnViewModel.kt b/app/src/main/java/org/linphone/ui/main/sso/viewmodel/SingleSignOnViewModel.kt index 957cefee7..a0fe73c77 100644 --- a/app/src/main/java/org/linphone/ui/main/sso/viewmodel/SingleSignOnViewModel.kt +++ b/app/src/main/java/org/linphone/ui/main/sso/viewmodel/SingleSignOnViewModel.kt @@ -35,6 +35,7 @@ import net.openid.appauth.ResponseTypeValues import org.json.JSONObject import org.linphone.LinphoneApplication.Companion.coreContext import org.linphone.LinphoneApplication.Companion.corePreferences +import org.linphone.R import org.linphone.core.Factory import org.linphone.core.tools.Log import org.linphone.ui.GenericViewModel @@ -43,16 +44,18 @@ import org.linphone.utils.FileUtils import org.linphone.utils.TimestampUtils import androidx.core.net.toUri -class SingleSignOnViewModel : GenericViewModel() { +class SingleSignOnViewModel + @UiThread + constructor() : GenericViewModel() { companion object { private const val TAG = "[Single Sign On ViewModel]" - - private const val CLIENT_ID = "linphone" - private const val REDIRECT_URI = "org.linphone:/openidcallback" } val singleSignOnProcessCompletedEvent = MutableLiveData>() + private var clientId: String + private val redirectUri: String + private var singleSignOnUrl = "" private var username: String = "" @@ -68,14 +71,37 @@ class SingleSignOnViewModel : GenericViewModel() { private lateinit var authState: AuthState private lateinit var authService: AuthorizationService + init { + clientId = corePreferences.singleSignOnClientId + + val openIdCallbackScheme = coreContext.context.getString(R.string.linphone_openid_callback_scheme) + redirectUri = "$openIdCallbackScheme:/openidcallback" + + Log.i("$TAG Using client ID [$clientId] and redirect URI [$redirectUri]") + } + @UiThread fun setUp(ssoUrl: String, user: String = "") { viewModelScope.launch { singleSignOnUrl = ssoUrl username = user + try { + val parsedUrl = ssoUrl.toUri() + val urlClientId = parsedUrl.getQueryParameter("client_id") + if (urlClientId.isNullOrEmpty()) { + Log.i("$TAG No client_id query parameter in URL, using value from config [$clientId]") + } else { + Log.w("$TAG client_id query parameter found in URL, overriding value from config [$clientId] to [$urlClientId]") + clientId = urlClientId + } + + } catch (e: Exception) { + Log.e("$TAG Failed to parse SSO URL [$singleSignOnUrl]: $e") + } + Log.i( - "$TAG Setting up SSO environment for username [$username] and URL [$singleSignOnUrl], redirect URI is [$REDIRECT_URI]" + "$TAG Setting up SSO environment for username [$username] and URL [$singleSignOnUrl]" ) authState = getAuthState() updateTokenInfo() @@ -128,9 +154,9 @@ class SingleSignOnViewModel : GenericViewModel() { val authRequestBuilder = AuthorizationRequest.Builder( serviceConfiguration, // the authorization service configuration - CLIENT_ID, // the client ID, typically pre-registered and static + clientId, // the client ID, typically pre-registered and static ResponseTypeValues.CODE, // the response_type value: we want a code - REDIRECT_URI.toUri() // the redirect URI to which the auth response is sent + redirectUri.toUri() // the redirect URI to which the auth response is sent ) // Needed for SDK to be able to refresh the token, otherwise it will return @@ -346,7 +372,7 @@ class SingleSignOnViewModel : GenericViewModel() { ) } - authInfo.clientId = CLIENT_ID + authInfo.clientId = clientId core.addAuthInfo(authInfo) Log.i( diff --git a/app/src/main/res/layout-sw600dp/welcome_page_1.xml b/app/src/main/res/layout-sw600dp/welcome_page_1.xml index 27b6de054..9686448f6 100644 --- a/app/src/main/res/layout-sw600dp/welcome_page_1.xml +++ b/app/src/main/res/layout-sw600dp/welcome_page_1.xml @@ -39,7 +39,7 @@ - - @@ -65,7 +50,7 @@ app:indicatorColor="?attr/color_main1_500" android:indeterminate="true" app:layout_constraintVertical_chainStyle="packed" - app:layout_constraintTop_toTopOf="parent" + app:layout_constraintTop_toBottomOf="@id/title" app:layout_constraintStart_toStartOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintBottom_toTopOf="@id/message"/> @@ -84,7 +69,21 @@ app:layout_constraintTop_toBottomOf="@id/progress" app:layout_constraintStart_toStartOf="parent" app:layout_constraintEnd_toEndOf="parent" - app:layout_constraintBottom_toBottomOf="parent"/> + app:layout_constraintBottom_toTopOf="@id/mountains"/> + + diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml index c43a584da..0693326d7 100644 --- a/app/src/main/res/values-fr/strings.xml +++ b/app/src/main/res/values-fr/strings.xml @@ -6,7 +6,6 @@ Adresse SIP ID du téléphone - utilisateur@domaine Nom d\'affichage Domaine Nom d\'utilisateur @@ -14,7 +13,7 @@ Mot de passe Numéro de téléphone ou - suivant + Suivant Commencer Aujourd\'hui Hier diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 9c5efe8e8..cfc3398f7 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -51,7 +51,7 @@ Password Phone number or - next + Next Start Today Yesterday