I am working with Gmail API in Go as backend. I made the Gmail sign-in authentication in front end using javascript and sending the auth-code to backend using AJAX Post method in localhost. In backend, I tried to get the Access tokens and Refresh tokens. I used Exchange function to do this. But I am getting the error "oauth2: token expired and refresh token is not set". The Go code for your reference
func GmailCallback(c *fiber.Ctx) error {
googleOauthConfig = &oauth2.Config{
RedirectURL: "callback_url",
ClientID: "XXXXX",
ClientSecret: "XXXXXXX",
Scopes: []string{"Scope1", "Scope2"},
Endpoint: google.Endpoint,
}
code := c.Query("code")
token, err := googleOauthConfig.Exchange(context.Background(), code)
if err != nil {
log.Println("Error",err)
}
return nil
}
I referred this page reference to create this flow : https://developers.google.com/identity/sign-in/web/server-side-flow
And also i found similar thread here in Node.js. But I do not know how to implement in Go.
It will be great if I get any help for this issue.