I am trying to access a keycloak user authentication with below mentioned code.
package main
import (
“context”
“fmt”
"github.com/Nerzal/gocloak/v9"
)
func main() {
// Keycloak configuration
keycloak := gocloak.NewClient(“http://localhost:8080/auth”)
realm := “myrealm”
clientID := “myapp-client”
username := “myuser”
password := “user-password” // The user’s actual password
// Authenticate the user using ROPC (Resource Owner Password Credentials)
token, err := keycloak.Login(context.TODO(), clientID, clientSecret, realm, username, password)
if err != nil {
fmt.Println("Error authenticating:", err)
return
}
// Use the obtained access token for further API requests
fmt.Println("Access Token:", token.AccessToken)
}
however getting following error:
Error authenticating: 404 Not Found: RESTEASY003210: Could not find resource for full path: http://localhost:8080/auth/auth/realms/myrealm/protocol/openid-connect/token
Please help.