Skip to content

Commit

Permalink
Add OAuth 2.0 configuration for Office 365 / Outlook
Browse files Browse the repository at this point in the history
  • Loading branch information
blino committed Jun 2, 2022
1 parent 49806dd commit 61083bf
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 2 deletions.
Expand Up @@ -105,7 +105,7 @@ class ProvidersXmlDiscovery(
}

// TODO: Remove this hack
val authType = if (host == "imap.gmail.com" || host == "imap.googlemail.com") {
val authType = if (host == "imap.gmail.com" || host == "imap.googlemail.com" || host == "outlook.office365.com") {
AuthType.XOAUTH2
} else {
AuthType.PLAIN
Expand Down Expand Up @@ -135,7 +135,7 @@ class ProvidersXmlDiscovery(
}

// TODO: Remove this hack
val authType = if (host == "smtp.gmail.com" || host == "smtp.googlemail.com") {
val authType = if (host == "smtp.gmail.com" || host == "smtp.googlemail.com" || host == "smtp.office365.com") {
AuthType.XOAUTH2
} else {
AuthType.PLAIN
Expand Down
2 changes: 2 additions & 0 deletions app/k9mail/build.gradle
Expand Up @@ -83,6 +83,7 @@ android {
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'

buildConfigField "String", "OAUTH_GMAIL_CLIENT_ID", "\"262622259280-hhmh92rhklkg2k1tjil69epo0o9a12jm.apps.googleusercontent.com\""
buildConfigField "String", "OAUTH_OUTLOOK_CLIENT_ID", "\"08162f7c-0fd2-4200-a84a-f25a4db0b584\""

manifestPlaceholders = ['appAuthRedirectScheme': 'com.fsck.k9']
}
Expand All @@ -96,6 +97,7 @@ android {
minifyEnabled false

buildConfigField "String", "OAUTH_GMAIL_CLIENT_ID", "\"262622259280-5qb3vtj68d5dtudmaif4g9vd3cpar8r3.apps.googleusercontent.com\""
buildConfigField "String", "OAUTH_OUTLOOK_CLIENT_ID", "\"08162f7c-0fd2-4200-a84a-f25a4db0b584\""

manifestPlaceholders = ['appAuthRedirectScheme': 'com.fsck.k9.debug']
}
Expand Down
Expand Up @@ -6,4 +6,6 @@ import com.fsck.k9.activity.setup.OAuthCredentials
class K9OAuthCredentials : OAuthCredentials {
override val gmailClientId: String
get() = BuildConfig.OAUTH_GMAIL_CLIENT_ID
override val outlookClientId: String
get() = BuildConfig.OAUTH_OUTLOOK_CLIENT_ID
}
Expand Up @@ -144,6 +144,15 @@ class AuthViewModel(
redirectUri = getGmailRedirectUri()
)
}
"outlook.office365.com", "smtp.office365.com" -> {
OAuthConfiguration(
clientId = oauthCredentials.outlookClientId,
scopes = listOf("https://outlook.office365.com/IMAP.AccessAsUser.All", "https://outlook.office365.com/POP.AccessAsUser.All", "https://outlook.office365.com/SMTP.Send", "offline_access"),
authorizationEndpoint = "https://login.microsoftonline.com/common/oauth2/v2.0/authorize",
tokenEndpoint = "https://login.microsoftonline.com/common/oauth2/v2.0/token",
redirectUri = "http://localhost"
)
}
else -> null
}
}
Expand Down
Expand Up @@ -2,4 +2,5 @@ package com.fsck.k9.activity.setup

interface OAuthCredentials {
val gmailClientId: String
val outlookClientId: String
}

0 comments on commit 61083bf

Please sign in to comment.