Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions oauth/src/connections/asana/init.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import axios from 'axios';
import qs from 'qs';
import { DataObject, OAuthResponse } from '../../lib/types';

export const init = async ({ body }: DataObject): Promise<OAuthResponse> => {
try {
const {
clientId: client_id,
clientSecret: client_secret,
metadata: { code, redirectUri: redirect_uri },
} = body;

const requestBody = {
grant_type: 'authorization_code',
code,
client_id,
client_secret,
redirect_uri,
};

const response = await axios({
url: 'https://app.asana.com/-/oauth_token',
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
Accept: 'application/json',
},
data: qs.stringify(requestBody),
});

const {
access_token: accessToken,
refresh_token: refreshToken,
token_type: tokenType,
expires_in: expiresIn,
} = response.data;

return {
accessToken,
refreshToken,
expiresIn,
tokenType: tokenType === 'bearer' ? 'Bearer' : tokenType,
meta: {},
};
} catch (error) {
throw new Error(`Error fetching access token for Asana: ${error}`);
}
};
49 changes: 49 additions & 0 deletions oauth/src/connections/asana/refresh.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import axios from 'axios';
import qs from 'qs';
import { DataObject, OAuthResponse } from '../../lib/types';

export const refresh = async ({ body }: DataObject): Promise<OAuthResponse> => {
try {
const {
OAUTH_CLIENT_ID: client_id,
OAUTH_CLIENT_SECRET: client_secret,
OAUTH_REFRESH_TOKEN: refresh_token,
OAUTH_METADATA: { meta },
OAUTH_REQUEST_PAYLOAD: { redirectUri: redirect_uri },
} = body;

const requestBody = {
grant_type: 'refresh_token',
refresh_token,
client_id,
client_secret,
redirect_uri,
};

const response = await axios({
url: 'https://app.asana.com/-/oauth_token',
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
Accept: 'application/json',
},
data: qs.stringify(requestBody),
});

const {
access_token: accessToken,
token_type: tokenType,
expires_in: expiresIn,
} = response.data;

return {
accessToken,
refreshToken: refresh_token,
expiresIn,
tokenType: tokenType === 'bearer' ? 'Bearer' : tokenType,
meta,
};
} catch (error) {
throw new Error(`Error fetching access token for Asana: ${error}`);
}
};
41 changes: 41 additions & 0 deletions oauth/src/connections/jira/init.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import axios from 'axios';
import { DataObject, OAuthResponse } from '../../lib/types';

export const init = async ({ body }: DataObject): Promise<OAuthResponse> => {
try {
const {
clientId: client_id,
clientSecret: client_secret,
metadata: { code, redirectUri: redirect_uri },
} = body;

const response = await axios({
url: 'https://auth.atlassian.com/oauth/token',
method: 'POST',
params: {
grant_type: 'authorization_code',
code,
client_id,
client_secret,
redirect_uri,
},
});

const {
access_token: accessToken,
refresh_token: refreshToken,
token_type: tokenType,
expires_in: expiresIn,
} = response.data;

return {
accessToken,
refreshToken,
expiresIn,
tokenType: tokenType === 'bearer' ? 'Bearer' : tokenType,
meta: {},
};
} catch (error) {
throw new Error(`Error fetching access token for Jira: ${error}`);
}
};
41 changes: 41 additions & 0 deletions oauth/src/connections/jira/refresh.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import axios from 'axios';
import { DataObject, OAuthResponse } from '../../lib/types';

export const refresh = async ({ body }: DataObject): Promise<OAuthResponse> => {
try {
const {
OAUTH_CLIENT_ID: client_id,
OAUTH_CLIENT_SECRET: client_secret,
OAUTH_REFRESH_TOKEN: refresh_token,
OAUTH_METADATA: { meta },
} = body;

const response = await axios({
url: 'https://auth.atlassian.com/oauth/token',
method: 'POST',
params: {
grant_type: 'refresh_token',
refresh_token,
client_id,
client_secret,
},
});

const {
access_token: accessToken,
refresh_token: refreshToken,
token_type: tokenType,
expires_in: expiresIn,
} = response.data;

return {
accessToken,
refreshToken,
expiresIn,
tokenType: tokenType === 'bearer' ? 'Bearer' : tokenType,
meta,
};
} catch (error) {
throw new Error(`Error fetching access token for Jira: ${error}`);
}
};