chatgptauth

package module
v0.0.0-...-a31e058 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 11, 2022 License: MIT Imports: 19 Imported by: 0

README

ChatGPTAuth provides requests-based authentication for the OpenAI ChatGPT website.

Extra care was put to ensure that requests match the browser requests in every aspect to avoid blocks, but you still may get rate limit.

It is currently in a VERY wip state, things can and will change.

Installation

go get -u github.com/rodjunger/chatgptauth

Pre-built binaries

Pre-built binaries are not available currently, a CLI is planned.

Lib usage

Check the full example including captcha handling on example/main.go

func main() {
	// Don't use zerolog.DebugLevel to log to console, it will make the output unreadable
	logger := log.Output(zerolog.ConsoleWriter{Out: os.Stdout}).Hook(OnlyInfoHook{}).Level(zerolog.InfoLevel)
	auth, err := chatgptauth.NewAuthClient("user", "password", "", &logger)

	if err != nil {
		log.Error().Err(err).Msg("Failed to create auth client")
		return
	}

	captcha, err := auth.Begin()

	if err != nil {
		log.Error().Err(err).Msg("Failed to begin auth")
		return
	}

	var answer string
	if captcha.Available() {
		// Solve the captcha
		answer = ""
	}

	creds, err := auth.Finish(answer)

	if err != nil {
		log.Error().Err(err).Msg("Failed to finish auth")
		return
	}
	logger.Info().Str("Access token", creds.AccessToken).Str("Expiry", creds.ExpiresAt).Msg("logged in")
	//Save credentials to file so you don't have to login again next time
}

Thank you

This lib was made possible by the reverse engineering work of rawandahmad698, my own reverse engineering work (big shoutout to charles proxy), and the awesome maintainers of all libraries used in this project.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Auth

type Auth struct {
	EmailAddress string
	Password     string
	// contains filtered or unexported fields
}

Auth contains the state for an authenticated user's session.

func NewAuthClient

func NewAuthClient(email, password, proxy string, logger *zerolog.Logger) (auth *Auth, err error)

NewAuthClient creates a new authenticator, performing valiation on the parameters. If the logger pointer is nil, a NOOP logger is used.

func (*Auth) Begin

func (a *Auth) Begin() (captcha Captcha, err error)

Begin starts the authentication process, up to the point where a captcha can be presented or not. if there's no captcha, Finish() can be called with an empty captcha answer, if not, the captcha must be solved and passed to finish. the Captcha type has some helpers to convert the captcha to a png or write it to a file (as png too)

func (*Auth) Finish

func (a *Auth) Finish(captcha string) (cred *Credentials, err error)

type Captcha

type Captcha string

func (Captcha) Available

func (c Captcha) Available() bool

Simple helper to check if there's a captcha

func (Captcha) ToFile

func (c Captcha) ToFile(path string) error

ToFile converts the captcha to png and writes in to disk

func (Captcha) ToPng

func (c Captcha) ToPng() ([]byte, error)

toPng returns the captcha converted to png in []byte format

type Credentials

type Credentials struct {
	AccessToken string `json:"access_token"`
	ExpiresAt   string `json:"expires_at"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL