go-client icon indicating copy to clipboard operation
go-client copied to clipboard

Application registration for an existing user fails

Open TeddyPaddington opened this issue 3 years ago • 6 comments

Application registration for an existing user fails due to the non-nillable user field in the RegistrationRequest struct. Change User type property to a pointer

TeddyPaddington avatar Feb 09 '22 13:02 TeddyPaddington

Thanks for the patch, @TeddyPaddington !

Unfortunately I can't merge it directly, as that domain object is built by inspecting some java objects. We'll have to find some way to upstream the change.

I'm no go expert; can you please show me how this change affects making a go client call? That's been one reason I haven't tried to fix this, I'm not sure how to test whether it'd be a breaking change or not.

mooreds avatar Feb 09 '22 16:02 mooreds

Ran into the same problem. The reason for the bug is that the User object is embedded into the RegistrationRequest and the json encoder cannot determine that it is empty, so it serializes it with empty fields into the request and it's then rejected by the server.

Two other solutions are to create a separate RegistrationWithExistingUserRequest (presumably in the java source) or to change the server so it ignores the User object if it only has empty fields.

ziemek avatar Jun 23 '22 15:06 ziemek

Just ran into this issue today.

as that domain object is built by inspecting some java objects.

@mooreds you're saying the Go code is generated from Java objects? To your earlier question, Go struct fields don't have a nil value possible by default. The default/zero value is an empty struct, so if I say

//create new request 
req := fusionAuth.RegistrationRequest{}

it's equivalent to saying

//create new request 
req := fusionAuth.RegistrationRequest{
    User: fusionAuth.User{}
}

When that gets marshaled to JSON, it looks like:

{
    "user": {}
}

Which, because not null, is getting validated for fields. Making this PR change allows the User field to have a nil value which is marshaled as { "user": null } and allows the client call to succeed.

I wrote a custom function in my local app to use a copied request struct (with this change) that mirrors the existing Register() function and it works like a champ.

mshap avatar Aug 01 '23 00:08 mshap

Merge it

smilad avatar Oct 17 '23 18:10 smilad

Thanks @smilad . We need to take a look at this, but unfortunately are busy with some other things internally (new release, documentation overhaul). Hopefully we can get to this in the next month or two. Sorry for the delay!

mooreds avatar Oct 23 '23 11:10 mooreds

Hi guys, any update on this? We're facing the same issue

mirobertod avatar Mar 04 '24 17:03 mirobertod