我有一个用Go编写的Web应用程序,使用oauth2(包
golang.org/x/oauth2
)通过Google登录用户(请按照此教程进行:https://developers.google.com/identity/sign-in/web/server-side-flow)。在本地测试应用程序时,它可以正常工作,但是当我在Docker容器中部署应用程序并运行二进制文件时(基于alpine:latest
),它会出现错误:Post https://accounts.google.com/o/oauth2/token: x509: certificate signed by unknown authority
。这是我的代码以交换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
}
ca-certificates
。 - Peter