Cannot exchange AccessToken from Google API inside Docker container

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



Cannot exchange AccessToken from Google API inside Docker container



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).


golang.org/x/oauth2



When I test app on local, it works fine but when I deploy app and run inside a Docker container (base on golang:alpine), it has an error:
Post https://accounts.google.com/o/oauth2/token: x509: certificate signed by unknown authority


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




1 Answer
1



You will need to add the Google Issuing CA certificate to the trusted cert store of the docker image.



The Google CA cert is this https://pki.google.com/GIAG2.crt .



More info on the certificate can be found from here



Then within the Dockerfile , you will need to do something like this


cp GIAG2.crt /usr/local/share/ca-certificates/GIAG2.crt
update-ca-certificates






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

How to determine optimal route across keyboard