-
Notifications
You must be signed in to change notification settings - Fork 7
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 business central oauth endpoints
- Loading branch information
1 parent
4c49803
commit ba45718
Showing
2 changed files
with
79 additions
and
0 deletions.
There are no files selected for viewing
37 changes: 37 additions & 0 deletions
37
integrationos-platform-oauth/src/connections/microsoftDynamics365BusinessCentral/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,37 @@ | ||
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, | ||
scope: "https://api.businesscentral.dynamics.com/.default", | ||
}; | ||
|
||
const response = await axios({ | ||
url: `https://login.microsoftonline.com/${body.metadata?.formData?.BUSINESS_CENTRAL_TENANT_ID}/oauth2/v2.0/token`, | ||
method: "POST", | ||
headers: { "Content-Type": "application/x-www-form-urlencoded" }, | ||
data: qs.stringify(requestBody), | ||
}); | ||
|
||
const { | ||
data: { access_token, expires_in, token_type }, | ||
} = response; | ||
|
||
return { | ||
accessToken: access_token, | ||
refreshToken: "", | ||
expiresIn: +expires_in, | ||
tokenType: token_type, | ||
meta: {}, | ||
}; | ||
} catch (error) { | ||
throw new Error( | ||
`Error fetching access token for Microsoft Dynamics 365 Business Central: ${error}` | ||
); | ||
} | ||
}; |
42 changes: 42 additions & 0 deletions
42
integrationos-platform-oauth/src/connections/microsoftDynamics365BusinessCentral/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 { | ||
OAUTH_CLIENT_ID: client_id, | ||
OAUTH_CLIENT_SECRET: client_secret, | ||
OAUTH_REQUEST_PAYLOAD: { formData }, | ||
} = body; | ||
const requestBody = { | ||
grant_type: "client_credentials", | ||
client_id, | ||
client_secret, | ||
scope: "https://api.businesscentral.dynamics.com/.default", | ||
}; | ||
|
||
const response = await axios({ | ||
url: `https://login.microsoftonline.com/${formData?.BUSINESS_CENTRAL_TENANT_ID}/oauth2/v2.0/token`, | ||
method: "POST", | ||
headers: { "Content-Type": "application/x-www-form-urlencoded" }, | ||
data: qs.stringify(requestBody), | ||
}); | ||
|
||
const { | ||
data: { access_token, expires_in, token_type }, | ||
} = response; | ||
|
||
return { | ||
accessToken: access_token, | ||
refreshToken: "", | ||
expiresIn: +expires_in, | ||
tokenType: token_type, | ||
meta: {}, | ||
}; | ||
} catch (error) { | ||
throw new Error( | ||
`Error fetching refresh token for Microsoft Dynamics 365 Business Central: ${error}` | ||
); | ||
} | ||
}; |