Skip to content

Commit 978d0b0

Browse files
feat: todoist oauth configuration (#327)
1 parent 3145fe7 commit 978d0b0

3 files changed

Lines changed: 63 additions & 0 deletions

File tree

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import axios from 'axios';
2+
import qs from 'qs';
3+
import { DataObject, OAuthResponse } from '../../lib/types';
4+
5+
export const init = async ({ body }: DataObject): Promise<OAuthResponse> => {
6+
try {
7+
const {
8+
clientId: client_id,
9+
clientSecret: client_secret,
10+
metadata: { code, redirectUri: redirect_uri },
11+
} = body;
12+
13+
const requestBody = {
14+
code,
15+
client_id,
16+
client_secret,
17+
redirect_uri,
18+
};
19+
20+
const response = await axios({
21+
url: 'https://todoist.com/oauth/access_token',
22+
method: 'POST',
23+
headers: {
24+
'Content-Type': 'application/x-www-form-urlencoded',
25+
Accept: 'application/json',
26+
},
27+
data: qs.stringify(requestBody),
28+
});
29+
30+
const { access_token: accessToken, token_type: tokenType } =
31+
response.data;
32+
33+
return {
34+
accessToken,
35+
refreshToken: accessToken,
36+
expiresIn: 2147483647,
37+
tokenType: tokenType === 'bearer' ? 'Bearer' : tokenType,
38+
meta: {},
39+
};
40+
} catch (error) {
41+
throw new Error(`Error fetching access token for Todoist: ${error}`);
42+
}
43+
};
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { DataObject, OAuthResponse } from '../../lib/types';
2+
3+
export const refresh = async ({ body }: DataObject): Promise<OAuthResponse> => {
4+
try {
5+
const {
6+
OAUTH_METADATA: { accessToken, refreshToken, tokenType, meta },
7+
} = body;
8+
9+
return {
10+
accessToken,
11+
refreshToken,
12+
expiresIn: 2147483647,
13+
tokenType,
14+
meta,
15+
};
16+
} catch (error) {
17+
throw new Error(`Error fetching access token for Todoist: ${error}`);
18+
}
19+
};

oauth/src/connections/zendesk/refresh.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ export const refresh = async ({ body }: DataObject): Promise<OAuthResponse> => {
55
const {
66
OAUTH_METADATA: { accessToken, refreshToken, tokenType, meta },
77
} = body;
8+
89
return {
910
accessToken,
1011
refreshToken,

0 commit comments

Comments
 (0)