如何在gocloak中跳过(X509)证书验证?

5 go keycloak

我正在尝试使用gocloak从 keycloak 验证我的令牌,并为此使用以下代码。

token:=""
client:= gocloak.NewClient("https://example.com")
_, err := client.RetrospectToken(token,"client-id" ,"client-secret", "realm")
log.Print(err.Error())
Run Code Online (Sandbox Code Playgroud)

我遇到以下错误,

Post https://example.com/auth/realms/realm/protocol/openid-connect/token/introspect: x509: certificate signed by unknown authority

有什么办法可以跳过 gocloak 中的证书验证吗?

小智 4

因此,您正在寻找跳过 TLS 中的证书验证的方法,请尝试使用RestyClient

token:=""
client := gocloak.NewClient(serverURL)
restyClient := client.RestyClient()
restyClient.SetDebug(true)
restyClient.SetTLSClientConfig(&tls.Config{ InsecureSkipVerify: true })
_, err := client.RetrospectToken(token,"client-id" ,"client-secret", "realm")
log.Print(err.Error())
Run Code Online (Sandbox Code Playgroud)