diff --git a/src-ui/src/app/app.module.ts b/src-ui/src/app/app.module.ts
index 5b9460617..3f707ccdf 100644
--- a/src-ui/src/app/app.module.ts
+++ b/src-ui/src/app/app.module.ts
@@ -191,6 +191,7 @@ import {
folderFill,
funnel,
gear,
+ google,
grid,
gripVertical,
hash,
@@ -201,6 +202,7 @@ import {
link,
listTask,
listUl,
+ microsoft,
nodePlus,
pencil,
people,
@@ -295,6 +297,7 @@ const icons = {
folderFill,
funnel,
gear,
+ google,
grid,
gripVertical,
hash,
@@ -305,6 +308,7 @@ const icons = {
link,
listTask,
listUl,
+ microsoft,
nodePlus,
pencil,
people,
diff --git a/src-ui/src/app/components/manage/mail/mail.component.html b/src-ui/src/app/components/manage/mail/mail.component.html
index 564536c66..e6e4ac200 100644
--- a/src-ui/src/app/components/manage/mail/mail.component.html
+++ b/src-ui/src/app/components/manage/mail/mail.component.html
@@ -13,8 +13,16 @@
- Connect with Gmail
- Connect with Outlook
+ @if (gmailOAuthUrl) {
+
+ Connect Gmail Account
+
+ }
+ @if (outlookOAuthUrl) {
+
+ Connect Outlook Account
+
+ }
-
diff --git a/src-ui/src/app/components/manage/mail/mail.component.ts b/src-ui/src/app/components/manage/mail/mail.component.ts
index 2e46e3c67..381db6e1d 100644
--- a/src-ui/src/app/components/manage/mail/mail.component.ts
+++ b/src-ui/src/app/components/manage/mail/mail.component.ts
@@ -38,7 +38,7 @@ export class MailComponent
oAuthAccoundId: number
public get gmailOAuthUrl(): string {
- return this.settingsService.get(SETTINGS_KEYS.GOOGLE_OAUTH_URL)
+ return this.settingsService.get(SETTINGS_KEYS.GMAIL_OAUTH_URL)
}
public get outlookOAuthUrl(): string {
@@ -94,12 +94,20 @@ export class MailComponent
this.route.queryParamMap.subscribe((params) => {
if (params.get('oauth_success')) {
- this.oAuthAccoundId = parseInt(params.get('account_id'))
- if (this.mailAccounts.length > 0) {
- this.editMailAccount(
- this.mailAccounts.find(
- (account) => account.id === this.oAuthAccoundId
+ const success = params.get('oauth_success') === '1'
+ if (success) {
+ this.toastService.showInfo($localize`OAuth2 authentication success`)
+ this.oAuthAccoundId = parseInt(params.get('account_id'))
+ if (this.mailAccounts.length > 0) {
+ this.editMailAccount(
+ this.mailAccounts.find(
+ (account) => account.id === this.oAuthAccoundId
+ )
)
+ }
+ } else {
+ this.toastService.showError(
+ $localize`OAuth2 authentication failed, see logs for details`
)
}
}
diff --git a/src-ui/src/app/data/ui-settings.ts b/src-ui/src/app/data/ui-settings.ts
index ff0aad88d..18f9ff130 100644
--- a/src-ui/src/app/data/ui-settings.ts
+++ b/src-ui/src/app/data/ui-settings.ts
@@ -64,7 +64,7 @@ export const SETTINGS_KEYS = {
SEARCH_DB_ONLY: 'general-settings:search:db-only',
SEARCH_FULL_TYPE: 'general-settings:search:more-link',
EMPTY_TRASH_DELAY: 'trash_delay',
- GOOGLE_OAUTH_URL: 'google_oauth_url',
+ GMAIL_OAUTH_URL: 'gmail_oauth_url',
OUTLOOK_OAUTH_URL: 'outlook_oauth_url',
}
@@ -245,7 +245,7 @@ export const SETTINGS: UiSetting[] = [
default: 30,
},
{
- key: SETTINGS_KEYS.GOOGLE_OAUTH_URL,
+ key: SETTINGS_KEYS.GMAIL_OAUTH_URL,
type: 'string',
default: '',
},
diff --git a/src/documents/views.py b/src/documents/views.py
index 55c09410a..35ea013af 100644
--- a/src/documents/views.py
+++ b/src/documents/views.py
@@ -1566,7 +1566,6 @@ class UiSettingsView(GenericAPIView):
return url
def generate_outlook_oauth_url(self) -> str:
- # https://login.microsoftonline.com/common/oauth2/v2.0/authorize ?
token_request_uri = (
"https://login.microsoftonline.com/common/oauth2/v2.0/authorize"
)
@@ -1608,7 +1607,7 @@ class UiSettingsView(GenericAPIView):
ui_settings["auditlog_enabled"] = settings.AUDIT_LOG_ENABLED
if settings.GMAIL_OAUTH_ENABLED:
- ui_settings["google_oauth_url"] = self.generate_gmail_oauth_url()
+ ui_settings["gmail_oauth_url"] = self.generate_gmail_oauth_url()
if settings.OUTLOOK_OAUTH_ENABLED:
ui_settings["outlook_oauth_url"] = self.generate_outlook_oauth_url()
@@ -2225,7 +2224,9 @@ class OauthCallbackView(GenericAPIView):
if "error" in data:
logger.error(f"Error {response.status_code} getting access token: {data}")
- return HttpResponseBadRequest(data["error"])
+ return HttpResponseRedirect(
+ "http://localhost:4200/mail?oauth_success=0",
+ )
elif "access_token" in data:
access_token = data["access_token"]
# if "refresh_token" in data:
@@ -2237,7 +2238,6 @@ class OauthCallbackView(GenericAPIView):
imap_server=imap_server,
defaults=defaults,
)
-
- return HttpResponseRedirect(
- f"http://localhost:4200/mail?oauth_success=1&account_id={account.pk}",
- )
+ return HttpResponseRedirect(
+ f"http://localhost:4200/mail?oauth_success=1&account_id={account.pk}",
+ )