SalesforceCommerceCloud / commerce-sdk-isomorphic

Browser & Node.js JavaScript client for B2C Commerce API
https://salesforcecommercecloud.github.io/commerce-sdk-isomorphic/
BSD 3-Clause "New" or "Revised" License
42 stars 20 forks source link

Unexpected 401 Unauthorized #74

Closed dev-niko closed 2 years ago

dev-niko commented 2 years ago

Greetings,

i am trying the readme example of this Repo. But always receive an 401 Unauthorized. Although I have configured everything correctly according to the Docs.

const config = { proxy: 'https://localhost:3000', headers: {}, parameters: { clientId: '8c825a0f-ZZZZ-YYYY-XXXX-31a48689bc0c', organizationId: 'f_ecom_bdgv_s05', shortCode: 'cddbw104', siteId: 'RefArch', }, };

In my Sandbox Logs i see this error, after the auth request was send:

image

https://localhost:3000/shopper/auth/v1/organizations/f_ecom_bdgv_s05/oauth2/authorize?redirect_uri=https%3A%2F%2Flocalhost%3A3000%2Fcallback&response_type=code&client_id=8c825a0f-ZZZZ-YYYY-XXXX-31a48689bc0c&hint=guest&code_challenge=qmg4aiSfaJmawO7HbGlSPICvF_jOwU-UDis0hiwXUEY:

Request Headers:

Accept: */* Accept-Encoding: gzip, deflate, br Accept-Language: en-US,en;q=0.9 Connection: keep-alive Host: localhost:3000 Referer: https://localhost:3000/ sec-ch-ua: " Not;A Brand";v="99", "Google Chrome";v="97", "Chromium";v="97" sec-ch-ua-mobile: ?0 sec-ch-ua-platform: "Linux" Sec-Fetch-Dest: empty Sec-Fetch-Mode: cors Sec-Fetch-Site: same-origin User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.99 Safari/537.36

Response 401 Headers:

cache-control: no-store cf-cache-status: DYNAMIC cf-ray: 6d7302aa7c786977-FRA connection: close Content-Encoding: gzip content-type: application/json date: Wed, 02 Feb 2022 11:16:58 GMT expect-ct: max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct" pragma: no-cache server: cloudflare strict-transport-security: max-age=31536000; includeSubDomains transfer-encoding: chunked Vary: Accept-Encoding x-correlation-id: 1ad8f74b-6ccf-4596-a5c5-820fee2c516b X-Powered-By: Express x-ratelimit-1m-limit: 1800000, 1800000, 18000000, 60000 x-ratelimit-1m-remaining: 1799930, 1799999, 17999999, 59999 x-ratelimit-1m-reset: 1134, 1130, 1128, 1127 x-ratelimit-5m-limit: 120000 x-ratelimit-5m-remaining: 119999 x-ratelimit-5m-reset: 181126 x-ratelimit-limit: 1000000 x-ratelimit-remaining: 999930 x-ratelimit-reset: 1130 x-ratelimit-tenant-limit: 1000000 x-ratelimit-tenant-remaining: 999999 x-ratelimit-tenant-reset: 1136

What does this mean? What can i do, to send an valid "state" value?

I am on NodeJs 14.18.3 and Ubuntu 20.04

tarcang commented 2 years ago

Hello @dev-niko, thank you for reaching out to us! Are trying to run the example app that is included in this repository, or do you have a piece of test code that you are trying the sdk on?

dev-niko commented 2 years ago

Hi @tarcang, i am trying to run this repo. By executing the npm start command.

This are the settings of the api client, which i am using:

image

unandyala commented 2 years ago

Hi @dev-niko I presume you have not changed anything in the sample application code except the client configuration and poxy URL in package.json. We are not able to reproduce the issue. Just want to confirm if you are setting any state in the auth request.

Thanks Ujwala

dev-niko commented 2 years ago

Hi @unandyala, no i changed nothing except the client configuration and poxy URL.

unandyala commented 2 years ago

Hi @dev-niko, Thanks for confirming. Could you please share your client configuration so that we can try reproducing the issue.

dev-niko commented 2 years ago

Hi @unandyala. Yes sure.

My config.js:

const config = { proxy: 'https://localhost:3000', headers: {}, parameters: { clientId: '8c825a0f-ZZZZ-YYYY-XXXX-31a48689bc0c', organizationId: 'f_ecom_bdgv_s05', shortCode: 'cddbw104', siteId: 'RefArch', }, };

And the only change in package.json is:

"proxy": "https://cddbw104.api.commercecloud.salesforce.com"

tarcang commented 2 years ago

Hello @dev-niko. To be able to accurately reproduce to issue you are having, we need your full client id. Don't write the client id here, you can mail it to me at tarcan.gul@salesforce.com. We will try to reproduce it and see if it is the sdk problem, app problem or a client configuration problem (so far to us the app and the sdk looks ok).

dev-niko commented 2 years ago

Okay. Thank you for your support.