Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MI-121: Updates the "generateMeshToken" function to return a "custome… #39

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
11 changes: 11 additions & 0 deletions packages/modules/bigcommerce/release-notes.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# BigCommerce GraphQl Module Release Notes

## bigcommerce-graphql-module-1.1.0

#### Changes:

- Updates the "generateMeshToken" function to return a "customer_id" property instead of "bc_customer_id". Updates the "getBcCustomerIdFromMeshToken" function to look for a "customer_id" property instead of "bc_customer_id". This is due to the Auth Module generating a JWT containing a "customer_id" property but the BigCommerce Module decodes the JWT and looks for a "bc_customer_id" property.

#### Tickets

- MI-121: Auth module authentication issue
- https://aligent.atlassian.net/browse/MI-121

## bigcommerce-graphql-module-1.0.6

#### Changes:
Expand Down
2 changes: 2 additions & 0 deletions packages/modules/bigcommerce/src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,9 @@ export interface DecodedCustomerImpersonationToken {
}

export interface MeshToken {
/* @deprecated since v1.0.1. Use "customer_id" instead */
bc_customer_id: number;
customer_id: number;
iat: number;
exp: number;
}
Expand Down
10 changes: 7 additions & 3 deletions packages/modules/bigcommerce/src/utils/tokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,17 @@ export const getDecodedCustomerImpersonationToken = (
};

/**
* Attempts to extract "bc_customer_id" for the mesh token or throws an error
* Attempts to extract "customer_id" for the mesh token or throws an error
* @param meshToken
*/
export const getBcCustomerIdFromMeshToken = (meshToken: string): number => {
try {
if (meshToken?.toLowerCase().startsWith('bearer')) {
const splitMeshToken = meshToken.split(' ')[1];
const decodedMeshToken = verify(splitMeshToken, JWT_PRIVATE_KEY) as MeshToken;
return decodedMeshToken.bc_customer_id;

/* @deprecated since v1.0.1. Use "customer_id" instead of "bc_customer_id" */
return decodedMeshToken.customer_id || decodedMeshToken.bc_customer_id;
} else {
throw new Error(`Need to send Bearer token`);
}
Expand All @@ -48,13 +50,15 @@ export const getBcCustomerIdFromMeshToken = (meshToken: string): number => {
};

/**
* Creates a token when a user logs in also stores the bc_customer_id in the payload
* Creates a token when a user logs in also stores the customer_id in the payload
* which can be used for later request to the Mesh.
* @param {number} entityId - Bc User Id returned from logging in
*/
export const generateMeshToken = (entityId: number): string => {
const payload = {
/* @deprecated since v1.0.1. Use "customer_id" instead */
bc_customer_id: entityId,
customer_id: entityId,
exp: getUnixTimeStampInSecondsForMidnightTonight(),
};

Expand Down
Loading