-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added microsoft dynamics 365 sales oauth endpoints (#57)
- Loading branch information
1 parent
04903ff
commit 249acde
Showing
2 changed files
with
84 additions
and
0 deletions.
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
integrationos-platform-oauth/src/connections/microsoftDynamics365Sales/init.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import axios from "axios"; | ||
import qs from "qs"; | ||
import { DataObject, OAuthResponse } from "../../lib/types"; | ||
|
||
export const init = async ({ body }: DataObject): Promise<OAuthResponse> => { | ||
try { | ||
const requestBody = { | ||
grant_type: "client_credentials", | ||
client_id: body.clientId, | ||
client_secret: body.clientSecret, | ||
resource: body.metadata?.formData?.MICROSOFT_DYNAMICS_365_SALES_ORGANIZATION_URI, | ||
}; | ||
|
||
const response = await axios({ | ||
url: `https://login.windows.net/${body.metadata?.formData?.MICROSOFT_DYNAMICS_365_SALES_TENANT_ID}/oauth2/token`, | ||
method: "POST", | ||
headers: { "content-type": "application/x-www-form-urlencoded" }, | ||
data: qs.stringify(requestBody) | ||
}); | ||
|
||
const { | ||
data: { | ||
access_token, | ||
expires_in, | ||
token_type, | ||
resource, | ||
} | ||
} = response; | ||
|
||
return { | ||
accessToken: access_token, | ||
refreshToken: "", | ||
expiresIn: +expires_in, | ||
tokenType: token_type, | ||
meta: { | ||
resource, | ||
} | ||
}; | ||
} catch (error) { | ||
throw new Error(`Error fetching access token for Microsoft Dynamics 365 Sales: ${error}`); | ||
} | ||
}; |
42 changes: 42 additions & 0 deletions
42
integrationos-platform-oauth/src/connections/microsoftDynamics365Sales/refresh.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import axios from "axios"; | ||
import qs from "qs"; | ||
import { DataObject, OAuthResponse } from "../../lib/types"; | ||
|
||
export const refresh = async ({ body }: DataObject): Promise<OAuthResponse> => { | ||
try { | ||
const requestBody = { | ||
grant_type: "client_credentials", | ||
client_id: body.clientId, | ||
client_secret: body.clientSecret, | ||
resource: body.metadata?.formData?.MICROSOFT_DYNAMICS_365_SALES_ORGANIZATION_URI, | ||
}; | ||
|
||
const response = await axios({ | ||
url: `https://login.windows.net/${body.metadata?.formData?.MICROSOFT_DYNAMICS_365_SALES_TENANT_ID}/oauth2/token`, | ||
method: "POST", | ||
headers: { "content-type": "application/x-www-form-urlencoded" }, | ||
data: qs.stringify(requestBody) | ||
}); | ||
|
||
const { | ||
data: { | ||
access_token, | ||
expires_in, | ||
token_type, | ||
resource, | ||
} | ||
} = response; | ||
|
||
return { | ||
accessToken: access_token, | ||
refreshToken: "", | ||
expiresIn: +expires_in, | ||
tokenType: token_type, | ||
meta: { | ||
resource, | ||
} | ||
}; | ||
} catch (error) { | ||
throw new Error(`Error fetching refresh token for Microsoft Dynamics 365 Sales: ${error}`); | ||
} | ||
}; |