barnesoir / chatgpt-vscode-plugin

A VS code plugin for ChatGPT built by ChatGPT
MIT License
250 stars 61 forks source link

chatgpt failed to refresh auth token. 403 forbidden access #22

Closed inuru closed 1 year ago

inuru commented 1 year ago

I have the token but always Got error 403. Is there step that I miss?

ImYuya commented 1 year ago

+1

zouweidong91 commented 1 year ago

+1

iapYang commented 1 year ago

+1

minhlucvan commented 1 year ago

+1

mohammad-oghli commented 1 year ago

+1

mohammad-oghli commented 1 year ago

If you check authentication session token. It changed every second in the cookies tab. I think there is change in the backend code from the ChatGPT application side.

minhlucvan commented 1 year ago

refrenced issue: https://github.com/transitive-bullshit/chatgpt-api/issues/96

barnesoir commented 1 year ago

Added a capture for cf_clearance token in latest release.

ImYuya commented 1 year ago

still getting the same error

odragora commented 1 year ago

Me too. Followed the instructions in README, reset the token, pasted both tokens and still get 403: Forbidden.

ImYuya commented 1 year ago

@barnesoir https://github.com/barnesoir/chatgpt-vscode-plugin/blob/d8ca1e44d94d8d3a531f4ccb952282b315e055c7/src/chatgpt-view-provider.ts#L61-L62

I'm not familiar with Typescript, but I think you need to fix it below.

this.sessionToken = userSessionToken!;
this.context.globalState.update('chatgpt-clearance-token', this.sessionToken);

this.clearanceToken = userSessionToken!;
this.context.globalState.update('chatgpt-clearance-token', this.clearanceToken);
mohammad-oghli commented 1 year ago

Also he should add userAgent as mentioned in the updated issue on chatgpt-api.

Your user-agent and IP address must match from the real browser window you're logged in with to the one you're using for ChatGPTAPI

timkmecl commented 1 year ago

That's right, both the clearanceToken and userAgent have to be set and must match, as described here. See README.md from my extension for instructions on obtaining them.

timkmecl commented 1 year ago

My pull request #24 implements solutions by @mohammad-oghli and @ImYuya, should completely solve the issue caused by CloudFlare.

ImYuya commented 1 year ago

still getting the same error... I input sessionToken, clearanceToken and userAgent.

nilPogonin commented 1 year ago

Same thing. Still same error

mohammad-oghli commented 1 year ago

+1 same issue.

jasonke1025 commented 1 year ago

v1.1.8 still got the same error

timkmecl commented 1 year ago

Sorry, I've forgotten to commit changes that actually pass userAgent to ChatGPTAPI in the previous PR, #25 should fix this (I tested it and it works for me).

minhlucvan commented 1 year ago

image

mohammad-oghli commented 1 year ago

Not working for me.

oldcodeoberyn commented 1 year ago

the ChatGPTAPI update to 2.3.0, which require OpenAIEmail and OpenAIPassword to ensureAuth. BUT! it require nodejs >=18 which vscode bundle 16.14.3. No solution...

timkmecl commented 1 year ago

I just retested it and it still works for me. Maybe nodejs version is the problem like @oldcodeoberyn says; could someone with the problem post their node version (node -v in terminal) to check it? I have v18.12.1.

@mohammad-oghli Are you using it on the same machine and obtaining tokens in the same way as you did here? The implemented fix is basically the same as I did in my extension.

kaykouo commented 1 year ago

I just retested it and it still works for me. Maybe nodejs version is the problem like @oldcodeoberyn says; could someone with the problem post their node version (node -v in terminal) to check it? I have v18.12.1.

@mohammad-oghli Are you using it on the same machine and obtaining tokens in the same way as you did here? The implemented fix is basically the same as I did in my extension.

updated nodejs, still the 403 error

timkmecl commented 1 year ago

I will paste my answer from my extension here which shows some new info about this:

It looks like this problem is not limited to this project, but also to some other ones using chatgpt-api, probably caused by agressive CloudFlare protection. In my own testing, even when I tried to login to my account in Chrome right after using it inside Edge, I got a 403 error inside the web version. After I waited for several minutes and tried again, it disappeard, but this shows that the problem is not just with the javascript API.

The browser that you use for getting the tokens might influence the chance to get 403, especially chrome, so maybe try from another one (https://github.com/transitive-bullshit/chatgpt-api/issues/107#issuecomment-1349712906)

There might also be some account or IP flagging going on either by OpenAI or CloudFlare that increases the possibility of getting 403 especially if doing lots of requests often (https://github.com/transitive-bullshit/chatgpt-api/issues/96#issuecomment-1350275343)

Update:

It seems like using Chrome to obtain the tokens is what is causing (most of?) these issues. So if you have 403 Error despite following the instructions and using code from #25 PR, try using a browser other than Chrome!

evilz commented 1 year ago

It was not working with Chrome but it's ok using Edge (Win11) 👍🏻

DavidRavnsborg commented 1 year ago

I have tried in Chrome, Firefox, Edge, and Brave. They all lead to this error.

However, I haven't done JS development for a bit. My node version is v14.16.1. Going to try updating that and trying again.

DavidRavnsborg commented 1 year ago

I updated to node v18.12.1 and am still encountering the same issue. Used the Brave browser.

E.g. useragent key-value pair: user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36