Skip to content

Commit

Permalink
error handling etc
Browse files Browse the repository at this point in the history
  • Loading branch information
Antonio committed May 25, 2023
1 parent 5c236ce commit 92146e5
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions auth/OpenAiAuth.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func NewAuthenticator(emailAddress, password, proxy string) *Authenticator {
jar := tls_client.NewCookieJar()
options := []tls_client.HttpClientOption{
tls_client.WithTimeoutSeconds(20),
tls_client.WithClientProfile(tls_client.Chrome_110),
tls_client.WithClientProfile(tls_client.Firefox_102),
tls_client.WithNotFollowRedirects(),
tls_client.WithCookieJar(jar), // create cookieJar instance and pass it as argument
// Proxy
Expand Down Expand Up @@ -345,13 +345,16 @@ func (auth *Authenticator) partSix(oldState string, redirectURL string) Error {

}
func (auth *Authenticator) GetAccessToken() (string, Error) {
// Parse auth.URL (Get code=7QEpWz_4irkvJSP29Pyx0-EguHDFhQd_L1rhaxdBbl3gT) using regex
code := regexp.MustCompile(`code=(.*)&`).FindStringSubmatch(auth.URL)[1]
code := regexp.MustCompile(`code=(.*)&`).FindStringSubmatch(auth.URL)
if len(code) == 0 {
err := NewError("__get_access_token", 0, auth.URL, fmt.Errorf("error: Check details"))
return "", *err
}
payload, _ := json.Marshal(map[string]string{
"redirect_uri": "com.openai.chat://auth0.openai.com/ios/com.openai.chat/callback",
"grant_type": "authorization_code",
"client_id": "pdlLIX2Y72MIl2rhLhTE9VV9bN905kBh",
"code": code,
"code": code[1],
"code_verifier": auth.Verifier_code,
"state": auth.State,
})
Expand Down

0 comments on commit 92146e5

Please sign in to comment.