emailengine-app 2.83.0 → 2.83.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,169 +1,265 @@
1
- {{#if activeOutlook}}
2
- {{#> ui/stat-card variant="info" icon="icon-[tabler--info-circle]" class="mb-6"}}
3
- <strong>Delegated</strong> access means EmailEngine acts on behalf of a signed-in user. Each
4
- mailbox owner must complete an interactive OAuth2 login. Use this when users manage their own
5
- accounts or when you have access to the mailbox credentials.
6
- {{#if providerData.tutorialUrl}}
7
- Read about setting up {{providerData.comment}} OAuth2 project from <a href="{{providerData.tutorialUrl}}"
8
- target="_blank" rel="noopener noreferrer" referrerpolicy="no-referrer" class="link link-animated">here</a>.
9
- {{/if}}
10
- {{/ui/stat-card}}
11
- {{/if}}
1
+ {{!-- The OAuth2 application form, shared by the new and edit pages for every provider. Top to bottom it
2
+ asks what the app is (Application), what it connects with (Base scope, which decides which fields and
3
+ sections apply), how it signs in (Credentials) and, optionally, which scopes to add or drop. --}}
12
4
 
13
- {{#if activeGmailService}}
14
5
  {{#> ui/stat-card variant="info" icon="icon-[tabler--info-circle]" class="mb-6"}}
15
- <strong>Service accounts</strong> let EmailEngine access any mailbox in your Google Workspace
16
- organization without an interactive user login. The service account must have domain-wide
17
- delegation enabled in Workspace. Use this for automated integrations where you cannot perform
18
- interactive logins.
19
- <p class="mt-2 mb-0">
20
- Two authentication methods are supported: a downloaded <strong>service account key</strong>
21
- (classic) or <strong>Workload Identity Federation</strong> (keyless, for GKE, EKS, AKS, or
22
- any OIDC-emitting workload). Pick one below.
23
- </p>
24
- <p class="mt-2 mb-0">
25
- Accounts using service access can only be added via the
26
- <a href="/admin/reference/account#postV1Account" class="link link-animated">REST API</a>, not through the hosted
27
- authentication form.{{#if providerData.tutorialUrl}} Read the
28
- <a href="{{providerData.tutorialUrl}}" target="_blank" rel="noopener noreferrer" referrerpolicy="no-referrer"
29
- class="link link-animated">setup guide</a> for both methods.{{/if}}
30
- </p>
6
+ <div class="space-y-2">
7
+ <p>
8
+ {{#if activeGmail}}
9
+ Users sign in with their own Google account, through the hosted authentication form or your own OAuth2 flow.
10
+ Create an OAuth client of the <em>Web application</em> type in the Google Cloud console and add the redirect
11
+ URL below to it.
12
+ {{/if}}
13
+ {{#if activeGmailService}}
14
+ <strong>Service accounts</strong> let EmailEngine reach Google without an interactive user login. An
15
+ <strong>IMAP and SMTP</strong> or <strong>Gmail API</strong> app accesses any mailbox in your Google
16
+ Workspace organization through domain-wide delegation, which must be enabled for the service account in
17
+ Workspace. A <strong>Cloud Pub/Sub</strong> app accesses no mailboxes: it sets up the real-time change
18
+ notifications your Gmail API apps use.
19
+ {{/if}}
20
+ {{#if activeOutlook}}
21
+ <strong>Delegated</strong> access: EmailEngine acts on behalf of a signed-in user, so each mailbox owner
22
+ completes an interactive OAuth2 login. Use it when users connect their own accounts.
23
+ {{/if}}
24
+ {{#if activeOutlookService}}
25
+ <strong>Application</strong> access: EmailEngine authenticates as the app itself with client credentials,
26
+ and no user signs in. The Entra app registration needs <strong>application</strong> permissions (not
27
+ delegated) with admin consent. Use it for service integrations and shared mailboxes.
28
+ {{/if}}
29
+ {{#if activeMailRu}}
30
+ Users sign in with their own Mail.ru account, through the hosted authentication form or your own OAuth2
31
+ flow.
32
+ {{/if}}
33
+ </p>
34
+ {{#if providerData.serviceAccount}}
35
+ <p>Accounts of this app can only be added through the <a href="/admin/reference/account#postV1Account"
36
+ class="link link-animated">REST API</a>, not the hosted authentication form.</p>
37
+ {{/if}}
38
+ {{#if providerData.tutorialUrl}}
39
+ <p><a href="{{providerData.tutorialUrl}}" target="_blank" rel="noopener noreferrer" referrerpolicy="no-referrer"
40
+ class="link link-animated">Read the {{providerData.comment}} setup guide</a></p>
41
+ {{/if}}
42
+ </div>
31
43
  {{/ui/stat-card}}
32
- {{/if}}
33
44
 
34
- {{#if activeOutlookService}}
35
- {{#> ui/stat-card variant="info" icon="icon-[tabler--info-circle]" class="mb-6"}}
36
- <strong>Application</strong> access means EmailEngine authenticates as the app itself using
37
- client credentials, with no interactive user login required. The Entra app registration must have
38
- <strong>application permissions</strong> (not delegated) with admin consent. Use this for
39
- service integrations, shared mailboxes, or when you cannot perform interactive logins.
40
- Accounts using application access can only be added via the
41
- <a href="/admin/reference/account#postV1Account" class="link link-animated">REST API</a>,
42
- not through the hosted authentication form.
43
- {{#if providerData.tutorialUrl}}
44
- Read about setting up {{providerData.comment}} from <a href="{{providerData.tutorialUrl}}" target="_blank"
45
- rel="noopener noreferrer" referrerpolicy="no-referrer" class="link link-animated">here</a>.
46
- {{/if}}
47
- {{/ui/stat-card}}
48
- {{/if}}
45
+ {{#> ui/card title="Application" bodyClass="space-y-4"}}
46
+ <div>
47
+ {{#> ui/form-field id="name" label="Application name" error=errors.name}}
48
+ <input type="text" class="input{{#if errors.name}} is-invalid{{/if}}" id="name" name="name" value="{{values.name}}"
49
+ placeholder="For example &quot;My App&quot;" required />
50
+ <span class="helper-text">Shown in the OAuth2 app list.</span>
51
+ {{/ui/form-field}}
52
+ </div>
49
53
 
50
- <div class="card bg-base-100 shadow-md mb-6">
54
+ <div>
55
+ {{#> ui/form-field id="description" label="Description" error=errors.description}}
56
+ <input type="text" class="input{{#if errors.description}} is-invalid{{/if}}" id="description" name="description"
57
+ value="{{values.description}}" />
58
+ <span class="helper-text">Optional. A note on what this app is used for.</span>
59
+ {{/ui/form-field}}
60
+ </div>
51
61
 
52
- <div class="card-body space-y-4">
62
+ {{#unless providerData.serviceAccount}}
63
+ <div>
64
+ {{#> ui/form-field id="title" label="Display title" error=errors.title}}
65
+ <input type="text" class="input{{#if errors.title}} is-invalid{{/if}}" id="title" name="title"
66
+ value="{{values.title}}" />
67
+ <span class="helper-text">Optional. Shown on this app's button in the hosted authentication form.</span>
68
+ {{/ui/form-field}}
69
+ </div>
53
70
 
54
- <div>
55
- {{#> ui/form-field id="name" label="Application name" error=errors.name}}
56
- <input type="text" class="input{{#if errors.name}} is-invalid{{/if}}" id="name" name="name"
57
- value="{{values.name}}" placeholder="Enter application name, eg. &quot;My App&quot;&mldr;" required />
58
- <span class="helper-text">Name shown in the OAuth2 app list.</span>
59
- {{/ui/form-field}}
60
- </div>
71
+ <div>
72
+ {{> ui/checkbox id="enabled" name="enabled" label="Enable this app" checked=values.enabled error=errors.enabled
73
+ hint="Offer this app as an account type in the hosted authentication form."}}
74
+ </div>
75
+ {{/unless}}
61
76
 
62
- <div>
63
- {{#> ui/form-field id="description" label="Description" error=errors.description}}
64
- <input type="text" class="input{{#if errors.description}} is-invalid{{/if}}" id="description"
65
- name="description" value="{{values.description}}" placeholder="" />
66
- <span class="helper-text">Describe what this app is used for.</span>
67
- {{/ui/form-field}}
68
- </div>
77
+ {{#if activeGmail}}
78
+ <div>
79
+ {{> ui/checkbox id="googleWorkspaceAccounts" name="googleWorkspaceAccounts"
80
+ label="Accept only Google Workspace accounts" checked=values.googleWorkspaceAccounts
81
+ error=errors.googleWorkspaceAccounts
82
+ hint="Shows only Google Workspace accounts on the Gmail sign-in screen, and refuses the setup if a personal account signs in anyway."}}
83
+ </div>
84
+ {{/if}}
85
+ {{/ui/card}}
86
+
87
+ {{!-- The base scope comes before the credentials: it decides which sections apply (the Pub/Sub app
88
+ selector, the scope presets, the Graph notification endpoints) and, for a service account, which
89
+ authentication methods can be offered (the attached service account is Pub/Sub only). One panel per
90
+ scope, each marked data-base-scopes; checkScopesRadio() shows the selected one. A stored app's scope
91
+ cannot change, so its page names the scope instead of offering the strip, and the server renders the
92
+ matching panel visible. Mail.ru has a single mode and no card. --}}
93
+ {{#unless activeMailRu}}
94
+ {{!-- wrap-anywhere: the scope URLs in the descriptions have no break points of their own --}}
95
+ {{#> ui/card title="Base scope" bodyClass="space-y-4 wrap-anywhere"}}
96
+
97
+ {{#if activeOutlookService}}
98
+ <input type="hidden" name="baseScopes" value="api" />
99
+ <p><strong>MS Graph API</strong> <span class="text-sm text-base-content/60">- the only mode application
100
+ access supports</span></p>
101
+ {{else if actionCreate}}
102
+ {{#> ui/choice-tabs label="Base scope" heading="What the app connects with" note="Fixed once the app is created"
103
+ elId="base-scope-tabs"}}
104
+ {{> ui/choice-tab id="baseScopesImap" name="baseScopes" value="imap" label="IMAP and SMTP"
105
+ checked=baseScopesImap class="base-scopes-radio"}}
106
+ {{> ui/choice-tab id="baseScopesAPI" name="baseScopes" value="api"
107
+ label=(when activeOutlook "MS Graph API" "Gmail API") checked=baseScopesApi class="base-scopes-radio"}}
108
+ {{#if activeGmailService}}
109
+ {{> ui/choice-tab id="baseScopesPubsub" name="baseScopes" value="pubsub" label="Cloud Pub/Sub"
110
+ checked=baseScopesPubsub class="base-scopes-radio"}}
111
+ {{/if}}
112
+ {{/ui/choice-tabs}}
113
+ {{else}}
114
+ <p>
115
+ <strong>{{#if baseScopesPubsub}}Cloud Pub/Sub{{else if baseScopesApi}}{{#if activeOutlook}}MS Graph API{{else}}Gmail API{{/if}}{{else}}IMAP and SMTP{{/if}}</strong>
116
+ <span class="text-sm text-base-content/60">- fixed once the app is created</span>
117
+ </p>
118
+ {{/if}}
69
119
 
70
- {{#unless activeGmailService}}{{#unless activeOutlookService}}
71
- <div>
72
- {{#> ui/form-field id="title" label="Display title" error=errors.title}}
73
- <input type="text" class="input{{#if errors.title}} is-invalid{{/if}}" id="title" name="title"
74
- value="{{values.title}}" placeholder="" />
75
- <span class="helper-text">Optional title shown next to this app on the hosted authentication form.</span>
76
- {{/ui/form-field}}
120
+ {{#unless activeOutlookService}}
121
+ <div class="space-y-4{{#unless baseScopesImap}} hidden{{/unless}}" data-base-scopes="imap">
122
+ <p class="text-sm">
123
+ {{#if activeGmail}}Mail is synced over IMAP and sent over SMTP. Requires the
124
+ <code>https://mail.google.com/</code> scope on the OAuth consent screen.{{/if}}
125
+ {{#if activeGmailService}}Mail is synced over IMAP and sent over SMTP for any mailbox in your
126
+ Workspace. Authorize the domain-wide delegation for <code>https://mail.google.com/</code>.{{/if}}
127
+ {{#if activeOutlook}}Mail is synced over IMAP and sent over SMTP. Requires the
128
+ <code>IMAP.AccessAsUser.All</code> and <code>SMTP.Send</code> delegated permissions.{{/if}}
129
+ </p>
77
130
  </div>
78
- {{/unless}}{{/unless}}
79
-
80
-
81
- {{#if activeGmail}}
82
- <div>
83
- {{> ui/checkbox id="googleWorkspaceAccounts" name="googleWorkspaceAccounts"
84
- label="Accept only Google Workspace accounts"
85
- checked=values.googleWorkspaceAccounts error=errors.googleWorkspaceAccounts
86
- hint="Shows only Google Workspace accounts on the Gmail sign-in screen, and refuses the setup if a personal account signs in anyway."}}
131
+ {{/unless}}
132
+
133
+ <div class="space-y-4{{#unless activeOutlookService}}{{#unless baseScopesApi}} hidden{{/unless}}{{/unless}}"
134
+ data-base-scopes="api">
135
+ <p class="text-sm">
136
+ {{#if activeGmail}}Mail is synced and sent through the Gmail HTTP API. Requires the
137
+ <code>https://www.googleapis.com/auth/gmail.modify</code> scope on the OAuth consent screen.{{/if}}
138
+ {{#if activeGmailService}}Mail is synced and sent through the Gmail HTTP API for any mailbox in
139
+ your Workspace. Authorize the domain-wide delegation for
140
+ <code>https://www.googleapis.com/auth/gmail.modify</code>.{{/if}}
141
+ {{#if activeOutlook}}Mail is synced and sent through Microsoft Graph. Requires the
142
+ <code>Mail.ReadWrite</code> and <code>Mail.Send</code> delegated permissions.{{/if}}
143
+ {{#if activeOutlookService}}Mail is synced and sent through Microsoft Graph. Requires the
144
+ <code>Mail.ReadWrite</code>, <code>Mail.Send</code> and <code>User.Read.All</code> application
145
+ permissions with admin consent.{{/if}}
146
+ </p>
147
+ {{!-- Guarded on providerData.gmailApi, not on one provider: a service account in Gmail API mode
148
+ takes the same delegated scopes an interactive app takes, so the presets apply to it too --}}
149
+ {{#if providerData.gmailApi}}
150
+ {{> oauth_scope_presets provider="gmail"}}
151
+ {{> oauth_pubsub_app_select}}
152
+ {{/if}}
153
+ {{#if activeOutlook}}
154
+ {{> oauth_scope_presets provider="outlook"}}
155
+ {{> oauth_graph_endpoints}}
156
+ {{/if}}
157
+ {{#if activeOutlookService}}
158
+ {{> oauth_graph_endpoints}}
159
+ {{/if}}
87
160
  </div>
88
- {{/if}}
89
161
 
90
- {{#unless activeGmailService}}{{#unless activeOutlookService}}
91
- <div>
92
- {{> ui/checkbox id="enabled" name="enabled" label="Enable this app" checked=values.enabled
93
- error=errors.enabled
94
- hint="Show this app as an account type in the hosted authentication form."}}
162
+ {{#if activeGmailService}}
163
+ <div class="space-y-4{{#unless baseScopesPubsub}} hidden{{/unless}}" data-base-scopes="pubsub">
164
+ <p class="text-sm">Accesses no mailboxes: creates and manages the Pub/Sub topic and subscription that
165
+ deliver real-time change notifications for your Gmail API apps. The service account needs the
166
+ <code>Pub/Sub Admin</code> role in the project.</p>
167
+ {{#if actionCreate}}
168
+ <div>
169
+ {{#> ui/form-field id="googleTopicName" label="Topic name" error=errors.googleTopicName}}
170
+ <input type="text" class="input{{#if errors.googleTopicName}} is-invalid{{/if}}" id="googleTopicName"
171
+ name="googleTopicName" value="{{values.googleTopicName}}" placeholder="ee-pub-&lt;app id&gt;" />
172
+ <span class="helper-text">Optional. Leave empty to use the generated name shown.</span>
173
+ {{/ui/form-field}}
174
+ </div>
175
+ <div>
176
+ {{#> ui/form-field id="googleSubscriptionName" label="Subscription name"
177
+ error=errors.googleSubscriptionName}}
178
+ <input type="text" class="input{{#if errors.googleSubscriptionName}} is-invalid{{/if}}"
179
+ id="googleSubscriptionName" name="googleSubscriptionName"
180
+ value="{{values.googleSubscriptionName}}" placeholder="ee-sub-&lt;app id&gt;" />
181
+ <span class="helper-text">Optional. Leave empty to use the generated name shown.</span>
182
+ {{/ui/form-field}}
183
+ </div>
184
+ {{else}}
185
+ <dl class="ee-dl">
186
+ <dt>Pub/Sub topic</dt>
187
+ <dd>{{#if appData.pubSubTopic}}<code>{{lastVal appData.pubSubTopic "/"}}</code>{{else}}Not created
188
+ yet{{/if}}</dd>
189
+ <dt>Pub/Sub subscription</dt>
190
+ <dd>{{#if appData.pubSubSubscription}}<code>{{lastVal appData.pubSubSubscription
191
+ "/"}}</code>{{else}}Not created yet{{/if}}</dd>
192
+ </dl>
193
+ {{/if}}
95
194
  </div>
96
- {{/unless}}{{/unless}}
97
-
98
- </div>
99
- </div>
195
+ {{/if}}
196
+ {{/ui/card}}
197
+ {{/unless}}
100
198
 
199
+ {{!-- Hand-rolled rather than ui/card: the whole body is one {{#if}}/{{else}}, which is the shape that
200
+ loses its content inside a partial block (see .claude/rules/admin-ui.md) --}}
101
201
  <div class="card bg-base-100 shadow-md mb-6">
102
202
 
103
203
  <div class="card-header">
104
- <h6 class="card-title text-primary">OAuth2 Credentials</h6>
204
+ <h6 class="card-title text-primary">Credentials</h6>
105
205
  </div>
106
206
 
107
207
  <div class="card-body space-y-4">
108
208
 
109
209
  {{#if activeGmailService}}
110
210
 
211
+ {{#if authMethodLocked}}
111
212
  <div>
112
- <label class="label-text block">Authentication method</label>
213
+ <span class="label-text block">Authentication method</span>
113
214
  <input type="hidden" name="authMethod" id="authMethod"
114
215
  value="{{#if authMethodIsExternalAccount}}externalAccount{{else if authMethodIsMetadataServer}}metadataServer{{else}}serviceKey{{/if}}" />
115
- {{#if authMethodLocked}}
116
- <p class="mb-1">
117
- <strong>{{#if authMethodIsExternalAccount}}Workload Identity Federation (keyless){{else if
118
- authMethodIsMetadataServer}}Attached service account (Google Cloud){{else}}Service
119
- account key{{/if}}</strong>
216
+ <p>
217
+ <strong>{{#if authMethodIsExternalAccount}}Workload Identity Federation{{else if
218
+ authMethodIsMetadataServer}}Attached service account{{else}}Service account key{{/if}}</strong>
219
+ <span class="text-sm text-base-content/60">- fixed once the app is created</span>
120
220
  </p>
121
- <span class="helper-text">The authentication method is fixed once the application has been created and
122
- cannot be changed.</span>
123
- {{else}}
124
- {{!-- custom tab behavior: the script at the end of this partial
125
- toggles tab-active and the auth-method sections; not a FlyonUI
126
- data-tabs instance, deliberately - each method toggles two
127
- .auth-method-section blocks that are interleaved with fields
128
- shared by both methods, and HSTabs maps one toggle to exactly
129
- one content element. The script also syncs the hidden
130
- #authMethod input submitted with the form. --}}
131
- <nav class="tabs tabs-bordered" id="auth-method-tabs" role="tablist" aria-label="Authentication method">
132
- <button type="button" class="tab auth-method-tab{{#if authMethodIsServiceKey}} tab-active{{/if}}"
133
- id="auth-method-tab-serviceKey" data-auth-method="serviceKey" role="tab"
134
- aria-selected="{{#if authMethodIsServiceKey}}true{{else}}false{{/if}}">Service account key</button>
135
- <button type="button" class="tab auth-method-tab{{#if authMethodIsExternalAccount}} tab-active{{/if}}"
136
- id="auth-method-tab-externalAccount" data-auth-method="externalAccount" role="tab"
137
- aria-selected="{{#if authMethodIsExternalAccount}}true{{else}}false{{/if}}">Workload Identity
138
- Federation (keyless)</button>
139
- {{!-- Pub/Sub only: the metadata server's token is the service account's own and
140
- cannot impersonate a Workspace user. The script at the end of this partial
141
- shows it while the Cloud Pub/Sub base scope is selected --}}
142
- <button type="button"
143
- class="tab auth-method-tab{{#if authMethodIsMetadataServer}} tab-active{{/if}}{{#unless baseScopesPubsub}} hidden{{/unless}}"
144
- id="auth-method-tab-metadataServer" data-auth-method="metadataServer" data-auth-method-scope="pubsub"
145
- role="tab" aria-selected="{{#if authMethodIsMetadataServer}}true{{else}}false{{/if}}">Attached
146
- service account (Google Cloud)</button>
147
- </nav>
148
- <span class="helper-text">"Service account key" expects a downloaded JSON key file.
149
- "Workload Identity Federation" authenticates without a long-lived key, using a credential issued
150
- by your runtime environment. For a Cloud Pub/Sub application running on Google Cloud, "Attached
151
- service account" uses the service account of the VM, GKE workload or Cloud Run service itself,
152
- with nothing to store.</span>
153
- {{/if}}
154
221
  </div>
222
+ {{else}}
223
+ {{!-- A ui/choice-tabs strip: the selection is the submitted authMethod radio. Every method is
224
+ always offered, so the strip never changes shape. The attached service account is Pub/Sub
225
+ only (the metadata server's token is the service account's own and cannot impersonate a
226
+ Workspace user): outside that base scope its tab carries a badge saying so, and choosing it
227
+ selects the Cloud Pub/Sub base scope above. The script at the end of this partial swaps the
228
+ .auth-method-section blocks, which are interleaved with fields shared by the methods, and
229
+ each method's own description opens its section. --}}
230
+ <div>
231
+ {{#> ui/choice-tabs label="Authentication method" heading="Authentication method"
232
+ note="Fixed once the app is created" elId="auth-method-tabs"}}
233
+ {{> ui/choice-tab id="authMethodServiceKey" name="authMethod" value="serviceKey"
234
+ label="Service account key" checked=authMethodIsServiceKey class="auth-method-radio"}}
235
+ {{> ui/choice-tab id="authMethodExternalAccount" name="authMethod" value="externalAccount"
236
+ label="Workload Identity Federation" checked=authMethodIsExternalAccount class="auth-method-radio"}}
237
+ {{> ui/choice-tab id="authMethodMetadataServer" name="authMethod" value="metadataServer"
238
+ label="Attached service account" checked=authMethodIsMetadataServer class="auth-method-radio"
239
+ badgeLabel="Pub/Sub only" badgeId="authMethodScopeBadge" badgeHidden=baseScopesPubsub}}
240
+ {{/ui/choice-tabs}}
241
+ <span class="helper-text text-warning hidden" id="authMethodNotice" aria-live="polite"></span>
242
+ </div>
243
+ {{/if}}
155
244
 
156
- <div class="auth-method-section auth-method-section-serviceKey{{#unless authMethodIsServiceKey}} hidden{{/unless}}">
245
+ <div class="auth-method-section auth-method-section-serviceKey space-y-3{{#unless authMethodIsServiceKey}} hidden{{/unless}}">
246
+ {{#unless authMethodLocked}}
247
+ <p class="text-sm">Signs in with a JSON key file downloaded from the Google Cloud console.</p>
248
+ {{/unless}}
157
249
  <div>
158
- {{> ui/btn label="Load configuration from the service key file…" variant="info" id="serviceFile"
250
+ {{> ui/btn label="Load from the key file..." variant="info" id="serviceFile"
159
251
  icon="icon-[tabler--cloud-upload]"}}
160
252
  <span class="helper-text">Choose a service account key JSON file to fill in the credentials below.</span>
161
253
  </div>
162
254
  </div>
163
255
 
164
- <div class="auth-method-section auth-method-section-externalAccount{{#unless authMethodIsExternalAccount}} hidden{{/unless}}">
256
+ <div class="auth-method-section auth-method-section-externalAccount space-y-3{{#unless authMethodIsExternalAccount}} hidden{{/unless}}">
257
+ {{#unless authMethodLocked}}
258
+ <p class="text-sm">No long-lived key: EmailEngine exchanges a credential issued by its runtime (GKE,
259
+ EKS, AKS or any OIDC-emitting workload) for Google access tokens.</p>
260
+ {{/unless}}
165
261
  <div>
166
- {{> ui/btn label="Load configuration from the external-account JSON file…" variant="info"
262
+ {{> ui/btn label="Load from the configuration file..." variant="info"
167
263
  id="externalAccountFile" icon="icon-[tabler--cloud-upload]"}}
168
264
  <span class="helper-text">Select the credential configuration file produced by
169
265
  <code>gcloud iam workload-identity-pools create-cred-config</code>.</span>
@@ -172,8 +268,8 @@ Read about setting up {{providerData.comment}} from <a href="{{providerData.tuto
172
268
 
173
269
  <div class="auth-method-section auth-method-section-metadataServer{{#unless authMethodIsMetadataServer}} hidden{{/unless}}">
174
270
  <div class="space-y-2">
175
- <p class="text-sm">EmailEngine requests access tokens for the service account attached to the
176
- machine it runs on, from the Google Cloud metadata server. Nothing is stored. Grant that service
271
+ <p class="text-sm">Uses the service account of the VM, GKE workload or Cloud Run service EmailEngine
272
+ runs on, so there is nothing to store. Available for Cloud Pub/Sub apps only. Grant that service
177
273
  account the <code>Pub/Sub Admin</code> role, and on Compute Engine give the VM the
178
274
  <code>cloud-platform</code> access scope.</p>
179
275
  {{#if actionCreate}}
@@ -187,12 +283,13 @@ Read about setting up {{providerData.comment}} from <a href="{{providerData.tuto
187
283
  </div>
188
284
 
189
285
  <div>
190
- {{#> ui/form-field id="googleProjectId" label="Google Cloud Project ID" error=errors.googleProjectId}}
286
+ {{#> ui/form-field id="googleProjectId" label="Google Cloud project ID" error=errors.googleProjectId}}
191
287
  <input type="text" class="input{{#if errors.googleProjectId}} is-invalid{{/if}}" id="googleProjectId"
192
288
  name="googleProjectId" value="{{values.googleProjectId}}"
193
- placeholder="Enter the Google Cloud Project ID of the service, for example &quot;project-name-425411&quot;"
289
+ placeholder="For example &quot;project-name-425411&quot;"
194
290
  required />
195
- <span class="helper-text">Google Cloud project that owns this service account.</span>
291
+ <span class="helper-text">The project that owns the service account. A Cloud Pub/Sub app creates its
292
+ topic and subscription there.</span>
196
293
  {{/ui/form-field}}
197
294
  </div>
198
295
 
@@ -205,7 +302,7 @@ Read about setting up {{providerData.comment}} from <a href="{{providerData.tuto
205
302
  {{#> ui/form-field id="serviceClientEmail" label="Service account email" error=errors.serviceClientEmail}}
206
303
  <input type="email" class="input{{#if errors.serviceClientEmail}} is-invalid{{/if}}" id="serviceClientEmail"
207
304
  name="serviceClientEmail" value="{{values.serviceClientEmail}}"
208
- placeholder="Enter the principal of the service, for example &quot;name@project-123.iam.gserviceaccount.com&quot;"
305
+ placeholder="For example &quot;name@project-123.iam.gserviceaccount.com&quot;"
209
306
  required {{#if authMethodIsMetadataServer}}disabled{{/if}} />
210
307
  <span class="helper-text">Email address of the Google service account.</span>
211
308
  {{/ui/form-field}}
@@ -214,7 +311,7 @@ Read about setting up {{providerData.comment}} from <a href="{{providerData.tuto
214
311
  <div>
215
312
  {{#> ui/form-field id="serviceClient" label="Service account client ID" error=errors.serviceClient}}
216
313
  <input type="text" class="input{{#if errors.serviceClient}} is-invalid{{/if}}" id="serviceClient"
217
- name="serviceClient" value="{{values.serviceClient}}" placeholder="Enter service client ID&mldr;"
314
+ name="serviceClient" value="{{values.serviceClient}}" placeholder="For example &quot;104226123456789012345&quot;"
218
315
  required {{#if authMethodIsMetadataServer}}disabled{{/if}} />
219
316
  <span class="helper-text">Numeric client ID used to configure domain-wide delegation.</span>
220
317
  {{/ui/form-field}}
@@ -252,750 +349,173 @@ Read about setting up {{providerData.comment}} from <a href="{{providerData.tuto
252
349
  </div>
253
350
  </div>
254
351
 
255
- {{else if activeOutlookService}}
256
-
257
- <div>
258
- {{#> ui/form-field id="clientId" label="Application (client) ID" error=errors.clientId}}
259
- <input type="text" class="input{{#if errors.clientId}} is-invalid{{/if}}" id="clientId" name="clientId"
260
- value="{{values.clientId}}" placeholder="Enter application (client) ID&mldr;" required />
261
- <span class="helper-text">The Application (client) ID from your Entra app registration.</span>
262
- {{/ui/form-field}}
263
- </div>
352
+ {{else}}
264
353
 
354
+ {{#if activeGmail}}
265
355
  <div>
266
- {{#> ui/form-field id="clientSecret" label="Client Secret" error=errors.clientSecret}}
267
- <input type="text" class="input{{#if errors.clientSecret}} is-invalid{{/if}}" id="clientSecret"
268
- name="clientSecret" value="{{values.clientSecret}}" {{#if hasClientSecret}}
269
- placeholder="Client secret is set but not shown&mldr;" {{else}} placeholder="Enter client
270
- secret&mldr;" {{/if}} {{#unless hasClientSecret}}required{{/unless}} />
271
- <span class="helper-text">Client secret value from Certificates &amp; secrets.</span>
272
- {{/ui/form-field}}
356
+ {{> ui/btn label="Load from the client JSON file..." variant="info" id="gmailConfigFile"
357
+ icon="icon-[tabler--cloud-upload]"}}
358
+ <span class="helper-text">Fills in the fields below from the client file downloaded from the Google Cloud
359
+ console.</span>
273
360
  </div>
361
+ {{/if}}
274
362
 
275
363
  <div>
276
- {{#> ui/form-field id="cloud" label="Azure cloud environment" error=errors.cloud}}
277
- <select class="select max-w-md{{#if errors.cloud}} is-invalid{{/if}}" id="cloud" name="cloud"
278
- required>
279
-
280
- {{#each azureClouds}}
281
- <option value="{{id}}" {{#if selected}}selected{{/if}}>{{name}}{{#if
282
- description}} -
283
- {{description}}{{/if}}</option>
284
- {{/each}}
285
- </select>
286
- <span class="helper-text">Accounts hosted in different cloud environments use different OAuth2
287
- endpoints.</span>
364
+ {{#> ui/form-field id="clientId" label=(when providerData.microsoft "Application (client) ID" "Client ID") error=errors.clientId}}
365
+ <input type="text" class="input{{#if errors.clientId}} is-invalid{{/if}}" id="clientId" name="clientId"
366
+ value="{{values.clientId}}" required />
367
+ <span class="helper-text">
368
+ {{#if activeGmail}}From APIs &amp; Services &gt; Credentials in the Google Cloud console.{{/if}}
369
+ {{#if providerData.microsoft}}From the Overview page of the app registration in Microsoft
370
+ Entra.{{/if}}
371
+ {{#if activeMailRu}}From the settings of your Mail.ru OAuth2 application.{{/if}}
372
+ </span>
288
373
  {{/ui/form-field}}
289
374
  </div>
290
375
 
291
376
  <div>
292
- {{#> ui/form-field id="authority" label="Directory (tenant) ID" error=errors.authority}}
293
- <input type="text" class="input{{#if errors.authority}} is-invalid{{/if}}" id="authority" name="authority"
294
- value="{{values.authority}}"
295
- placeholder="Enter tenant ID, eg. &quot;f8cdef31-a31e-4b4a-93e4-5f571e91255a&quot;" required />
296
- <span class="helper-text">The Directory (tenant) ID from your Entra app registration. Client credentials
297
- flow requires a specific tenant ID.</span>
377
+ {{#> ui/form-field id="clientSecret" label="Client secret" error=errors.clientSecret}}
378
+ {{> ui/secret-field id="clientSecret" value=values.clientSecret toggleId="showClientSecret"
379
+ toggleLabel="Show client secret" error=errors.clientSecret required=(when hasClientSecret "" "required")
380
+ placeholder=(when hasClientSecret "Set, not shown. Leave empty to keep it." "")}}
381
+ <span class="helper-text">
382
+ {{#if activeGmail}}Shown next to the client ID in the Google Cloud console.{{/if}}
383
+ {{#if providerData.microsoft}}The secret's Value from Certificates &amp; secrets, not its Secret
384
+ ID.{{/if}}
385
+ {{#if activeMailRu}}From the settings of your Mail.ru OAuth2 application.{{/if}}
386
+ </span>
298
387
  {{/ui/form-field}}
299
388
  </div>
300
389
 
301
- {{else}}
302
-
303
390
  {{#if activeGmail}}
304
-
305
- <div>
306
- {{> ui/btn label="Load configuration from the JSON file…" variant="info" id="gmailConfigFile"
307
- icon="icon-[tabler--cloud-upload]"}}
308
- <span class="helper-text">Choose the OAuth client JSON file downloaded from Google Cloud Console.</span>
309
- </div>
310
-
311
391
  <div>
312
- {{#> ui/form-field id="googleProjectId" label="Google Cloud Project ID" error=errors.googleProjectId}}
392
+ {{#> ui/form-field id="googleProjectId" label="Google Cloud project ID" error=errors.googleProjectId}}
313
393
  <input type="text" class="input{{#if errors.googleProjectId}} is-invalid{{/if}}" id="googleProjectId"
314
394
  name="googleProjectId" value="{{values.googleProjectId}}"
315
- placeholder="Enter the Google Cloud Project ID of the service, for example &quot;project-name-425411&quot;" />
316
- <span class="helper-text">OAuth2 Project ID</span>
395
+ placeholder="For example &quot;project-name-425411&quot;" />
396
+ <span class="helper-text">Optional. The project that owns the OAuth client; a Gmail API app uses it to
397
+ offer Pub/Sub apps from the same project.</span>
317
398
  {{/ui/form-field}}
318
399
  </div>
319
-
320
400
  {{/if}}
321
401
 
322
- <div>
323
- {{#> ui/form-field id="clientId" error=errors.clientId}}
324
- <label class="label-text" for="clientId">
325
- {{#if activeGmail}}
326
- Client ID
327
- {{/if}}
328
-
329
- {{#if activeMailRu}}
330
- Client ID
331
- {{/if}}
332
-
333
- {{#if activeOutlook}}
334
- Application (client) ID
335
- {{/if}}
336
- </label>
337
- <input type="text" class="input{{#if errors.clientId}} is-invalid{{/if}}" id="clientId" name="clientId"
338
- value="{{values.clientId}}" placeholder="Enter client ID&mldr;" required />
339
- <span class="helper-text">Client ID from your provider's app configuration.</span>
340
- {{/ui/form-field}}
341
- </div>
342
-
343
- <div>
344
- {{#> ui/form-field id="clientSecret" label="Client Secret" error=errors.clientSecret}}
345
- <input type="text" class="input{{#if errors.clientSecret}} is-invalid{{/if}}" id="clientSecret"
346
- name="clientSecret" value="{{values.clientSecret}}" {{#if hasClientSecret}}
347
- placeholder="Client secret is set but not shown&mldr;" {{else}} placeholder="Enter client
348
- secret&mldr;" {{/if}} {{#unless hasClientSecret}}required{{/unless}} />
349
- <span class="helper-text">OAuth2 client secret.</span>
350
- {{/ui/form-field}}
351
- </div>
352
-
353
- {{#if activeOutlook}}
354
-
402
+ {{#if providerData.microsoft}}
355
403
  <div>
356
404
  {{#> ui/form-field id="cloud" label="Azure cloud environment" error=errors.cloud}}
357
- <select class="select max-w-md{{#if errors.cloud}} is-invalid{{/if}}" id="cloud" name="cloud"
358
- required>
359
-
405
+ <select class="select max-w-md{{#if errors.cloud}} is-invalid{{/if}}" id="cloud" name="cloud" required>
360
406
  {{#each azureClouds}}
361
- <option value="{{id}}" {{#if selected}}selected{{/if}}>{{name}}{{#if
362
- description}} -
407
+ <option value="{{id}}" {{#if selected}}selected{{/if}}>{{name}}{{#if description}} -
363
408
  {{description}}{{/if}}</option>
364
409
  {{/each}}
365
410
  </select>
366
- <span class="helper-text">Accounts hosted in different cloud environments use different OAuth2 endpoints
367
- and scopes.</span>
411
+ <span class="helper-text">Accounts in different cloud environments use different OAuth2 endpoints.</span>
368
412
  {{/ui/form-field}}
369
413
  </div>
370
-
371
414
  {{/if}}
372
415
 
373
416
  {{#if activeOutlook}}
374
-
375
417
  <div>
376
- <label class="label-text block mb-2">Supported account types</label>
377
-
378
- <div class="space-y-2">
379
- <div class="flex items-start gap-2">
380
- <input class="radio radio-sm mt-0.5 r-auth" type="radio" name="authority"
381
- id="authorityOrganizations" value="organizations" {{#if
382
- authorityOrganizations}}checked{{/if}}>
383
- <label class="label-text p-0" for="authorityOrganizations">
384
- Accounts in any organizational directory (Any Microsoft Entra ID tenant - Multitenant)
385
- </label>
386
- </div>
387
-
388
- <div class="flex items-start gap-2">
389
- <input class="radio radio-sm mt-0.5 r-auth" type="radio" name="authority" id="authorityCommon"
390
- value="common" {{#if authorityCommon}}checked{{/if}}>
391
- <label class="label-text p-0" for="authorityCommon">
392
- Accounts in any organizational directory (Any Microsoft Entra ID tenant - Multitenant) and
393
- personal Microsoft accounts (e.g. Skype, Xbox)
394
- </label>
395
- </div>
396
-
397
- <div class="flex items-start gap-2">
398
- <input class="radio radio-sm mt-0.5 r-auth" type="radio" name="authority" id="authorityConsumers"
399
- value="consumers" {{#if authorityConsumers}}checked{{/if}}>
400
- <label class="label-text p-0" for="authorityConsumers">
401
- Personal Microsoft accounts only
402
- </label>
403
- </div>
404
-
405
- <div class="flex items-start gap-2">
406
- <input class="radio radio-sm mt-0.5 r-auth" type="radio" name="authority" id="authorityTenant"
407
- value="tenant" {{#if authorityTenant}}checked{{/if}}>
408
- <label class="label-text p-0" for="authorityTenant">
409
- Accounts in the specified organizational directory only (Single tenant)
410
- </label>
411
- </div>
412
- </div>
418
+ {{#> ui/form-field id="authority" label="Supported account types" error=errors.authority}}
419
+ <select class="select max-w-md{{#if errors.authority}} is-invalid{{/if}}" id="authority"
420
+ name="authority" required>
421
+ {{!-- an app stored without an account type gets no silent default: saving it asks --}}
422
+ {{#unless authorityCommon}}{{#unless authorityOrganizations}}{{#unless authorityConsumers}}{{#unless
423
+ authorityTenant}}<option value="" selected disabled>Choose...</option>{{/unless}}{{/unless}}{{/unless}}{{/unless}}
424
+ <option value="common" {{#if authorityCommon}}selected{{/if}}>Work, school and personal Microsoft
425
+ accounts</option>
426
+ <option value="organizations" {{#if authorityOrganizations}}selected{{/if}}>Work and school accounts
427
+ from any organization</option>
428
+ <option value="consumers" {{#if authorityConsumers}}selected{{/if}}>Personal Microsoft accounts only
429
+ </option>
430
+ <option value="tenant" {{#if authorityTenant}}selected{{/if}}>Work and school accounts from one
431
+ organization</option>
432
+ </select>
433
+ <span class="helper-text">Must match "Supported account types" in the app registration.</span>
434
+ {{/ui/form-field}}
413
435
  </div>
414
436
 
415
- <div>
437
+ <div class="{{#unless authorityTenant}}hidden{{/unless}}" id="tenant-field">
416
438
  {{#> ui/form-field id="tenant" label="Directory (tenant) ID" error=errors.tenant}}
417
439
  <input type="text" class="input{{#if errors.tenant}} is-invalid{{/if}}" id="tenant" name="tenant"
418
- value="{{values.tenant}}" />
419
- <span class="helper-text">Fill this value if you checked "Accounts in the specified organizational
420
- directory only" above. The Directory ID is a UUID value like
421
- "f8cdef31-a31e-4b4a-93e4-5f571e91255a"</span>
440
+ value="{{values.tenant}}" placeholder="For example &quot;f8cdef31-a31e-4b4a-93e4-5f571e91255a&quot;"
441
+ {{#unless authorityTenant}}disabled{{/unless}} />
442
+ <span class="helper-text">From the Overview page of the app registration in Microsoft Entra.</span>
422
443
  {{/ui/form-field}}
423
444
  </div>
424
445
  {{/if}}
425
446
 
426
-
447
+ {{#if activeOutlookService}}
427
448
 
428
449
  <div>
429
- {{#> ui/form-field id="redirectUrl" label="Redirect URL" error=errors.redirectUrl}}
430
- <input type="url" class="input{{#if errors.redirectUrl}} is-invalid{{/if}}" id="redirectUrl"
431
- name="redirectUrl" value="{{values.redirectUrl}}" required />
432
- <span class="helper-text">Redirect URL for OAuth2. If you are using EmailEngine's OAuth2 flow, then set it
433
- to <code>{{defaultRedirectUrl}}</code></span>
450
+ {{#> ui/form-field id="authority" label="Directory (tenant) ID" error=errors.authority}}
451
+ <input type="text" class="input{{#if errors.authority}} is-invalid{{/if}}" id="authority" name="authority"
452
+ value="{{values.authority}}" placeholder="For example &quot;f8cdef31-a31e-4b4a-93e4-5f571e91255a&quot;"
453
+ required />
454
+ <span class="helper-text">From the Overview page of the app registration. Application access always
455
+ needs a specific tenant.</span>
434
456
  {{/ui/form-field}}
435
457
  </div>
436
458
  {{/if}}
437
459
 
438
- </div>
439
- </div>
440
-
441
- {{#if activeGmailService}}
442
-
443
- <div class="card bg-base-100 shadow-md mb-6">
444
-
445
- <div class="card-header">
446
- <h6 class="card-title text-primary">Base scopes</h6>
447
- </div>
448
-
449
- <div class="overflow-x-auto">
450
- <table class="table">
451
-
452
- <thead>
453
- <tr>
454
- <th>Type</th>
455
- <th>Description</th>
456
- <th>Requirements</th>
457
-
458
- </tr>
459
-
460
- </thead>
461
- <tbody>
462
-
463
- {{#if actionCreate}}
464
- <tr>
465
- <td>
466
- <div class="flex items-center gap-2">
467
- <input class="radio radio-sm base-scopes-radio" type="radio" name="baseScopes"
468
- id="baseScopesImap" value="imap" {{#if baseScopesImap}}checked{{/if}}>
469
- <label class="label-text p-0" for="baseScopesImap">
470
- IMAP and SMTP
471
- </label>
472
- </div>
473
- </td>
474
- <td>Regular email protocols</td>
475
- <td><code>"https://mail.google.com/"</code> consent screen scope</td>
476
-
477
- </tr>
478
- <tr>
479
- <td>
480
- <div class="flex items-center gap-2">
481
- <input class="radio radio-sm base-scopes-radio" type="radio" name="baseScopes"
482
- id="baseScopesAPI" value="api" {{#if baseScopesApi}}checked{{/if}}>
483
- <label class="label-text p-0" for="baseScopesAPI">
484
- Gmail API {{> ui/badge label="beta" variant="neutral"}}
485
- </label>
486
- </div>
487
- </td>
488
- <td>Gmail HTTP API, through domain-wide delegation</td>
489
- <td><code>"/auth/gmail.modify"</code> delegated scope</td>
490
-
491
- </tr>
492
- <tr>
493
- <td>
494
- <div class="flex items-center gap-2">
495
- <input class="radio radio-sm base-scopes-radio" type="radio" name="baseScopes"
496
- id="baseScopesPubsub" value="pubsub" {{#if baseScopesPubsub}}checked{{/if}}>
497
- <label class="label-text p-0" for="baseScopesPubsub">
498
- Cloud Pub/Sub {{> ui/badge label="beta" variant="neutral"}}
499
- </label>
500
- </div>
501
- </td>
502
- <td>Webhook management</td>
503
- <td><code>"Pub/Sub Admin"</code> service credentials role</td>
504
-
505
- </tr>
506
-
507
- {{else}}
508
- {{#if baseScopesImap}}
509
- <tr>
510
- <td>
511
- <strong>IMAP and SMTP</strong>
512
- </td>
513
- <td>Regular email protocols</td>
514
- <td><code>"https://mail.google.com/"</code> consent screen scope</td>
515
-
516
- </tr>
517
- {{/if}}
518
-
519
- {{#if baseScopesApi}}
520
- <tr>
521
- <td>
522
- <strong>Gmail API</strong> {{> ui/badge label="beta" variant="neutral"}}
523
- </td>
524
- <td>Gmail HTTP API, through domain-wide delegation</td>
525
- <td><code>"/auth/gmail.modify"</code> delegated scope</td>
526
-
527
- </tr>
528
- {{/if}}
529
-
530
- {{#if baseScopesPubsub}}
531
- <tr>
532
- <td>
533
- <strong>Cloud Pub/Sub</strong> {{> ui/badge label="beta" variant="neutral"}}
534
- </td>
535
- <td>Webhook management</td>
536
- <td><code>"Pub/Sub Admin"</code> service credentials role</td>
537
-
538
- </tr>
539
- {{/if}}
540
-
541
- {{/if}}
542
- </tbody>
543
-
544
- </table>
545
- </div>
546
-
547
- {{> oauth_pubsub_app_select}}
548
-
549
- <div class="card-footer border-base-content/10 border-t px-6 py-4{{#unless baseScopesPubsub}} hidden{{/unless}}"
550
- data-base-scopes="pubsub">
551
-
552
- {{#if actionCreate}}
553
-
554
- <div class="mb-4">
555
- {{#> ui/form-field id="googleTopicName" label="Google Pub/Sub Topic Name" error=errors.googleTopicName}}
556
- <input type="text" class="input{{#if errors.googleTopicName}} is-invalid{{/if}}" id="googleTopicName"
557
- name="googleTopicName" value="{{values.googleTopicName}}"
558
- placeholder="Enter the Topic Name for the Google Pub/Sub subscription, for example &quot;ee-pub-12345&quot;" />
559
- <span class="helper-text">OAuth2 Pub/Sub Topic Name. Automatically generated if not set.</span>
560
- {{/ui/form-field}}
561
- </div>
562
-
460
+ {{#unless activeOutlookService}}
563
461
  <div>
564
- {{#> ui/form-field id="googleSubscriptionName" label="Google Pub/Sub Subscription Name"
565
- error=errors.googleSubscriptionName}}
566
- <input type="text" class="input{{#if errors.googleSubscriptionName}} is-invalid{{/if}}"
567
- id="googleSubscriptionName" name="googleSubscriptionName" value="{{values.googleSubscriptionName}}"
568
- placeholder="Enter the Subscription Name for the Google Pub/Sub subscription, for example &quot;ee-sub-12345&quot;" />
569
- <span class="helper-text">OAuth2 Pub/Sub Subscription Name. Automatically generated if not set.</span>
462
+ {{#> ui/form-field id="redirectUrl" label="Redirect URL" error=errors.redirectUrl}}
463
+ <input type="url" class="input{{#if errors.redirectUrl}} is-invalid{{/if}}" id="redirectUrl"
464
+ name="redirectUrl" value="{{values.redirectUrl}}" required />
465
+ <span class="helper-text">
466
+ {{#if activeGmail}}Add it to the authorized redirect URIs of the OAuth client.{{/if}}
467
+ {{#if activeOutlook}}Add it as a Web redirect URI under Authentication in the app registration.{{/if}}
468
+ {{#if activeMailRu}}Add it to the redirect URIs of your Mail.ru application.{{/if}}
469
+ Change it only if you run your own OAuth2 flow; EmailEngine's own is
470
+ <code>{{defaultRedirectUrl}}</code>.
471
+ </span>
570
472
  {{/ui/form-field}}
571
473
  </div>
572
-
573
- {{else}}
574
-
575
- <dl class="ee-dl">
576
-
577
- <dt>Pub/Sub Topic</dt>
578
- <dd>
579
- {{#if appData.pubSubTopic}}
580
-
581
- <code>{{lastVal appData.pubSubTopic "/"}}</code>
582
- {{else}}
583
- Not initialized
584
- {{/if}}
585
- </dd>
586
-
587
-
588
- <dt>Pub/Sub Subscription</dt>
589
- <dd>
590
- {{#if appData.pubSubSubscription}}
591
- <code>{{lastVal appData.pubSubSubscription "/"}}</code>
592
- {{else}}
593
- Not initialized
594
- {{/if}}
595
- </dd>
596
- </dl>
597
-
474
+ {{/unless}}
598
475
 
599
476
  {{/if}}
600
477
 
601
478
  </div>
602
-
603
479
  </div>
604
- {{/if}}
605
-
606
- {{#if activeGmail}}
607
-
608
- <div class="card bg-base-100 shadow-md mb-6">
609
-
610
- <div class="card-header">
611
- <h6 class="card-title text-primary">Base scopes</h6>
612
- </div>
613
480
 
481
+ {{#> ui/details summary="Custom scopes" summarySmall="Optional" id="setupScopes" class="card bg-base-100 shadow-md mb-6"
482
+ bodyClass="space-y-4 wrap-anywhere"
483
+ open=(when values.extraScopes true values.skipScopes)}}
484
+ <p>Add scopes beyond the defaults, for example when your application uses the access tokens for other services,
485
+ or drop default scopes your integration does not need.</p>
614
486
 
615
- <div class="overflow-x-auto">
616
- <table class="table">
617
-
618
- <thead>
619
- <tr>
620
- <th>Type</th>
621
- <th>Description</th>
622
- <th>Requirements</th>
623
- </tr>
624
-
625
- </thead>
626
- <tbody>
627
-
628
- {{#if actionCreate}}
629
- <tr>
630
- <td>
631
- <div class="flex items-center gap-2">
632
- <input class="radio radio-sm base-scopes-radio" type="radio" name="baseScopes"
633
- id="baseScopesImap" value="imap" {{#if baseScopesImap}}checked{{/if}}>
634
- <label class="label-text p-0" for="baseScopesImap">
635
- IMAP and SMTP
636
- </label>
637
- </div>
638
- </td>
639
- <td>Regular email protocols</td>
640
- <td><code>"https://mail.google.com/"</code> consent screen scope</td>
641
-
642
- </tr>
643
- <tr>
644
- <td>
645
- <div class="flex items-center gap-2">
646
- <input class="radio radio-sm base-scopes-radio" type="radio" name="baseScopes"
647
- id="baseScopesAPI" value="api" {{#if baseScopesApi}}checked{{/if}}>
648
- <label class="label-text p-0" for="baseScopesAPI">
649
- Gmail API {{> ui/badge label="beta" variant="neutral"}}
650
- </label>
651
- </div>
652
- </td>
653
- <td>Gmail HTTP API</td>
654
- <td><code>"/auth/gmail.modify"</code> consent screen scope</td>
655
-
656
- </tr>
657
-
658
- {{else}}
659
-
660
- {{#if baseScopesImap}}
661
- <tr>
662
- <td>
663
- <strong>IMAP and SMTP</strong>
664
- </td>
665
- <td>Regular email protocols</td>
666
- <td><code>"https://mail.google.com/"</code> consent screen scope</td>
667
-
668
- </tr>
669
- {{/if}}
670
-
671
- {{#if baseScopesApi}}
672
- <tr>
673
- <td>
674
- <strong>Gmail API</strong> {{> ui/badge label="beta" variant="neutral"}}
675
- </td>
676
- <td>Gmail HTTP API</td>
677
- <td><code>"/auth/gmail.modify"</code> consent screen scope</td>
678
-
679
- </tr>
680
- {{/if}}
681
-
682
- {{/if}}
683
- </tbody>
684
- </table>
685
- </div>
686
-
687
- {{> oauth_pubsub_app_select}}
688
-
689
- </div>
487
+ {{#if providerData.gmailApi}}
488
+ <div class="alert alert-soft alert-info block">Enable the matching APIs for the project (<em>Enabled APIs &amp;
489
+ services</em> in the <a href="https://console.cloud.google.com/apis/dashboard" target="_blank"
490
+ rel="noopener noreferrer" referrerpolicy="no-referrer" class="link link-animated">Google Cloud console</a>)
491
+ before adding accounts with new scopes, or token requests will fail.</div>
690
492
  {{/if}}
691
493
 
692
-
693
494
  {{#if activeOutlook}}
694
-
695
- <div class="card bg-base-100 shadow-md mb-6">
696
-
697
- <div class="card-header">
698
- <h6 class="card-title text-primary">Base scopes</h6>
699
- </div>
700
-
701
-
702
- <div class="overflow-x-auto">
703
- <table class="table">
704
-
705
- <thead>
706
- <tr>
707
- <th>Type</th>
708
- <th>Description</th>
709
- <th>Requirements</th>
710
- </tr>
711
-
712
- </thead>
713
- <tbody>
714
-
715
- {{#if actionCreate}}
716
- <tr>
717
- <td>
718
- <div class="flex items-center gap-2">
719
- <input class="radio radio-sm base-scopes-radio" type="radio" name="baseScopes"
720
- id="baseScopesImap" value="imap" {{#if baseScopesImap}}checked{{/if}}>
721
- <label class="label-text p-0" for="baseScopesImap">
722
- IMAP and SMTP
723
- </label>
724
- </div>
725
- </td>
726
- <td>Regular email protocols</td>
727
- <td><code>"IMAP.AccessAsUser.All"</code> and <code>"SMTP.Send"</code> consent screen scopes</td>
728
-
729
- </tr>
730
- <tr>
731
- <td>
732
- <div class="flex items-center gap-2">
733
- <input class="radio radio-sm base-scopes-radio" type="radio" name="baseScopes"
734
- id="baseScopesAPI" value="api" {{#if baseScopesApi}}checked{{/if}}>
735
- <label class="label-text p-0" for="baseScopesAPI">
736
- MS Graph API {{> ui/badge label="beta" variant="neutral"}}
737
- </label>
738
- </div>
739
- </td>
740
- <td>Microsoft HTTP API</td>
741
- <td><code>"Mail.ReadWrite"</code> and <code>"Mail.Send"</code> consent screen scopes</td>
742
-
743
- </tr>
744
-
745
- {{else}}
746
-
747
- {{#if baseScopesImap}}
748
- <tr>
749
- <td>
750
- <strong>IMAP and SMTP</strong>
751
- </td>
752
- <td>Regular email protocols</td>
753
- <td><code>"IMAP.AccessAsUser.All"</code> and <code>"SMTP.Send"</code> consent screen scopes</td>
754
-
755
- </tr>
756
- {{/if}}
757
-
758
- {{#if baseScopesApi}}
759
- <tr>
760
- <td>
761
- <strong>MS Graph API</strong> {{> ui/badge label="beta" variant="neutral"}}
762
- </td>
763
- <td>Microsoft HTTP API</td>
764
- <td><code>"Mail.ReadWrite"</code> and <code>"Mail.Send"</code> consent screen scopes</td>
765
-
766
- </tr>
767
- {{/if}}
768
-
769
- {{/if}}
770
- </tbody>
771
- </table>
772
- </div>
773
-
774
- <div class="card-footer border-base-content/10 border-t px-6 py-4{{#unless baseScopesApi}} hidden{{/unless}}"
775
- data-base-scopes="api">
776
-
777
- <p class="mb-2">Microsoft Graph delivers change notifications to EmailEngine at these two endpoints:</p>
778
-
779
- <pre class="ee-code-block mb-2"><code>{{mainServiceUrl}}/oauth/msg/lifecycle
780
- {{mainServiceUrl}}/oauth/msg/notification</code></pre>
781
-
782
- <p class="mb-2">
783
- Both endpoints must be publicly reachable for anonymous HTTPS
784
- <strong>POST</strong> requests. When a notification arrives, EmailEngine
785
- processes the change and sends matching events through your configured webhooks.
786
- </p>
787
-
788
- <p>
789
- If your EmailEngine instance cannot be exposed directly, configure a public
790
- proxy domain in <span class="text-base-content/60 code-link"><a
791
- href="/admin/reference/settings#postV1Settings" target="_blank" rel="noopener noreferrer"
792
- class="link link-animated">notificationBaseUrl</a></span>. Microsoft Graph will then
793
- post to <code>https://&lt;proxy-domain&gt;/oauth/msg/...</code> instead of
794
- <code>{{mainServiceUrl}}</code>.
795
- </p>
796
-
797
-
798
- </div>
799
- </div>
800
-
801
- {{/if}}
802
-
803
- {{#if activeOutlookService}}
804
-
805
- <div class="card bg-base-100 shadow-md mb-6">
806
-
807
- <div class="card-header">
808
- <h6 class="card-title text-primary">Connection type</h6>
809
- </div>
810
-
811
- <div class="card-body">
812
- <input type="hidden" name="baseScopes" value="api" />
813
- <p><strong>MS Graph API</strong> - This app uses Microsoft Graph API with application permissions
814
- (client credentials). Requires <code>Mail.ReadWrite</code>, <code>Mail.Send</code>, and
815
- <code>User.Read.All</code> application permissions with admin consent in Entra.</p>
816
- </div>
817
-
818
- <div class="card-footer border-base-content/10 border-t px-6 py-4">
819
-
820
- <p class="mb-2">Microsoft Graph delivers change notifications to EmailEngine at these two endpoints:</p>
821
-
822
- <pre class="ee-code-block mb-2"><code>{{mainServiceUrl}}/oauth/msg/lifecycle
823
- {{mainServiceUrl}}/oauth/msg/notification</code></pre>
824
-
825
- <p class="mb-2">
826
- Both endpoints must be publicly reachable for anonymous HTTPS
827
- <strong>POST</strong> requests. When a notification arrives, EmailEngine
828
- processes the change and sends matching events through your configured webhooks.
829
- </p>
830
-
831
- <p>
832
- If your EmailEngine instance cannot be exposed directly, configure a public
833
- proxy domain in <span class="text-base-content/60 code-link"><a
834
- href="/admin/reference/settings#postV1Settings" target="_blank" rel="noopener noreferrer"
835
- class="link link-animated">notificationBaseUrl</a></span>. Microsoft Graph will then
836
- post to <code>https://&lt;proxy-domain&gt;/oauth/msg/...</code> instead of
837
- <code>{{mainServiceUrl}}</code>.
838
- </p>
839
-
840
- </div>
841
- </div>
842
-
495
+ <div class="alert alert-soft alert-info block">A Microsoft token is issued for one API, so every scope must come
496
+ from <code>{{#if baseScopesApi}}https://graph.microsoft.com/{{else}}https://outlook.office.com/{{/if}}</code>
497
+ while this app uses {{#if baseScopesApi}}MS Graph API{{else}}IMAP and SMTP{{/if}}.</div>
843
498
  {{/if}}
844
499
 
845
- {{!-- Guarded on providerData.gmailApi, not on one provider: a service account in Gmail API mode takes
846
- the same delegated scopes an interactive app takes, so the presets apply to it too. --}}
847
- {{#if providerData.gmailApi}}
848
- <div class="card bg-base-100 shadow-md mb-6{{#unless baseScopesApi}} hidden{{/unless}}" id="account-type-card-gmail">
849
- <div class="card-header">
850
- <h6 class="card-title text-primary">Scope presets</h6>
500
+ <div class="grid gap-4 md:grid-cols-2">
501
+ <div>
502
+ {{#> ui/form-field id="extraScopes" label="Additional scopes" error=errors.extraScopes}}
503
+ <textarea class="textarea w-full font-mono{{#if errors.extraScopes}} is-invalid{{/if}}" id="extraScopes"
504
+ name="extraScopes" rows="5" spellcheck="false" data-enable-grammarly="false"
505
+ placeholder="One scope per line">{{values.extraScopes}}</textarea>
506
+ <span class="helper-text">Requested on top of the defaults.</span>
507
+ {{/ui/form-field}}
851
508
  </div>
852
- <div class="card-body">
853
- <p class="mb-4">Choose a preset to fill in the scope fields below:</p>
854
-
855
- <div class="join mb-4" role="group">
856
- <button type="button" class="btn btn-outline btn-primary btn-sm join-item account-type-btn"
857
- data-type="normal" data-provider="gmail">
858
- Full access
859
- </button>
860
- <button type="button" class="btn btn-outline btn-primary btn-sm join-item account-type-btn"
861
- data-type="readonly" data-provider="gmail">
862
- Read-Only
863
- </button>
864
- <button type="button" class="btn btn-outline btn-primary btn-sm join-item account-type-btn"
865
- data-type="readonlysend" data-provider="gmail">
866
- Read-Only + Send
867
- </button>
868
- <button type="button" class="btn btn-outline btn-primary btn-sm join-item account-type-btn"
869
- data-type="sendonly" data-provider="gmail">
870
- Send-Only
871
- </button>
872
- </div>
873
-
874
- <div class="mt-2">
875
- <small class="text-base-content/60">
876
- <strong>Full access:</strong> Default Gmail API scopes for full mailbox access<br>
877
- <strong>Read-Only:</strong> Uses <code>gmail.readonly</code> scope for read-only access (no send)<br>
878
- <strong>Read-Only + Send:</strong> Uses <code>gmail.readonly</code> and <code>gmail.send</code>
879
- scopes<br>
880
- <strong>Send-Only:</strong> Uses <code>gmail.send</code> scope only. Does not require privileged scope
881
- approval from Google.
882
- </small>
883
- </div>
884
-
885
- <div class="alert alert-soft alert-info mt-4 mb-0 block">
886
- <p class="mb-2"><strong>Tip:</strong> Send-only accounts are useful when you only need to send emails and
887
- don't want to request privileged scopes that require Google verification.</p>
888
- <p class="mb-0"><strong>Important limitation:</strong> Messages sent through send-only accounts cannot be
889
- tracked by EmailEngine. The Gmail API modifies the Message-ID header when sending emails, and without
890
- read permissions, EmailEngine cannot resolve the new Message-ID assigned by Gmail. This means delivery
891
- status and bounce notifications may not be accurately associated with the sent message.</p>
892
- </div>
509
+ <div>
510
+ {{#> ui/form-field id="skipScopesList" label="Disabled scopes" error=errors.skipScopes}}
511
+ <textarea class="textarea w-full font-mono{{#if errors.skipScopes}} is-invalid{{/if}}" id="skipScopesList"
512
+ name="skipScopes" rows="5" spellcheck="false" data-enable-grammarly="false"
513
+ placeholder="One scope per line">{{values.skipScopes}}</textarea>
514
+ <span class="helper-text">Default scopes to leave out, such as
515
+ {{#if providerData.gmailApi}}<code>https://www.googleapis.com/auth/gmail.modify</code>{{else}}<code>SMTP.Send</code>{{/if}}.</span>
516
+ {{/ui/form-field}}
893
517
  </div>
894
518
  </div>
895
- {{/if}}
896
-
897
- {{#if activeOutlook}}
898
- <div class="card bg-base-100 shadow-md mb-6{{#unless baseScopesApi}} hidden{{/unless}}" id="account-type-card-outlook">
899
- <div class="card-header">
900
- <h6 class="card-title text-primary">Scope presets</h6>
901
- </div>
902
- <div class="card-body">
903
- <p class="mb-4">Choose a preset to fill in the scope fields below:</p>
904
-
905
- <div class="join mb-4" role="group">
906
- <button type="button" class="btn btn-outline btn-primary btn-sm join-item account-type-btn"
907
- data-type="normal" data-provider="outlook">
908
- Full access
909
- </button>
910
- <button type="button" class="btn btn-outline btn-primary btn-sm join-item account-type-btn"
911
- data-type="readonly" data-provider="outlook">
912
- Read-Only
913
- </button>
914
- <button type="button" class="btn btn-outline btn-primary btn-sm join-item account-type-btn"
915
- data-type="readonlysend" data-provider="outlook">
916
- Read-Only + Send
917
- </button>
918
- <button type="button" class="btn btn-outline btn-primary btn-sm join-item account-type-btn"
919
- data-type="sendonly" data-provider="outlook">
920
- Send-Only
921
- </button>
922
- </div>
923
-
924
- <div class="mt-2">
925
- <small class="text-base-content/60">
926
- <strong>Full access:</strong> Default MS Graph API scopes for full mailbox access<br>
927
- <strong>Read-Only:</strong> Uses <code>Mail.Read</code> scope for read-only access (no send)<br>
928
- <strong>Read-Only + Send:</strong> Uses <code>Mail.Read</code> with <code>Mail.Send</code> enabled<br>
929
- <strong>Send-Only:</strong> Uses <code>Mail.Send</code> scope only (disables
930
- <code>Mail.ReadWrite</code>)
931
- </small>
932
- </div>
933
- </div>
934
- </div>
935
- {{/if}}
936
-
937
- {{#> ui/details summary="Additional scopes" id="setupScopes" class="card bg-base-100 shadow-md mb-6"
938
- open=values.extraScopes}}
939
-
940
- <p class="mb-4">Request additional OAuth2 scopes, for example when your application uses the provider access tokens
941
- for services beyond email.</p>
942
-
943
- {{#if providerData.gmailApi}}
944
- <div class="alert alert-soft alert-info mb-4 block">
945
- <p>When adding new scopes, ensure that related APIs are
946
- enabled for your OAuth2 app (look for <em>Enabled APIs & services</em> in <a
947
- href="https://console.cloud.google.com/apis/dashboard" target="_blank" rel="noopener noreferrer"
948
- referrerpolicy="no-referrer" class="link link-animated">Google Cloud Console</a>)
949
- before registering accounts with these permissions. Otherwise, token generation will fail.</p>
950
- </div>
951
- {{/if}}
952
-
953
- {{#if activeOutlook}}
954
- <div class="alert alert-soft alert-info mb-4"><span>
955
-
956
- {{#if baseScopesImap}}
957
- All scopes must come exclusively from <code>https://outlook.office.com/</code>; scopes from
958
- <code>https://graph.microsoft.com/</code> are not allowed.
959
- {{/if}}
960
-
961
- {{#if baseScopesApi}}
962
- All scopes must come exclusively from <code>https://graph.microsoft.com/</code>; scopes from
963
- <code>https://outlook.office.com/</code> are not allowed.
964
- {{/if}}
965
-
966
- You cannot mix APIs from different endpoints within a single application.
967
-
968
- </span>
969
- </div>
970
- {{/if}}
971
-
972
- <div>
973
- {{#> ui/form-field id="extraScopes" label="List of OAuth2 scopes" error=errors.extraScopes}}
974
- <textarea class="textarea w-full font-mono{{#if errors.extraScopes}} is-invalid{{/if}}" id="extraScopes"
975
- name="extraScopes" rows="5" spellcheck="false" data-enable-grammarly="false"
976
- placeholder="Scope identifiers like &quot;https://mail.google.com/&quot;&mldr;">{{values.extraScopes}}</textarea>
977
- <span class="helper-text">Enter one scope per line.</span>
978
- {{/ui/form-field}}
979
- </div>
980
-
981
- {{/ui/details}}
982
-
983
- {{#> ui/details summary="Disabled scopes" id="skipScopes" class="card bg-base-100 shadow-md mb-6"
984
- open=values.skipScopes}}
985
-
986
- <p class="mb-4">Exclude default OAuth2 scopes that your integration does not need, such as <code>"SMTP.Send"</code> in Outlook or
987
- <code>"https://www.googleapis.com/auth/gmail.modify"</code> in Gmail.
988
- </p>
989
-
990
- <div>
991
- {{#> ui/form-field id="skipScopesList" label="List of disabled OAuth2 scopes" error=errors.skipScopes}}
992
- <textarea class="textarea w-full font-mono{{#if errors.skipScopes}} is-invalid{{/if}}" id="skipScopesList"
993
- name="skipScopes" rows="5" spellcheck="false" data-enable-grammarly="false"
994
- placeholder="Scope identifiers like &quot;SMTP.Send&quot;&mldr;">{{values.skipScopes}}</textarea>
995
- <span class="helper-text">Enter one scope per line.</span>
996
- {{/ui/form-field}}
997
- </div>
998
-
999
519
  {{/ui/details}}
1000
520
 
1001
521
  <script data-cfasync="false" nonce="{{cspNonce}}">
@@ -1006,12 +526,8 @@ open=values.skipScopes}}
1006
526
  const pubSubAppElm = document.getElementById('pubSubApp');
1007
527
 
1008
528
  /**
1009
- * Shows the configuration sections that belong to the selected base scope.
1010
- *
1011
- * Each toggled section declares the value that reveals it with `data-base-scopes`, rather than
1012
- * being looked up by element id: a service-account app offers both `api` and `pubsub` and so
1013
- * carries two of them in one block, which two hardcoded id lookups could not express - they
1014
- * both reached for the same element and fought over it.
529
+ * Shows the panel whose data-base-scopes matches the selected base scope, and disables the
530
+ * Pub/Sub selector while its panel is hidden.
1015
531
  */
1016
532
  function checkScopesRadio() {
1017
533
  let selected = document.querySelector('.base-scopes-radio:checked');
@@ -1039,15 +555,10 @@ open=values.skipScopes}}
1039
555
  pubSubAppElm.disabled = !shownElm || !shownElm.contains(pubSubAppElm);
1040
556
  }
1041
557
 
1042
- // The account type card describes what an API-based app can do with an account
1043
- document.querySelectorAll('#account-type-card-gmail, #account-type-card-outlook').forEach(cardElm => {
1044
- cardElm.classList.toggle('hidden', selected.value !== 'api');
1045
- });
1046
558
  }
1047
559
 
1048
560
  document.querySelectorAll('.base-scopes-radio').forEach(radioElm => {
1049
561
  radioElm.addEventListener('change', checkScopesRadio);
1050
- radioElm.addEventListener('click', checkScopesRadio);
1051
562
  });
1052
563
 
1053
564
  checkScopesRadio();
@@ -1078,8 +589,7 @@ open=values.skipScopes}}
1078
589
  }
1079
590
 
1080
591
  if (projectIdElm && pubSubAppElm) {
1081
- projectIdElm.addEventListener('click', filterPubSubApps)
1082
- projectIdElm.addEventListener('change', filterPubSubApps)
592
+ projectIdElm.addEventListener('input', filterPubSubApps)
1083
593
  filterPubSubApps()
1084
594
  }
1085
595
 
@@ -1109,7 +619,10 @@ open=values.skipScopes}}
1109
619
  }
1110
620
 
1111
621
  document.getElementById('clientId').value = data.web.client_id;
1112
- document.getElementById('clientSecret').value = data.web.client_secret;
622
+ let clientSecretElm = document.getElementById('clientSecret');
623
+ clientSecretElm.value = data.web.client_secret;
624
+ // ui/secret-field enables its reveal and copy buttons on input, which a script write does not fire
625
+ clientSecretElm.dispatchEvent(new Event('input', { bubbles: true }));
1113
626
 
1114
627
  document.getElementById('googleProjectId').value = data.web.project_id || '';
1115
628
 
@@ -1129,39 +642,26 @@ open=values.skipScopes}}
1129
642
  });
1130
643
  }
1131
644
 
1132
- let authorityElms = document.querySelectorAll('.r-auth');
645
+ // The tenant ID applies to the single-tenant choice only, so it is shown, required and submitted
646
+ // only while that choice is selected
647
+ let authorityElm = document.querySelector('select#authority');
648
+ let tenantFieldElm = document.getElementById('tenant-field');
1133
649
  let tenantElm = document.getElementById('tenant');
1134
- let checkAuthorityState = () => {
1135
- if (!tenantElm) {
1136
- return
1137
- }
1138
-
1139
- let showtenant = false;
1140
- for (let aElm of authorityElms) {
1141
- if (aElm.checked) {
1142
- if (aElm.value === 'tenant') {
1143
- showtenant = true
1144
- }
1145
- break;
1146
- }
1147
- }
1148
- tenantElm.disabled = !showtenant;
1149
- tenantElm.required = showtenant;
1150
- }
1151
-
1152
- for (let aElm of authorityElms) {
1153
- aElm.addEventListener('click', checkAuthorityState)
1154
- aElm.addEventListener('change', checkAuthorityState)
650
+ if (authorityElm && tenantFieldElm && tenantElm) {
651
+ let checkAuthorityState = () => {
652
+ let single = authorityElm.value === 'tenant';
653
+ tenantFieldElm.classList.toggle('hidden', !single);
654
+ tenantElm.disabled = !single;
655
+ tenantElm.required = single;
656
+ };
657
+ authorityElm.addEventListener('change', checkAuthorityState);
658
+ checkAuthorityState();
1155
659
  }
1156
660
 
1157
- checkAuthorityState();
1158
-
1159
- // Account type helper for API mode
1160
661
  const accountTypeButtons = document.querySelectorAll('.account-type-btn');
1161
662
  const extraScopesElm = document.querySelector('textarea#extraScopes');
1162
663
  const skipScopesElm = document.querySelector('textarea[name="skipScopes"]');
1163
- const setupScopesCard = document.getElementById('setupScopes');
1164
- const skipScopesCard = document.getElementById('skipScopes');
664
+ const customScopesCard = document.getElementById('setupScopes');
1165
665
 
1166
666
  // Scope configurations
1167
667
  const scopeConfigs = {
@@ -1222,7 +722,6 @@ open=values.skipScopes}}
1222
722
  return;
1223
723
  }
1224
724
 
1225
- // Get the appropriate config
1226
725
  let config = scopeConfigs[provider] && scopeConfigs[provider][type];
1227
726
 
1228
727
  if (!config) {
@@ -1249,35 +748,22 @@ open=values.skipScopes}}
1249
748
  extraScopesElm.value = newExtraScopes.join('\n');
1250
749
  skipScopesElm.value = newSkipScopes.join('\n');
1251
750
 
1252
- // Expand/collapse the native details sections based on content
1253
- setupScopesCard.open = newExtraScopes.length > 0;
1254
- skipScopesCard.open = newSkipScopes.length > 0;
751
+ // Expand the custom scopes card when the preset left anything in it
752
+ customScopesCard.open = newExtraScopes.length > 0 || newSkipScopes.length > 0;
1255
753
  }
1256
754
 
1257
- // Define which scopes are managed by the helper buttons
1258
- const managedScopes = {
1259
- gmail: {
1260
- extra: [
1261
- 'https://www.googleapis.com/auth/gmail.readonly',
1262
- 'https://www.googleapis.com/auth/gmail.send',
1263
- 'https://www.googleapis.com/auth/gmail.labels'
1264
- ],
1265
- skip: [
1266
- 'https://www.googleapis.com/auth/gmail.modify'
1267
- ]
1268
- },
1269
- outlook: {
1270
- extra: [
1271
- 'Mail.Read'
1272
- ],
1273
- skip: [
1274
- 'Mail.ReadWrite',
1275
- 'Mail.Send'
1276
- ]
1277
- }
1278
- };
755
+ // The scopes the preset buttons own: every scope any preset adds or skips. Derived from the presets
756
+ // so a scope added to one cannot be left behind when another preset replaces it
757
+ const managedScopes = Object.fromEntries(
758
+ Object.entries(scopeConfigs).map(([provider, presets]) => [
759
+ provider,
760
+ {
761
+ extra: [...new Set(Object.values(presets).flatMap(preset => preset.extraScopes))],
762
+ skip: [...new Set(Object.values(presets).flatMap(preset => preset.skipScopes))]
763
+ }
764
+ ])
765
+ );
1279
766
 
1280
- // Attach event listeners to buttons
1281
767
  for (let btn of accountTypeButtons) {
1282
768
  btn.addEventListener('click', function () {
1283
769
  const provider = this.getAttribute('data-provider');
@@ -1287,7 +773,7 @@ open=values.skipScopes}}
1287
773
  }
1288
774
 
1289
775
  // Shared by the new/edit pages: gmailService credential-file loaders
1290
- // and the auth-method tab switcher (all target markup in this partial)
776
+ // and the auth-method strip (all target markup in this partial)
1291
777
 
1292
778
  let serviceFileElm = document.getElementById('serviceFile');
1293
779
  if (serviceFileElm) {
@@ -1345,7 +831,7 @@ open=values.skipScopes}}
1345
831
 
1346
832
  if (data.type !== 'external_account') {
1347
833
  if (data.type === 'service_account') {
1348
- return showToast('This is a service account key file, not a Workload Identity Federation config. Switch to the "Service account key" tab to load it.', 'alert-triangle');
834
+ return showToast('This is a service account key file, not a Workload Identity Federation config. Choose the "Service account key" tab to load it.', 'alert-triangle');
1349
835
  }
1350
836
  return showToast(`Selected file is not an external_account credential config (type: ${data.type || 'missing'})`, 'alert-triangle');
1351
837
  }
@@ -1369,10 +855,21 @@ open=values.skipScopes}}
1369
855
  });
1370
856
  }
1371
857
 
1372
- let authMethodTabs = document.querySelectorAll('.auth-method-tab');
1373
- let authMethodInput = document.getElementById('authMethod');
1374
- if (authMethodTabs.length && authMethodInput) {
1375
- let updateSections = selected => {
858
+ let authMethodRadios = document.querySelectorAll('.auth-method-radio');
859
+ if (authMethodRadios.length) {
860
+ let noticeElm = document.getElementById('authMethodNotice');
861
+ let scopeBadgeElm = document.getElementById('authMethodScopeBadge');
862
+ let pubsubScopeElm = document.getElementById('baseScopesPubsub');
863
+
864
+ let showNotice = text => {
865
+ noticeElm.textContent = text;
866
+ noticeElm.classList.toggle('hidden', !text);
867
+ };
868
+
869
+ let selectedMethod = () => document.querySelector('.auth-method-radio:checked').value;
870
+
871
+ let updateSections = () => {
872
+ let selected = selectedMethod();
1376
873
  document.querySelectorAll('.auth-method-section').forEach(section => {
1377
874
  let active = section.classList.contains('auth-method-section-' + selected);
1378
875
  section.classList.toggle('hidden', !active);
@@ -1382,51 +879,52 @@ open=values.skipScopes}}
1382
879
  });
1383
880
  });
1384
881
  };
1385
- let selectTab = tab => {
1386
- let selected = tab.getAttribute('data-auth-method');
1387
- authMethodTabs.forEach(other => {
1388
- let isActive = other === tab;
1389
- other.classList.toggle('tab-active', isActive);
1390
- other.setAttribute('aria-selected', isActive ? 'true' : 'false');
1391
- });
1392
- authMethodInput.value = selected;
1393
- updateSections(selected);
882
+
883
+ let selectedScope = () => {
884
+ let scopeElm = document.querySelector('.base-scopes-radio:checked');
885
+ return scopeElm && scopeElm.value;
1394
886
  };
1395
- authMethodTabs.forEach(tab => {
1396
- tab.addEventListener('click', e => {
1397
- e.preventDefault();
1398
- if (tab.classList.contains('disabled') || tab.classList.contains('tab-active')) {
1399
- return;
887
+
888
+ authMethodRadios.forEach(radioElm => {
889
+ radioElm.addEventListener('change', () => {
890
+ showNotice('');
891
+ updateSections();
892
+
893
+ // The attached service account only works for a Pub/Sub app, so choosing it chooses
894
+ // that base scope too, and says so: the base scope card is above, likely out of view
895
+ if (radioElm.value === 'metadataServer' && pubsubScopeElm && selectedScope() !== 'pubsub') {
896
+ pubsubScopeElm.checked = true;
897
+ pubsubScopeElm.dispatchEvent(new Event('change', { bubbles: true }));
898
+ showNotice('The attached service account works only for Cloud Pub/Sub apps, so the base scope was set to Cloud Pub/Sub.');
1400
899
  }
1401
- selectTab(tab);
1402
900
  });
1403
901
  });
1404
- // the rendered selection, so a re-rendered form disables the sections it hides from the start
1405
- updateSections(authMethodInput.value);
1406
902
 
1407
- // A method tied to a base scope (the attached service account, Pub/Sub only) is offered
1408
- // while that scope is selected. Switching away from it while its tab is active falls back
1409
- // to the key tab, so the form never submits a method the schema refuses for the scope
1410
- let scopedTabs = document.querySelectorAll('.auth-method-tab[data-auth-method-scope]');
1411
- let checkScopedTabs = () => {
1412
- let scopeElm = document.querySelector('.base-scopes-radio:checked');
1413
- if (!scopeElm) {
903
+ // Leaving Pub/Sub while the attached service account is selected falls back to the key, and
904
+ // says so, because the form must never submit a method the schema refuses for the scope
905
+ let checkScopedMethod = () => {
906
+ let scope = selectedScope();
907
+ if (!scope) {
1414
908
  return;
1415
909
  }
1416
- scopedTabs.forEach(tab => {
1417
- let offered = tab.getAttribute('data-auth-method-scope') === scopeElm.value;
1418
- tab.classList.toggle('hidden', !offered);
1419
- if (!offered && tab.classList.contains('tab-active')) {
1420
- selectTab(document.getElementById('auth-method-tab-serviceKey'));
1421
- }
1422
- });
910
+ let offered = scope === 'pubsub';
911
+ if (scopeBadgeElm) {
912
+ scopeBadgeElm.classList.toggle('hidden', offered);
913
+ }
914
+ if (!offered && selectedMethod() === 'metadataServer') {
915
+ document.getElementById('authMethodServiceKey').checked = true;
916
+ updateSections();
917
+ showNotice('The attached service account works only for Cloud Pub/Sub apps, so the method was switched to Service account key.');
918
+ }
1423
919
  };
1424
- if (scopedTabs.length) {
1425
- document.querySelectorAll('.base-scopes-radio').forEach(radioElm => {
1426
- radioElm.addEventListener('change', checkScopedTabs);
1427
- });
1428
- checkScopedTabs();
1429
- }
920
+
921
+ document.querySelectorAll('.base-scopes-radio').forEach(radioElm => {
922
+ radioElm.addEventListener('change', checkScopedMethod);
923
+ });
924
+
925
+ checkScopedMethod();
926
+ // the rendered selection, so a re-rendered form disables the sections it hides from the start
927
+ updateSections();
1430
928
  }
1431
929
 
1432
930
  let metadataProbeElm = document.getElementById('metadataProbe');