Loading app/k9mail/build.gradle.kts +31 −4 Original line number Diff line number Diff line Loading @@ -126,10 +126,23 @@ android { "\"dj0yJmk9dUNqYXZhYWxOYkdRJmQ9WVdrOU1YQnZVRFZoY1ZrbWNHbzlNQT09JnM9Y29uc3VtZXJzZWNyZXQmc3Y9MCZ4PWIw\"", ) buildConfigField("String", "OAUTH_MICROSOFT_CLIENT_ID", "\"${getProperty("MICROSOFT_CLIENT_ID")}\"") buildConfigField( "String", "MICROSOFT_REDIRECT_URI_SUFFIX_COMMUNITY", "\"${getProperty("MICROSOFT_REDIRECT_URI_SUFFIX_COMMUNITY")}\"", ) buildConfigField( "String", "OAUTH_MICROSOFT_REDIRECT_URI", "\"msauth://foundation.e.mail/${getProperty("MICROSOFT_REDIRECT_URI_SUFFIX")}\"", "MICROSOFT_REDIRECT_URI_SUFFIX_OFFICIAL", "\"${getProperty("MICROSOFT_REDIRECT_URI_SUFFIX_OFFICIAL")}\"", ) buildConfigField( "String", "MICROSOFT_REDIRECT_URI_SUFFIX_TEST", "\"${getProperty("MICROSOFT_REDIRECT_URI_SUFFIX_TEST")}\"", ) manifestPlaceholders["appAuthRedirectScheme"] = "foundation.e.mail" Loading Loading @@ -157,11 +170,25 @@ android { "OAUTH_AOL_CLIENT_ID", "\"dj0yJmk9cHYydkJkTUxHcXlYJmQ9WVdrOWVHZHhVVXN4VVV3bWNHbzlNQT09JnM9Y29uc3VtZXJzZWNyZXQmc3Y9MCZ4PTdm\"", ) buildConfigField("String", "OAUTH_MICROSOFT_CLIENT_ID", "\"${getProperty("MICROSOFT_CLIENT_ID")}\"") buildConfigField( "String", "MICROSOFT_REDIRECT_URI_SUFFIX_COMMUNITY", "\"${getProperty("MICROSOFT_REDIRECT_URI_SUFFIX_COMMUNITY")}\"", ) buildConfigField( "String", "MICROSOFT_REDIRECT_URI_SUFFIX_OFFICIAL", "\"${getProperty("MICROSOFT_REDIRECT_URI_SUFFIX_OFFICIAL")}\"", ) buildConfigField( "String", "OAUTH_MICROSOFT_REDIRECT_URI", "\"msauth://foundation.e.mail/${getProperty("MICROSOFT_REDIRECT_URI_SUFFIX")}\"", "MICROSOFT_REDIRECT_URI_SUFFIX_TEST", "\"${getProperty("MICROSOFT_REDIRECT_URI_SUFFIX_TEST")}\"", ) manifestPlaceholders["appAuthRedirectScheme"] = "foundation.e.mail.debug" Loading app/k9mail/src/main/java/com/fsck/k9/auth/AppOAuthConfigurationFactory.kt +1 −1 Original line number Diff line number Diff line Loading @@ -52,7 +52,7 @@ class AppOAuthConfigurationFactory : OAuthConfigurationFactory { ), authorizationEndpoint = "https://login.microsoftonline.com/common/oauth2/v2.0/authorize", tokenEndpoint = "https://login.microsoftonline.com/common/oauth2/v2.0/token", redirectUri = BuildConfig.OAUTH_MICROSOFT_REDIRECT_URI, redirectUri = MicrosoftRedirectUriGenerator.generate(), ) } Loading app/k9mail/src/main/java/com/fsck/k9/auth/MicrosoftRedirectUriGenerator.kt 0 → 100644 +42 −0 Original line number Diff line number Diff line /* * Copyright (C) 2024 e Foundation * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. * */ package com.fsck.k9.auth import com.fsck.k9.BuildConfig import com.fsck.k9.auth.ReleaseType.Community import com.fsck.k9.auth.ReleaseType.Official import com.fsck.k9.auth.ReleaseType.Test import com.fsck.k9.auth.ReleaseType.Unavailable object MicrosoftRedirectUriGenerator { fun generate(): String { val releaseType = ReleaseTypeHelper.getReleaseType() val redirectUriSuffix = when (releaseType) { Community -> BuildConfig.MICROSOFT_REDIRECT_URI_SUFFIX_COMMUNITY Official -> BuildConfig.MICROSOFT_REDIRECT_URI_SUFFIX_OFFICIAL Test, Unavailable -> BuildConfig.MICROSOFT_REDIRECT_URI_SUFFIX_TEST } // For debug build (foundation.e.mail.debug), update the hash of your debug keystore in Microsoft Azure portal, // and based on that, set the redirectUriSuffix as it is a combination of both // the applicationId and signature hash of the keystore. return "msauth://${BuildConfig.APPLICATION_ID}/$redirectUriSuffix" } } app/k9mail/src/main/java/com/fsck/k9/auth/ReleaseTypeHelper.kt 0 → 100644 +61 −0 Original line number Diff line number Diff line /* * Copyright (C) 2024 e Foundation * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. * */ package com.fsck.k9.auth import android.annotation.SuppressLint import com.fsck.k9.auth.ReleaseType.Community import com.fsck.k9.auth.ReleaseType.Official import com.fsck.k9.auth.ReleaseType.Test import com.fsck.k9.auth.ReleaseType.Unavailable import com.fsck.k9.logging.Timber object ReleaseTypeHelper { private const val KEY_SYSTEM_PROPERTY_RELEASE_TYPE = "ro.lineage.releasetype" fun getReleaseType(): ReleaseType { val property = getSystemProperty(KEY_SYSTEM_PROPERTY_RELEASE_TYPE) return when (property) { Community.value -> Community Official.value -> Official Test.value -> Test else -> Unavailable } } } enum class ReleaseType(val value: String) { Community("community"), Official("official"), Test("test"), Unavailable("") } @SuppressLint("PrivateApi") private fun getSystemProperty(key: String): String { return try { Class.forName("android.os.SystemProperties") .getMethod("get", String::class.java) .invoke(null, key) as String } catch (e: Exception) { Timber.e("Unable to determine system property for $key", e) Unavailable.value } } Loading
app/k9mail/build.gradle.kts +31 −4 Original line number Diff line number Diff line Loading @@ -126,10 +126,23 @@ android { "\"dj0yJmk9dUNqYXZhYWxOYkdRJmQ9WVdrOU1YQnZVRFZoY1ZrbWNHbzlNQT09JnM9Y29uc3VtZXJzZWNyZXQmc3Y9MCZ4PWIw\"", ) buildConfigField("String", "OAUTH_MICROSOFT_CLIENT_ID", "\"${getProperty("MICROSOFT_CLIENT_ID")}\"") buildConfigField( "String", "MICROSOFT_REDIRECT_URI_SUFFIX_COMMUNITY", "\"${getProperty("MICROSOFT_REDIRECT_URI_SUFFIX_COMMUNITY")}\"", ) buildConfigField( "String", "OAUTH_MICROSOFT_REDIRECT_URI", "\"msauth://foundation.e.mail/${getProperty("MICROSOFT_REDIRECT_URI_SUFFIX")}\"", "MICROSOFT_REDIRECT_URI_SUFFIX_OFFICIAL", "\"${getProperty("MICROSOFT_REDIRECT_URI_SUFFIX_OFFICIAL")}\"", ) buildConfigField( "String", "MICROSOFT_REDIRECT_URI_SUFFIX_TEST", "\"${getProperty("MICROSOFT_REDIRECT_URI_SUFFIX_TEST")}\"", ) manifestPlaceholders["appAuthRedirectScheme"] = "foundation.e.mail" Loading Loading @@ -157,11 +170,25 @@ android { "OAUTH_AOL_CLIENT_ID", "\"dj0yJmk9cHYydkJkTUxHcXlYJmQ9WVdrOWVHZHhVVXN4VVV3bWNHbzlNQT09JnM9Y29uc3VtZXJzZWNyZXQmc3Y9MCZ4PTdm\"", ) buildConfigField("String", "OAUTH_MICROSOFT_CLIENT_ID", "\"${getProperty("MICROSOFT_CLIENT_ID")}\"") buildConfigField( "String", "MICROSOFT_REDIRECT_URI_SUFFIX_COMMUNITY", "\"${getProperty("MICROSOFT_REDIRECT_URI_SUFFIX_COMMUNITY")}\"", ) buildConfigField( "String", "MICROSOFT_REDIRECT_URI_SUFFIX_OFFICIAL", "\"${getProperty("MICROSOFT_REDIRECT_URI_SUFFIX_OFFICIAL")}\"", ) buildConfigField( "String", "OAUTH_MICROSOFT_REDIRECT_URI", "\"msauth://foundation.e.mail/${getProperty("MICROSOFT_REDIRECT_URI_SUFFIX")}\"", "MICROSOFT_REDIRECT_URI_SUFFIX_TEST", "\"${getProperty("MICROSOFT_REDIRECT_URI_SUFFIX_TEST")}\"", ) manifestPlaceholders["appAuthRedirectScheme"] = "foundation.e.mail.debug" Loading
app/k9mail/src/main/java/com/fsck/k9/auth/AppOAuthConfigurationFactory.kt +1 −1 Original line number Diff line number Diff line Loading @@ -52,7 +52,7 @@ class AppOAuthConfigurationFactory : OAuthConfigurationFactory { ), authorizationEndpoint = "https://login.microsoftonline.com/common/oauth2/v2.0/authorize", tokenEndpoint = "https://login.microsoftonline.com/common/oauth2/v2.0/token", redirectUri = BuildConfig.OAUTH_MICROSOFT_REDIRECT_URI, redirectUri = MicrosoftRedirectUriGenerator.generate(), ) } Loading
app/k9mail/src/main/java/com/fsck/k9/auth/MicrosoftRedirectUriGenerator.kt 0 → 100644 +42 −0 Original line number Diff line number Diff line /* * Copyright (C) 2024 e Foundation * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. * */ package com.fsck.k9.auth import com.fsck.k9.BuildConfig import com.fsck.k9.auth.ReleaseType.Community import com.fsck.k9.auth.ReleaseType.Official import com.fsck.k9.auth.ReleaseType.Test import com.fsck.k9.auth.ReleaseType.Unavailable object MicrosoftRedirectUriGenerator { fun generate(): String { val releaseType = ReleaseTypeHelper.getReleaseType() val redirectUriSuffix = when (releaseType) { Community -> BuildConfig.MICROSOFT_REDIRECT_URI_SUFFIX_COMMUNITY Official -> BuildConfig.MICROSOFT_REDIRECT_URI_SUFFIX_OFFICIAL Test, Unavailable -> BuildConfig.MICROSOFT_REDIRECT_URI_SUFFIX_TEST } // For debug build (foundation.e.mail.debug), update the hash of your debug keystore in Microsoft Azure portal, // and based on that, set the redirectUriSuffix as it is a combination of both // the applicationId and signature hash of the keystore. return "msauth://${BuildConfig.APPLICATION_ID}/$redirectUriSuffix" } }
app/k9mail/src/main/java/com/fsck/k9/auth/ReleaseTypeHelper.kt 0 → 100644 +61 −0 Original line number Diff line number Diff line /* * Copyright (C) 2024 e Foundation * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. * */ package com.fsck.k9.auth import android.annotation.SuppressLint import com.fsck.k9.auth.ReleaseType.Community import com.fsck.k9.auth.ReleaseType.Official import com.fsck.k9.auth.ReleaseType.Test import com.fsck.k9.auth.ReleaseType.Unavailable import com.fsck.k9.logging.Timber object ReleaseTypeHelper { private const val KEY_SYSTEM_PROPERTY_RELEASE_TYPE = "ro.lineage.releasetype" fun getReleaseType(): ReleaseType { val property = getSystemProperty(KEY_SYSTEM_PROPERTY_RELEASE_TYPE) return when (property) { Community.value -> Community Official.value -> Official Test.value -> Test else -> Unavailable } } } enum class ReleaseType(val value: String) { Community("community"), Official("official"), Test("test"), Unavailable("") } @SuppressLint("PrivateApi") private fun getSystemProperty(key: String): String { return try { Class.forName("android.os.SystemProperties") .getMethod("get", String::class.java) .invoke(null, key) as String } catch (e: Exception) { Timber.e("Unable to determine system property for $key", e) Unavailable.value } }