Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting error "OAUTHBEARER authentication error (invalid_request)", when trying to re-establish a connection #24

Open
sandeep-das-31 opened this issue Sep 25, 2023 · 0 comments

Comments

@sandeep-das-31
Copy link

sandeep-das-31 commented Sep 25, 2023

The initial connection is working fine with the generated access token which has a TTL of 60 minutes, but when I try to use to same access token with multiple calls to the same API and trying to establish a connection for the same, I am getting this error.

I am able to establish a connection after 9-10 tries, which takes around a time of 3-4 minutes after continuous retries

The code I am using to establish the connection,
func (i *imapUtils) ConnectAndReturnClient(clientAddress string, email string, userAccountsUUID string) (*client.Client, error) {
c, err := client.DialTLS(clientAddress, nil)
if err != nil {
i.log.Error("error in dialing client: ", err)
return nil, err
}
userAccountsCredentials, err := i.userAccountCredentialsRepo.GetByAccountUUID(userAccountsUUID)
if err != nil {
i.log.Error("error in credential details for ConnectAndReturnClient: ", err)
}
saslClient := sasl.NewOAuthBearerClient(&sasl.OAuthBearerOptions{
Username: email,
Token: userAccountsCredentials.AccessToken,
})
// giving a time interval before connecting for other connection
if *countPointer > 0 {
time.Sleep(time.Second * 10)
} else {
*countPointer += 1
}
err = c.Authenticate(saslClient)
if err != nil {
if err.Error() == domain.ErrOauthBeararAccess { // error handloinig for oAuth bearer
usvc := useraccountcredentials.New(i.cfg, i.log)
_, err := usvc.RegenerateAccessToken(userAccountsUUID) //Function to regenerate token
if err != nil {
i.log.Error("unable to regenerate access token ", userAccountsUUID, err)
return nil, err
} // error handling for new token
time.Sleep(time.Second * 10) // sleep time before re-trying
return i.ConnectAndReturnClient(clientAddress, email, userAccountsUUID) // check here
}
return nil, err
}
i.log.Info("Auth done.....")
*countPointer = 0
return c, nil
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant