I have a web app written in Go, use oauth2 (package golang.org/x/oauth2
) to sign user in by Google (follow this tutorial https://developers.google.com/identity/sign-in/web/server-side-flow).
When I test app on local, it works fine but when I deploy app and run inside a Docker container (base on alpine:latest
, run binary file), it has an error:
Post https://accounts.google.com/o/oauth2/token: x509: certificate signed by unknown authority
Here is my code to exchange the accessToken:
ctx = context.Background()
config := &oauth2.Config{
ClientID: config.GoogleClientId,
ClientSecret: config.GoogleClientSecret,
RedirectURL: config.GoogleLoginRedirectUrl,
Endpoint: google.Endpoint,
Scopes: []string{"email", "profile"},
}
accessToken, err := config.Exchange(ctx, req.Code)
if err != nil {
log.Println(err.Error()) // Error here
}