Nerzal / gocloak

golang keycloak client
Apache License 2.0
1.01k stars 275 forks source link

Login() success get token but Further calling the interface 403 Unkow err #445

Open xyjboys opened 1 year ago

xyjboys commented 1 year ago

Describe the bug A clear and concise description of what the bug is.

Cant use the GetRealmRoles methods. 403

To Reproduce

client := gocloak.NewClient("http://127.0.0.1:8080/auth") ctx := context.Background()

token, err := client.Login(ctx, "go-demo", "7VTxDxG4TOrtAert6FvjhMdcZKrYLyXz", "demo", "admin", "123456")
if err != nil {
    panic("Something wrong with the credentials or url")
}
fmt.Println(token)

rptResult, err := client.RetrospectToken(ctx, token.AccessToken, "go-demo", "7VTxDxG4TOrtAert6FvjhMdcZKrYLyXz", "demo")
if err != nil {
    panic("Inspection failed:" + err.Error())
}

if !*rptResult.Active {
    panic("Token is not active")
}

permissions := rptResult.Permissions
fmt.Println(permissions)

user, err := client.GetUserInfo(ctx, token.AccessToken, "demo")
fmt.Printf("user: %v\n", user)

users, err := client.GetRawUserInfo(ctx, token.AccessToken, "demo")
fmt.Printf("users: %v\n", users)

parmas := gocloak.GetRoleParams{}
roles, err := client.GetRealmRoles(ctx, token.AccessToken, "demo", parmas)
fmt.Printf("roles: %v\n", roles)

 for this demo i can login success and get the token userInfo  but  GetUserByID  err 403 

Expected behavior A clear and concise description of what you expected to happen.

200 status code response of GetUserByID user.

Screenshots 1693988385827

Additional context Add any other context about the problem here.

gocloak version: 13.8 keycloak version: 22.0.1-2