feat(asana): add asana integration
This commit is contained in:
37
packages/backend/src/apps/asana/auth/refresh-token.js
Normal file
37
packages/backend/src/apps/asana/auth/refresh-token.js
Normal file
@@ -0,0 +1,37 @@
|
||||
import { URLSearchParams } from 'node:url';
|
||||
|
||||
const refreshToken = async ($) => {
|
||||
const oauthRedirectUrlField = $.app.auth.fields.find(
|
||||
(field) => field.key == 'oAuthRedirectUrl'
|
||||
);
|
||||
const redirectUri = oauthRedirectUrlField.value;
|
||||
|
||||
const params = new URLSearchParams({
|
||||
client_id: $.auth.data.clientId,
|
||||
client_secret: $.auth.data.clientSecret,
|
||||
redirect_uri: redirectUri,
|
||||
grant_type: 'refresh_token',
|
||||
refresh_token: $.auth.data.refreshToken,
|
||||
});
|
||||
|
||||
const { data } = await $.http.post(
|
||||
'https://app.asana.com/-/oauth_token',
|
||||
params.toString(),
|
||||
{
|
||||
headers: {
|
||||
'Content-Type': 'application/x-www-form-urlencoded',
|
||||
},
|
||||
additionalProperties: {
|
||||
skipAddingAuthHeader: true,
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
await $.auth.set({
|
||||
accessToken: data.access_token,
|
||||
expiresIn: data.expires_in,
|
||||
tokenType: data.token_type,
|
||||
});
|
||||
};
|
||||
|
||||
export default refreshToken;
|
Reference in New Issue
Block a user