Skip to content

Commit

Permalink
added: Business central to prefetch company data in oauth
Browse files Browse the repository at this point in the history
  • Loading branch information
oberoi-gaurav committed Jul 2, 2024
1 parent efa8e6e commit 06f500c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,25 @@ export const init = async ({ body }: DataObject): Promise<OAuthResponse> => {
data: { access_token, expires_in, token_type },
} = response;

const companiesURL = `https://api.businesscentral.dynamics.com/v2.0/${body.metadata?.formData?.ENVIRONMENT_NAME}/api/v2.0/companies`;

const companies = await axios.get(companiesURL, {
headers: {
Authorization: `Bearer ${access_token}`,
},
});

const {
data: { value: companiesData },
} = companies;
const companyId = companiesData[0].id;

return {
accessToken: access_token,
refreshToken: "",
expiresIn: +expires_in,
tokenType: token_type,
meta: {},
meta: { companyId },
};
} catch (error) {
throw new Error(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export const refresh = async ({ body }: DataObject): Promise<OAuthResponse> => {
OAUTH_CLIENT_ID: client_id,
OAUTH_CLIENT_SECRET: client_secret,
OAUTH_REQUEST_PAYLOAD: { formData },
OAUTH_METADATA,
} = body;
const requestBody = {
grant_type: "client_credentials",
Expand All @@ -32,7 +33,9 @@ export const refresh = async ({ body }: DataObject): Promise<OAuthResponse> => {
refreshToken: "",
expiresIn: +expires_in,
tokenType: token_type,
meta: {},
meta: {
...OAUTH_METADATA?.meta,
},
};
} catch (error) {
throw new Error(
Expand Down

0 comments on commit 06f500c

Please sign in to comment.