Nerzal / gocloak

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

GetRealm has serialization error when realm is an empty string #470

Open Dmarcotrigiano opened 4 months ago

Dmarcotrigiano commented 4 months ago

Describe the bug A missing realm is an appropriate call to the API, it will retrieve all realms. The serialization of that fails due to the type expecting a non-empty string, and the API should only return one value.

To Reproduce Steps to reproduce the behavior:

  1. Create a bootstrap function that creates a default realm using environment variables.
  2. Do not populate the environment variable for realm.
  3. Before creating the default realm, check if the default realm exists.
  4. See response serialization error: could not get realm: json: cannot unmarshal array into Go value of type gocloak.RealmRepresentation

Expected behavior Malformed request error.

Additional context I have a bunch of environment variables and missed the guard for realm, burned a lot of time trying to figure out why the serialization wasn't working, until I saw that the call for GetRealms was the same but realm was an empty string.