RomanHotsiy / commitgpt

Automatically generate commit messages using ChatGPT
1.57k stars 92 forks source link

Unable to authenticate - the request is blocked #3

Closed shrx closed 1 year ago

shrx commented 1 year ago

Pasting the auth token into commitgpt returns the message: "Invalid token. Please try again."

I did an equivalent curl request and the response is:

curl -H "__Secure-next-auth.session-token=$TOKEN" "https://chat.openai.com/api/auth/session"
<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'><html xmlns='http://www.w3.org/1999/xhtml'><head><meta content='text/html; charset=utf-8' http-equiv='content-type'/><style type='text/css'>body { font-family:Arial; margin-left:40px; }img  { border:0 none; }#content { margin-left: auto; margin-right: auto }#message h2 { font-size: 20px; font-weight: normal; color: #000000; margin: 34px 0px 0px 0px }#message p  { font-size: 13px; color: #000000; margin: 7px 0px 0px 0px }#errorref { font-size: 11px; color: #737373; margin-top: 41px }</style><title>Microsoft</title></head><body><div id='content'><div id='message'><h2>The request is blocked.</h2></div><div id='errorref'><span>0YvqOYwAAAAAiMEPW7daTQ7ok4jSan+1sRlJBMzFFREdFMDkxNwBlNjZiOGIwMy0wNzkzLTQ0MDktOTc3My0yZTYxMmU3MWExZTM=</span></div></div></body></html>%  
fzn0x commented 1 year ago

After checking it for a while, I noticed that the auth token keeps changing

fzn0x commented 1 year ago

I think it's related to your problem, try to check your session token expires.

shrx commented 1 year ago

Indeed it looks to be changing constantly, but it's not expiring: Expires / Max-Age:"Thu, 05 Jan 2023 08:41:24 GMT"

fzn0x commented 1 year ago

Indeed it looks to be changing constantly, but it's not expiring: Expires / Max-Age:"Thu, 05 Jan 2023 08:41:24 GMT"

It's weird... I wonder if chatGPT has an additional security mechanism that makes the token not work even though it has not expired...

shrx commented 1 year ago

I tried authenticating using the https://github.com/transitive-bullshit/chatgpt-api project and that demo works, so it looks like an issue with this project.

lukasnagl commented 1 year ago

I tried authenticating using the https://github.com/transitive-bullshit/chatgpt-api project and that demo works, so it looks like an issue with this project.

Maybe the API is sensitive to the user agent passed along? chatgpt-api passes a user agent while commitgpt is missing it.

chatgpt-api is using 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36' by default.

shrx commented 1 year ago

@lukasnagl indeed, a curl request with this user agent does not fail.

RomanHotsiy commented 1 year ago

Should be fixed by https://github.com/RomanHotsiy/commitgpt/pull/4