-
Notifications
You must be signed in to change notification settings - Fork 69
Description
Checklist
- I agree to the terms within the Auth0 Code of Conduct.
Describe the problem you'd like to have solved
With the recent addition of Connection Attributes, we would like to make a call to Management API to delete a user's phone-number or email. We can do that by sending a PATCH call to the users-endpoint (https://auth0.com/docs/api/management/v2/users/patch-users-by-id), with the payload {"phone_number":null}
or {"email":null}
.
However, there is no way to achieve this when using the Auth0 Go SDK, by using the function User.Update
, since passing in a management.User
with Email
or PhoneNumber
set to nil
will marshal the struct to {}
, which will not delete the phone/email.
Describe the ideal solution
Some suggestions:
- The
management.User
could be changed/extended to allow explicitnull
in theUser.Update
-call User.Update
could take an option (e.g.option.DeletePhoneNumber()
,option.DeleteEmail()
) that would set the correct payload.- A separate
User.DeletePhone
andUser.DeleteEmail
(andUser.DeleteUsername
also?) could be added, which would send the required payload.
Alternatives and current workarounds
A workaround is to use NewRequest
and pass a payload that overrides the default Go marshalling, like:
type deletePhoneRequest struct{}
func (r deletePhoneRequest) MarshalJSON() ([]byte, error) {
return []byte(`{"phone_number":null}`), nil
}
This requires us to manually handle the path to the PATCH-endpoint, and handling the status-code and closing of body, etc. manually.
Additional context
No response