Code Monkey home page Code Monkey logo

openaiauth's Introduction

OpenAIAuth

Fetch access tokens for chat.openai.com

Python version

from OpenAIAuth import Auth0
auth = Auth0(email_address="[email protected]", password="example_password")
access_token = auth.get_access_token()

Go version

package main

import (
	"fmt"
	"os"

	"github.com/acheong08/OpenAIAuth/auth"
)

func main() {
	auth := auth.NewAuthenticator(os.Getenv("OPENAI_EMAIL"), os.Getenv("OPENAI_PASSWORD"), os.Getenv("PROXY"))
	err := auth.Begin()
	if err.Error != nil {
		println("Error: " + err.Details)
		println("Location: " + err.Location)
		println("Status code: " + fmt.Sprint(err.StatusCode))
		println("Embedded error: " + err.Error.Error())
		return
	}
	token, err := auth.GetAccessToken()
	if err.Error != nil {
		println("Error: " + err.Details)
		println("Location: " + err.Location)
		println("Status code: " + fmt.Sprint(err.StatusCode))
		println("Embedded error: " + err.Error.Error())
		return
	}
	fmt.Println(token)
}

Credits

  • @linweiyuan
  • @rawandahmad698
  • @pengzhile

openaiauth's People

Contributors

aliazhar-id avatar chriscarrollsmith avatar coolplaylin avatar f33rni avatar fabaff avatar linweiyuan avatar oldweipro avatar yuchting avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

openaiauth's Issues

403 response code

Login may return status code 403, with a html response text

 <div id="challenge-body-text" class="core-msg spacer"> 
     chat.openai.com needs to review the security of your connection before proceeding.
  </div>

Max retries exceeded with url: /api/auth/csrf

Tried to host a proxy according to this script: acheong08/ChatGPT#776 (comment)
And run it in local

uvicorn proxy:app --reload

Then connect to the local proxy via the awesome project revChatGPT.V2 as below

from revChatGPT.V2 import Chatbot

chatbot = Chatbot(
    email=email,
    password=password,
    paid=True,
    proxy='http://0.0.0.0',
)

But got an error in OpenAIAuth
requests.exceptions.ProxyError: HTTPSConnectionPool(host='explorer.api.openai.com', port=443): Max retries exceeded with url: /api/auth/csrf (Caused by ProxyError('Cannot connect to proxy.', NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x7fe3a98e61d0>: Failed to establish a new connection: [Errno 111] Connection refused')))

How to fix this sir 🤝

Puid

This project is only suitable for plus users.

Missing one url

Should there be a /api/auth/callback/auth0 before the request /api/auth/session? code=%s&state=%s, otherwise it cannot be obtained

在请求/api/auth/session之前,应该还有一个/api/auth/callback/auth0?code=%s&state=%s,否则获取不到
image

begin这一步时报403错误。

我这边运行的时候begin这一步就报403错误了。好像是cf的v2版本人机认证问题。请大神指教一下如何处理

what version of OpenAIAuth to install

what version of OpenAIAuth to install? I installed default 0.2.0 version with "pip3 install openaiauth", the program crashed without any warn info

Captcha changed?

I seem to be getting a captcha in a different format. Which is resulting in this error (I'm running tag: 0.0.6 as source code).

I'm getting an error like

Traceback (most recent call last):
  File "/usr/local/bin/llmchat", line 33, in <module>
    sys.exit(load_entry_point('large-language-model-cli', 'console_scripts', 'llmchat')())
  File "/Users/tomwright/mine/llmcli/llmcli/__init__.py", line 101, in chatgpt_main
    chatgpt(args)
  File "/Users/tomwright/mine/llmcli/llmcli/__init__.py", line 171, in chatgpt
    chat = chatgpt_login(SESSION_FILE, credentials)
  File "/Users/tomwright/mine/llmcli/llmcli/__init__.py", line 228, in chatgpt_login
    chat = Chatbot(config=credentials)
  File "/Users/tomwright/mine/revchatgpt/ChatGPT/src/revChatGPT/revChatGPT.py", line 95, in __init__
    self.refresh_session()
  File "/Users/tomwright/mine/revchatgpt/ChatGPT/src/revChatGPT/revChatGPT.py", line 340, in refresh_session
    raise exc
  File "/Users/tomwright/mine/revchatgpt/ChatGPT/src/revChatGPT/revChatGPT.py", line 337, in refresh_session
    self.login(self.config["email"], self.config["password"])
  File "/Users/tomwright/mine/revchatgpt/ChatGPT/src/revChatGPT/revChatGPT.py", line 373, in login
    raise exc
  File "/Users/tomwright/mine/revchatgpt/ChatGPT/src/revChatGPT/revChatGPT.py", line 366, in login
    auth.begin()
  File "/Users/tomwright/mine/revchatgpt/OpenAIAuth/src/OpenAIAuth/OpenAIAuth.py", line 97, in begin
    raise Exception("API error")
Exception: API error

The headers look like this:

{'Alt-Svc': 'h3=":443"; ma=86400, h3-29=":443"; ma=86400', 'Cache-Control': 'private, max-age=0, no-store, no-cache, must-revalidate, post-check=0, pre-check=0', 'Cf-Chl-Bypass': '1', 'Cf-Ray': 'XXXXXXXXXX-LHR', 'Content-Encoding': 'gzip', 'Content-Type': 'text/html; charset=UTF-8', 'Date': 'Sun, 11 Dec 2022 22:04:57 GMT', 'Expires': 'Thu, 01 Jan 1970 00:00:01 GMT', 'Permissions-Policy': 'accelerometer=(),autoplay=(),camera=(),clipboard-read=(),clipboard-write=(),fullscreen=(),geolocation=(),gyroscope=(),hid=(),interest-cohort=(),magnetometer=(),microphone=(),payment=(),publickey-credentials-get=(),screen-wake-lock=(),serial=(),sync-xhr=(),usb=()', 'Referrer-Policy': 'same-origin', 'Server': 'cloudflare', 'Set-Cookie': 'XXXXXXXXXXXXXXXXXXXXX path=/; expires=Sun, 11-Dec-22 22:34:57 GMT; domain=.chat.openai.com; HttpOnly; Secure; SameSite=None', 'Vary': 'Accept-Encoding', 'X-Frame-Options': 'SAMEORIGIN'}

The page looks like this:

#  ![](/favicon.ico) chat.openai.com

##  Checking if the site connection is secure

When I logged in with a browser I was prompted by a capture with a similar tittle. J

Is it already irrelevant?

it has started to return the same error ->

Error: File not found.
Location: part_one
Status code: 404
Embedded error: error: Check details

RecursionError: maximum recursion depth exceeded while calling a Python object

I 've set my session_token, cf_clearance and user-agent seperately:

Debugger enabled on OpenAIAuth
Traceback (most recent call last):
  File "/root/miniconda3/lib/python3.8/runpy.py", line 194, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/root/miniconda3/lib/python3.8/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/home/myCharGPTRobot/main.py", line 44, in <module>
    gptChatbot = Chatbot(config, conversation_id=None, debug=True)
  File "/root/miniconda3/lib/python3.8/site-packages/revChatGPT/revChatGPT.py", line 96, in __init__
    self.refresh_session()
  File "/root/miniconda3/lib/python3.8/site-packages/revChatGPT/revChatGPT.py", line 279, in refresh_session
    s = httpx.Client()
  File "/root/miniconda3/lib/python3.8/site-packages/httpx/_client.py", line 679, in __init__
    self._transport = self._init_transport(
  File "/root/miniconda3/lib/python3.8/site-packages/httpx/_client.py", line 727, in _init_transport
    return HTTPTransport(
  File "/root/miniconda3/lib/python3.8/site-packages/httpx/_transports/default.py", line 126, in __init__
    ssl_context = create_ssl_context(verify=verify, cert=cert, trust_env=trust_env)
  File "/root/miniconda3/lib/python3.8/site-packages/httpx/_config.py", line 49, in create_ssl_context
    return SSLConfig(
  File "/root/miniconda3/lib/python3.8/site-packages/httpx/_config.py", line 73, in __init__
    self.ssl_context = self.load_ssl_context()
  File "/root/miniconda3/lib/python3.8/site-packages/httpx/_config.py", line 85, in load_ssl_context
    return self.load_ssl_context_verify()
  File "/root/miniconda3/lib/python3.8/site-packages/httpx/_config.py", line 122, in load_ssl_context_verify
    context = self._create_default_ssl_context()
  File "/root/miniconda3/lib/python3.8/site-packages/httpx/_config.py", line 157, in _create_default_ssl_context
    set_minimum_tls_version_1_2(context)
  File "/root/miniconda3/lib/python3.8/site-packages/httpx/_compat.py", line 35, in set_minimum_tls_version_1_2
    context.minimum_version = ssl.TLSVersion.TLSv1_2
  File "/root/miniconda3/lib/python3.8/ssl.py", line 586, in minimum_version
    super(SSLContext, SSLContext).minimum_version.__set__(self, value)
  File "/root/miniconda3/lib/python3.8/ssl.py", line 586, in minimum_version
    super(SSLContext, SSLContext).minimum_version.__set__(self, value)
  File "/root/miniconda3/lib/python3.8/ssl.py", line 586, in minimum_version
    super(SSLContext, SSLContext).minimum_version.__set__(self, value)
  [Previous line repeated 487 more times]
  File "/root/miniconda3/lib/python3.8/ssl.py", line 584, in minimum_version
    if value == TLSVersion.SSLv3:
RecursionError: maximum recursion depth exceeded while calling a Python object

How to deal with ?

OpenAIAuth.__init__() got an unexpected keyword argument 'cf_clearance'

Getting the following error, probably related to cfb9a17

Traceback (most recent call last):
  File "/code/project/slack.py", line 16, in <module>
    chatbot = Chatbot(config, conversation_id=None)
  File "/code/project/slack.py-ggXW00PY/lib/python3.10/site-packages/revChatGPT/revChatGPT.py", line 96, in __init__
    self.refresh_session()
  File "/code/project/slack.py-ggXW00PY/lib/python3.10/site-packages/revChatGPT/revChatGPT.py", line 352, in refresh_session
    raise exc
  File "/code/project/slack.py-ggXW00PY/lib/python3.10/site-packages/revChatGPT/revChatGPT.py", line 349, in refresh_session
    self.login(self.config["email"], self.config["password"])
  File "/code/project/slack.py-ggXW00PY/lib/python3.10/site-packages/revChatGPT/revChatGPT.py", line 375, in login
    auth = OpenAIAuth(email, password, use_proxy=bool(
TypeError: OpenAIAuth.__init__() got an unexpected keyword argument 'cf_clearance'

Feature: Implement Captcha - Success

            if soup.find('img', alt='captcha'):
                print(f"{Fore.RED}[OpenAI][5] {Fore.RED}Captcha detected")

                svg_captcha = soup.find('img', alt='captcha')['src'].split(',')[1]
                decoded_svg = base64.decodebytes(svg_captcha.encode("ascii"))

                # Convert decoded svg to png
                drawing = svg2rlg(BytesIO(decoded_svg))

                # Better quality
                renderPM.drawToFile(drawing, "captcha.png", fmt="PNG", dpi=300)
                print(f"{Fore.GREEN}[OpenAI][5] {Fore.WHITE}Captcha saved to {Fore.GREEN}captcha.png"
                      + f" {Fore.WHITE}in the current directory")

                # Wait.
                captcha_input = input(f"{Fore.GREEN}[OpenAI][5] {Fore.WHITE}Please solve the captcha and "
                                      f"press enter to continue: ")
                if captcha_input:
                    print(f"{Fore.GREEN}[OpenAI][5] {Fore.WHITE}Continuing...")
                    self._part_six(state=state, captcha=captcha_input)
                else:
                    raise Exceptions.PyChatGPTException("[OpenAI][5] You didn't enter anything.")

            else:
                print(f"{Fore.GREEN}[OpenAI][5] {Fore.GREEN}No captcha detected")
                self._part_six(state=state, captcha=None)

Translate this to use requests and regex

The latest go version triggers CF challenge

Error: <html>
  <head>
    <style global>body{font-family:Arial,Helvetica,sans-serif}.container{align-items:center;display:flex;flex-direction:column;gap:2rem;height:100%;justify-content:center;width:100%}@keyframes enlarge-appear{0%{opacity:0;transform:scale(75%) rotate(-90deg)}to{opacity:1;transform:scale(100%) rotate(0deg)}}.logo{color:#8e8ea0}.scale-appear{animation:enlarge-appear .4s ease-out}@media (min-width:768px){.scale-appear{height:48px;width:48px}}.data:empty{display:none}.data{border-radius:5px;color:#8e8ea0;text-align:center}@media (prefers-color-scheme:dark){body{background-color:#343541}.logo{color:#acacbe}}</style>

</head>
  <body>
    <div class="container">
      ........
</html>

Location: begin
Status code: 403
Embedded error: error: Check details

Your version of the ChatGPT app is out of date. Please update to the newest build of the app.

Traceback (most recent call last):
  File "C:\Users\user\PycharmProjects\ChatGPT\main.py", line 91, in <module>
    access_token = auth.get_access_token()
  File "C:\Users\user\PycharmProjects\ChatGPT\venv\lib\site-packages\OpenAIAuth.py", line 69, in get_access_token
    return self.__part_two()
  File "C:\Users\user\PycharmProjects\ChatGPT\venv\lib\site-packages\OpenAIAuth.py", line 82, in __part_two
    return self.__part_three(code_verifier, url)
  File "C:\Users\user\PycharmProjects\ChatGPT\venv\lib\site-packages\OpenAIAuth.py", line 97, in __part_three
    return self.__part_four(code_verifier, state)
  File "C:\Users\user\PycharmProjects\ChatGPT\venv\lib\site-packages\OpenAIAuth.py", line 124, in __part_four
    return self.__part_five(code_verifier, state)
  File "C:\Users\user\PycharmProjects\ChatGPT\venv\lib\site-packages\OpenAIAuth.py", line 150, in __part_five
    return self.__part_six(code_verifier, location, url)
  File "C:\Users\user\PycharmProjects\ChatGPT\venv\lib\site-packages\OpenAIAuth.py", line 179, in __part_six
    return self.__get_access_token(code_verifier, resp.headers["Location"])
  File "C:\Users\user\PycharmProjects\ChatGPT\venv\lib\site-packages\OpenAIAuth.py", line 221, in __get_access_token
    raise Exception("{}: {}".format(error, error_description))
Exception: access_denied: Your version of the ChatGPT app is out of date. Please update to the newest build of the app.

What is purpose of puid in the cookie?

I saw there is a new attribute in the latest code. I am not clear about what it is about and where it comes from in the application. It is a cookie value after the user logins in the webapp.

Please add some comments about this if possible. It will be greatly appreciated.

Connection to auth0.openai.com timed out

Dear,
My problem is that __part_two connect TimeoutError.
How could I solve it?
thks a lot.

urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='auth0.openai.com', port=443): Max retries exceeded with url: /authorize?client_id=&scope=openid%20email%20profile%20offline_access%20model.request%20model.read%20organization.read&response_type=code&redirect_uri=https%3A%2F%2Fexplorer.api.openai.com%2Fapi%2Fauth%2Fcallback%2Fauth0&audience=https%3A%2F%2Fapi.openai.com%2Fv1&prompt=login&state=&code_challenge=&code_challenge_method=S256 (Caused by ConnectTimeoutError(<urllib3.connection.HTTPSConnection object at 0x000001A86C97CE80>, 'Connection to auth0.openai.com timed out. (connect timeout=None)'))

How to use?

hi

I want to know how to use this library,can you tell me?

thanks.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.