-
Notifications
You must be signed in to change notification settings - Fork 337
fix: B2B-3725 add required b2b headers #2631
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
Conversation
|
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Hey @bc-victor , this is not a bug. It is intentional to use new headers. See below articles: |
bc-micah
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I want to see the docs updated + including tests for both the old and new tokens - comments have details.
core/b2b/client.ts
Outdated
| env: z.object({ | ||
| B2B_API_TOKEN: z.string(), | ||
| BIGCOMMERCE_CHANNEL_ID: z.string(), | ||
| BIGCOMMERCE_STORE_HASH: z.string(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did we update the docs that explain what a B2B_API_TOKEN is as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PR here: bigcommerce/docs#1104
core/b2b/client.ts
Outdated
| 'X-Store-Hash': BIGCOMMERCE_STORE_HASH, | ||
| 'X-Auth-Token': B2B_API_TOKEN, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we include full tests of both tokens (old b2b only s2s token + bigcommerce api account token)?
I would like to see the full flow tested for both scenarios and include showing / setting the env var + verifying the login is working appropriately (including opening the buyer portal as that shows the storefront is logged in as well as the b2b functions)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for the review. After testing realized we can't just send authToken, X-Auth-Token and X-Store-Hash together, we need to know which token is being used. I added a new variable BIGCOMMERCE_TOKEN_WITH_B2B_SCOPE to differntiatte from scopes
c0129ec to
761ca3b
Compare
761ca3b to
b3641af
Compare
.env.example
Outdated
| # BigCommerce API token with B2B Edition scopes used to authenticate requests to the B2B API | ||
| BIGCOMMERCE_TOKEN_WITH_B2B_SCOPE= | ||
|
|
||
| # DEPRECATED - Please prefer using the above variable | ||
| # The B2B API Token is used to authenticate requests to the B2B API. | ||
| # It can be generated in the B2B control panel Settings > API Accounts > Create API Account. | ||
| B2B_API_TOKEN= | ||
| # B2B_API_TOKEN= |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe lets remove this entirely? also from the docs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we do it directly?
maybe add a check, if B2B_API_TOKEN is present, throw and show an error message?
z.object({
B2B_API_TOKEN: z.undefined({ message: 'This is deprecated in favour or B2B_API_TOKEN'}).optional(),
BIGCOMMERCE_TOKEN: z.string()
})
icatalina
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pre approving, I think I prefer a more generic token name and removing the old one. What do you all think?
.env.example
Outdated
| # BigCommerce API token with B2B Edition scopes used to authenticate requests to the B2B API | ||
| BIGCOMMERCE_TOKEN_WITH_B2B_SCOPE= | ||
|
|
||
| # DEPRECATED - Please prefer using the above variable | ||
| # The B2B API Token is used to authenticate requests to the B2B API. | ||
| # It can be generated in the B2B control panel Settings > API Accounts > Create API Account. | ||
| B2B_API_TOKEN= | ||
| # B2B_API_TOKEN= |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we do it directly?
maybe add a check, if B2B_API_TOKEN is present, throw and show an error message?
z.object({
B2B_API_TOKEN: z.undefined({ message: 'This is deprecated in favour or B2B_API_TOKEN'}).optional(),
BIGCOMMERCE_TOKEN: z.string()
})
.env.example
Outdated
| B2B_API_HOST=https://api-b2b.bigcommerce.com | ||
|
|
||
| # BigCommerce API token with B2B Edition scopes used to authenticate requests to the B2B API | ||
| BIGCOMMERCE_TOKEN_WITH_B2B_SCOPE= |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| BIGCOMMERCE_TOKEN_WITH_B2B_SCOPE= | |
| BIGCOMMERCE_TOKEN= |
if we require new scopes in the future, are we gonna rename the variable to:
BIGCOMMERCE_TOKEN_WITH_B2B_AND_SOME_OTHER_SCOPE=
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thats a good point, I'll add this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"With x scope" seems like an awkward naming convention in general to me.
Just for reference, the optional BigCommerce REST token that can be included in the environment config for, e.g., supporting the customer groups lookup in Makeswift, is called BIGCOMMERCE_ACCESS_TOKEN. We might want to conform the naming convention here to more closely match that.
Or is it possibly appropriate to just use BIGCOMMERCE_ACCESS_TOKEN and give clear instructions that the token provided there needs to have the B2B scope? I think that might make more sense than having separate BigCommerce REST tokens for separate operations.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it's already being used in makeswift, let's stick to the existing name to reduce the number of things the user has to setup.
We can then just add that B2B scope is required in the setup docs.
.env.example
Outdated
| B2B_API_HOST=https://api-b2b.bigcommerce.com | ||
|
|
||
| # BigCommerce API token with B2B Edition scopes used to authenticate requests to the B2B API | ||
| BIGCOMMERCE_TOKEN_WITH_B2B_SCOPE= |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"With x scope" seems like an awkward naming convention in general to me.
Just for reference, the optional BigCommerce REST token that can be included in the environment config for, e.g., supporting the customer groups lookup in Makeswift, is called BIGCOMMERCE_ACCESS_TOKEN. We might want to conform the naming convention here to more closely match that.
Or is it possibly appropriate to just use BIGCOMMERCE_ACCESS_TOKEN and give clear instructions that the token provided there needs to have the B2B scope? I think that might make more sense than having separate BigCommerce REST tokens for separate operations.
core/b2b/client.ts
Outdated
| if (B2B_API_TOKEN) { | ||
| headers['authToken'] = B2B_API_TOKEN; | ||
| } | ||
|
|
||
| if (BIGCOMMERCE_TOKEN_WITH_B2B_SCOPE) { | ||
| headers['X-Auth-Token'] = BIGCOMMERCE_TOKEN_WITH_B2B_SCOPE; | ||
| headers['X-Store-Hash'] = BIGCOMMERCE_STORE_HASH; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| if (B2B_API_TOKEN) { | |
| headers['authToken'] = B2B_API_TOKEN; | |
| } | |
| if (BIGCOMMERCE_TOKEN_WITH_B2B_SCOPE) { | |
| headers['X-Auth-Token'] = BIGCOMMERCE_TOKEN_WITH_B2B_SCOPE; | |
| headers['X-Store-Hash'] = BIGCOMMERCE_STORE_HASH; | |
| } | |
| if (BIGCOMMERCE_TOKEN_WITH_B2B_SCOPE) { | |
| headers['X-Auth-Token'] = BIGCOMMERCE_TOKEN_WITH_B2B_SCOPE; | |
| headers['X-Store-Hash'] = BIGCOMMERCE_STORE_HASH; | |
| } else if (B2B_API_TOKEN) { | |
| headers['authToken'] = B2B_API_TOKEN; | |
| } |
They both should not be used at the same time, we should prefer the BIGCOMMERCE_TOKEN if possible.
.env.example
Outdated
| B2B_API_HOST=https://api-b2b.bigcommerce.com | ||
|
|
||
| # BigCommerce API token with B2B Edition scopes used to authenticate requests to the B2B API | ||
| BIGCOMMERCE_TOKEN_WITH_B2B_SCOPE= |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it's already being used in makeswift, let's stick to the existing name to reduce the number of things the user has to setup.
We can then just add that B2B scope is required in the setup docs.
b3641af to
ad75212
Compare
core/b2b/client.ts
Outdated
| } else { | ||
| throw new Error(`No B2B API token or BigCommerce token found in environment variables.`); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is only using the new BIGCOMMERCE_ACCESS_TOKEN, will break when existing customers upgrade to this version.
50de4a7 to
d8d8a48
Compare
core/b2b/client.ts
Outdated
| BIGCOMMERCE_CHANNEL_ID: z.string(), | ||
| BIGCOMMERCE_STORE_HASH: z.string(), | ||
| BIGCOMMERCE_ACCESS_TOKEN: z.string().optional(), | ||
| B2B_API_TOKEN: z.string().optional().describe('This is deprecated in favour or BIGCOMMERCE_ACCESS_TOKEN, read https://support.bigcommerce.com/s/article/Store-API-Accounts?language=en_US'), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💅 Not sure if we need the describe here.
We might want to define a union in this case:
z.union([
z.object({
BIGCOMMERCE_CHANNEL_ID: z.string(),
B2B_API_TOKEN: z.string(),
}),
z.object({
BIGCOMMERCE_CHANNEL_ID: z.string(),
BIGCOMMERCE_STORE_HASH: z.string(),
BIGCOMMERCE_ACCESS_TOKEN: z.string(),
}),
])The current approach makes BIGCOMMERCE_STORE_HASH mandatory, even for old consumers where it is not needed, and makes both B2B_API_TOKEN and BIGCOMMERCE_ACCESS_TOKEN which mean they can potentially be both missing.
d8d8a48 to
0027b89
Compare
What/Why?
After the release of PROJECT-6952, developers using a BC store-level oauth token with the new B2B Edition oauth scope need to send additional headers for the endpoint to respond properly.
Adding env variable
BIGCOMMERCE_ACCESS_TOKENto differentiate from the type of headers we need to send to the B2B APIsTesting
Login success ( only place where we use B2B APIs)
With B2B token
Screen.Recording.2025-10-08.at.11.20.59.a.m.mov
Without BC token
Screen.Recording.2025-10-08.at.11.22.03.a.m.mov
Migration
No migrations