Compare commits
1 Commits
dependabot
...
gmail-inte
Author | SHA1 | Date | |
---|---|---|---|
![]() |
b594a8e0f3 |
11
packages/backend/src/apps/gmail/assets/favicon.svg
Normal file
11
packages/backend/src/apps/gmail/assets/favicon.svg
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 49.4 512 399.42">
|
||||||
|
<g fill="none" fill-rule="evenodd">
|
||||||
|
<g fill-rule="nonzero">
|
||||||
|
<path fill="#4285f4" d="M34.91 448.818h81.454V251L0 163.727V413.91c0 19.287 15.622 34.91 34.91 34.91z"/>
|
||||||
|
<path fill="#34a853" d="M395.636 448.818h81.455c19.287 0 34.909-15.622 34.909-34.909V163.727L395.636 251z"/>
|
||||||
|
<path fill="#fbbc04" d="M395.636 99.727V251L512 163.727v-46.545c0-43.142-49.25-67.782-83.782-41.891z"/>
|
||||||
|
</g>
|
||||||
|
<path fill="#ea4335" d="M116.364 251V99.727L256 204.455 395.636 99.727V251L256 355.727z"/>
|
||||||
|
<path fill="#c5221f" fill-rule="nonzero" d="M0 117.182v46.545L116.364 251V99.727L83.782 75.291C49.25 49.4 0 74.04 0 117.18z"/>
|
||||||
|
</g>
|
||||||
|
</svg>
|
After Width: | Height: | Size: 720 B |
23
packages/backend/src/apps/gmail/auth/generate-auth-url.js
Normal file
23
packages/backend/src/apps/gmail/auth/generate-auth-url.js
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
import { URLSearchParams } from 'url';
|
||||||
|
import authScope from '../common/auth-scope.js';
|
||||||
|
|
||||||
|
export default async function generateAuthUrl($) {
|
||||||
|
const oauthRedirectUrlField = $.app.auth.fields.find(
|
||||||
|
(field) => field.key == 'oAuthRedirectUrl'
|
||||||
|
);
|
||||||
|
const redirectUri = oauthRedirectUrlField.value;
|
||||||
|
const searchParams = new URLSearchParams({
|
||||||
|
client_id: $.auth.data.clientId,
|
||||||
|
redirect_uri: redirectUri,
|
||||||
|
prompt: 'select_account',
|
||||||
|
scope: authScope.join(' '),
|
||||||
|
response_type: 'code',
|
||||||
|
access_type: 'offline',
|
||||||
|
});
|
||||||
|
|
||||||
|
const url = `https://accounts.google.com/o/oauth2/v2/auth?${searchParams.toString()}`;
|
||||||
|
|
||||||
|
await $.auth.set({
|
||||||
|
url,
|
||||||
|
});
|
||||||
|
}
|
48
packages/backend/src/apps/gmail/auth/index.js
Normal file
48
packages/backend/src/apps/gmail/auth/index.js
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
import generateAuthUrl from './generate-auth-url.js';
|
||||||
|
import verifyCredentials from './verify-credentials.js';
|
||||||
|
import refreshToken from './refresh-token.js';
|
||||||
|
import isStillVerified from './is-still-verified.js';
|
||||||
|
|
||||||
|
export default {
|
||||||
|
fields: [
|
||||||
|
{
|
||||||
|
key: 'oAuthRedirectUrl',
|
||||||
|
label: 'OAuth Redirect URL',
|
||||||
|
type: 'string',
|
||||||
|
required: true,
|
||||||
|
readOnly: true,
|
||||||
|
value: '{WEB_APP_URL}/app/gmail/connections/add',
|
||||||
|
placeholder: null,
|
||||||
|
description:
|
||||||
|
'When asked to input a redirect URL in Google Cloud, enter the URL above.',
|
||||||
|
clickToCopy: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: 'clientId',
|
||||||
|
label: 'Client ID',
|
||||||
|
type: 'string',
|
||||||
|
required: true,
|
||||||
|
readOnly: false,
|
||||||
|
value: null,
|
||||||
|
placeholder: null,
|
||||||
|
description: null,
|
||||||
|
clickToCopy: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: 'clientSecret',
|
||||||
|
label: 'Client Secret',
|
||||||
|
type: 'string',
|
||||||
|
required: true,
|
||||||
|
readOnly: false,
|
||||||
|
value: null,
|
||||||
|
placeholder: null,
|
||||||
|
description: null,
|
||||||
|
clickToCopy: false,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
|
||||||
|
generateAuthUrl,
|
||||||
|
verifyCredentials,
|
||||||
|
isStillVerified,
|
||||||
|
refreshToken,
|
||||||
|
};
|
@@ -0,0 +1,8 @@
|
|||||||
|
import getCurrentUser from '../common/get-current-user.js';
|
||||||
|
|
||||||
|
const isStillVerified = async ($) => {
|
||||||
|
const currentUser = await getCurrentUser($);
|
||||||
|
return !!currentUser.resourceName;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default isStillVerified;
|
26
packages/backend/src/apps/gmail/auth/refresh-token.js
Normal file
26
packages/backend/src/apps/gmail/auth/refresh-token.js
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
import { URLSearchParams } from 'node:url';
|
||||||
|
|
||||||
|
import authScope from '../common/auth-scope.js';
|
||||||
|
|
||||||
|
const refreshToken = async ($) => {
|
||||||
|
const params = new URLSearchParams({
|
||||||
|
client_id: $.auth.data.clientId,
|
||||||
|
client_secret: $.auth.data.clientSecret,
|
||||||
|
grant_type: 'refresh_token',
|
||||||
|
refresh_token: $.auth.data.refreshToken,
|
||||||
|
});
|
||||||
|
|
||||||
|
const { data } = await $.http.post(
|
||||||
|
'https://oauth2.googleapis.com/token',
|
||||||
|
params.toString()
|
||||||
|
);
|
||||||
|
|
||||||
|
await $.auth.set({
|
||||||
|
accessToken: data.access_token,
|
||||||
|
expiresIn: data.expires_in,
|
||||||
|
scope: authScope.join(' '),
|
||||||
|
tokenType: data.token_type,
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
export default refreshToken;
|
42
packages/backend/src/apps/gmail/auth/verify-credentials.js
Normal file
42
packages/backend/src/apps/gmail/auth/verify-credentials.js
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
import getCurrentUser from '../common/get-current-user.js';
|
||||||
|
|
||||||
|
const verifyCredentials = async ($) => {
|
||||||
|
const oauthRedirectUrlField = $.app.auth.fields.find(
|
||||||
|
(field) => field.key == 'oAuthRedirectUrl'
|
||||||
|
);
|
||||||
|
const redirectUri = oauthRedirectUrlField.value;
|
||||||
|
const { data } = await $.http.post(`https://oauth2.googleapis.com/token`, {
|
||||||
|
client_id: $.auth.data.clientId,
|
||||||
|
client_secret: $.auth.data.clientSecret,
|
||||||
|
code: $.auth.data.code,
|
||||||
|
grant_type: 'authorization_code',
|
||||||
|
redirect_uri: redirectUri,
|
||||||
|
});
|
||||||
|
|
||||||
|
await $.auth.set({
|
||||||
|
accessToken: data.access_token,
|
||||||
|
tokenType: data.token_type,
|
||||||
|
});
|
||||||
|
|
||||||
|
const currentUser = await getCurrentUser($);
|
||||||
|
|
||||||
|
const { displayName } = currentUser.names.find(
|
||||||
|
(name) => name.metadata.primary
|
||||||
|
);
|
||||||
|
const { value: email } = currentUser.emailAddresses.find(
|
||||||
|
(emailAddress) => emailAddress.metadata.primary
|
||||||
|
);
|
||||||
|
|
||||||
|
await $.auth.set({
|
||||||
|
clientId: $.auth.data.clientId,
|
||||||
|
clientSecret: $.auth.data.clientSecret,
|
||||||
|
scope: $.auth.data.scope,
|
||||||
|
idToken: data.id_token,
|
||||||
|
expiresIn: data.expires_in,
|
||||||
|
refreshToken: data.refresh_token,
|
||||||
|
resourceName: currentUser.resourceName,
|
||||||
|
screenName: `${displayName} - ${email}`,
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
export default verifyCredentials;
|
@@ -0,0 +1,9 @@
|
|||||||
|
const addAuthHeader = ($, requestConfig) => {
|
||||||
|
if ($.auth.data?.accessToken) {
|
||||||
|
requestConfig.headers.Authorization = `${$.auth.data.tokenType} ${$.auth.data.accessToken}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
return requestConfig;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default addAuthHeader;
|
8
packages/backend/src/apps/gmail/common/auth-scope.js
Normal file
8
packages/backend/src/apps/gmail/common/auth-scope.js
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
const authScope = [
|
||||||
|
'https://www.googleapis.com/auth/gmail.compose',
|
||||||
|
'https://www.googleapis.com/auth/gmail.modify',
|
||||||
|
'https://www.googleapis.com/auth/userinfo.email',
|
||||||
|
'https://www.googleapis.com/auth/userinfo.profile',
|
||||||
|
];
|
||||||
|
|
||||||
|
export default authScope;
|
@@ -0,0 +1,8 @@
|
|||||||
|
const getCurrentUser = async ($) => {
|
||||||
|
const { data: currentUser } = await $.http.get(
|
||||||
|
'https://people.googleapis.com/v1/people/me?personFields=names,emailAddresses'
|
||||||
|
);
|
||||||
|
return currentUser;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default getCurrentUser;
|
15
packages/backend/src/apps/gmail/index.js
Normal file
15
packages/backend/src/apps/gmail/index.js
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
import defineApp from '../../helpers/define-app.js';
|
||||||
|
import addAuthHeader from './common/add-auth-header.js';
|
||||||
|
import auth from './auth/index.js';
|
||||||
|
export default defineApp({
|
||||||
|
name: 'Gmail',
|
||||||
|
key: 'gmail',
|
||||||
|
baseUrl: 'https://mail.google.com',
|
||||||
|
apiBaseUrl: 'https://gmail.googleapis.com',
|
||||||
|
iconUrl: '{BASE_URL}/apps/gmail/assets/favicon.svg',
|
||||||
|
authDocUrl: 'https://automatisch.io/docs/apps/gmail/connection',
|
||||||
|
primaryColor: 'ea4335',
|
||||||
|
supportsConnections: true,
|
||||||
|
beforeRequest: [addAuthHeader],
|
||||||
|
auth,
|
||||||
|
});
|
@@ -141,6 +141,12 @@ export default defineConfig({
|
|||||||
{ text: 'Connection', link: '/apps/gitlab/connection' },
|
{ text: 'Connection', link: '/apps/gitlab/connection' },
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
text: 'Gmail',
|
||||||
|
collapsible: true,
|
||||||
|
collapsed: true,
|
||||||
|
items: [{ text: 'Connection', link: '/apps/gmail/connection' }],
|
||||||
|
},
|
||||||
{
|
{
|
||||||
text: 'Google Calendar',
|
text: 'Google Calendar',
|
||||||
collapsible: true,
|
collapsible: true,
|
||||||
|
28
packages/docs/pages/apps/gmail/connection.md
Normal file
28
packages/docs/pages/apps/gmail/connection.md
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
# Gmail
|
||||||
|
|
||||||
|
:::info
|
||||||
|
This page explains the steps you need to follow to set up the Gmail
|
||||||
|
connection in Automatisch. If any of the steps are outdated, please let us know!
|
||||||
|
:::
|
||||||
|
|
||||||
|
1. Go to the [Google Cloud Console](https://console.cloud.google.com) to create a project.
|
||||||
|
2. Click on the project drop-down menu at the top of the page, and click on the **New Project** button.
|
||||||
|
3. Enter a name for your project and click on the **Create** button.
|
||||||
|
4. Go to [API Library](https://console.cloud.google.com/apis/library) in Google Cloud console.
|
||||||
|
5. Search for **People API** in the search bar and click on it.
|
||||||
|
6. Click on the **Enable** button to enable the API.
|
||||||
|
7. Repeat steps 5 and 6 for the **Gmail API**
|
||||||
|
8. Go to [OAuth consent screen](https://console.cloud.google.com/apis/credentials/consent) in Google Cloud console.
|
||||||
|
9. Select **External** here for starting your app in testing mode at first. Click on the **Create** button.
|
||||||
|
10. Fill **App Name**, **User Support Email**, and **Developer Contact Information**. Click on the **Save and Continue** button.
|
||||||
|
11. Skip adding or removing scopes and click on the **Save and Continue** button.
|
||||||
|
12. Click on the **Add Users** button and add a test email because only test users can access the app while publishing status is set to "Testing".
|
||||||
|
13. Click on the **Save and Continue** button and now you have configured the consent screen.
|
||||||
|
14. Go to [Credentials](https://console.cloud.google.com/apis/credentials) in Google Cloud console.
|
||||||
|
15. Click on the **Create Credentials** button and select the **OAuth client ID** option.
|
||||||
|
16. Select the application type as **Web application** and fill the **Name** field.
|
||||||
|
17. Copy **OAuth Redirect URL** from Automatisch to **Authorized redirect URIs** field, and click on the **Create** button.
|
||||||
|
18. Copy the **Your Client ID** value from the following popup to the `Client ID` field on Automatisch.
|
||||||
|
19. Copy the **Your Client Secret** value from the following popup to the `Client Secret` field on Automatisch.
|
||||||
|
20. Click **Submit** button on Automatisch.
|
||||||
|
21. Congrats! Start using your new Gmail connection within the flows.
|
11
packages/docs/pages/public/favicons/gmail.svg
Normal file
11
packages/docs/pages/public/favicons/gmail.svg
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 49.4 512 399.42">
|
||||||
|
<g fill="none" fill-rule="evenodd">
|
||||||
|
<g fill-rule="nonzero">
|
||||||
|
<path fill="#4285f4" d="M34.91 448.818h81.454V251L0 163.727V413.91c0 19.287 15.622 34.91 34.91 34.91z"/>
|
||||||
|
<path fill="#34a853" d="M395.636 448.818h81.455c19.287 0 34.909-15.622 34.909-34.909V163.727L395.636 251z"/>
|
||||||
|
<path fill="#fbbc04" d="M395.636 99.727V251L512 163.727v-46.545c0-43.142-49.25-67.782-83.782-41.891z"/>
|
||||||
|
</g>
|
||||||
|
<path fill="#ea4335" d="M116.364 251V99.727L256 204.455 395.636 99.727V251L256 355.727z"/>
|
||||||
|
<path fill="#c5221f" fill-rule="nonzero" d="M0 117.182v46.545L116.364 251V99.727L83.782 75.291C49.25 49.4 0 74.04 0 117.18z"/>
|
||||||
|
</g>
|
||||||
|
</svg>
|
After Width: | Height: | Size: 720 B |
Reference in New Issue
Block a user