Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add method to unlink a users identity #35

Merged
merged 3 commits into from
Apr 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions management/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,14 @@ func (m *UserManager) Link(id string, il *UserIdentityLink, opts ...RequestOptio
return uIDs, nil
}

// Unlink unlinks an identity from a user making it a separate account again.
//
// See: https://auth0.com/docs/api/management/v2#!/Users/delete_user_identity_by_user_id
func (m *UserManager) Unlink(id, provider, userID string, opts ...RequestOption) (uIDs []UserIdentity, err error) {
err = m.Request("DELETE", m.URI("users", id, "identities", provider, userID), &uIDs, opts...)
return
}

// Organizations lists user's organizations.
//
// See: https://auth0.com/docs/api/management/v2#!/Users/get_organizations
Expand Down
57 changes: 57 additions & 0 deletions management/user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package management

import (
"encoding/json"
"strings"
"testing"
"time"

Expand Down Expand Up @@ -369,6 +370,62 @@ func TestUser(t *testing.T) {
m.User.Delete(batman.GetID())
})
})

t.Run("Unlink", func(t *testing.T) {
cs, err := m.Connection.ReadByName("Username-Password-Authentication")
if err != nil {
t.Error(err)
}

mainUser := &User{
Email: auth0.String("[email protected]"),
Username: auth0.String("main_user"),
Password: auth0.String("NF2QZxci3Z5NikLRoHcAu3H5"),
Connection: cs.Name,
}
if err := m.User.Create(mainUser); err != nil {
t.Error(err)
}

secondaryUser := &User{
Email: auth0.String("[email protected]"),
Username: auth0.String("secondary_user"),
Password: auth0.String("Ta9Y95PNbiCummJ3zpzCtEYy"),
Connection: cs.Name,
}
if err := m.User.Create(secondaryUser); err != nil {
t.Error(err)
}

linkedIdentities, err := m.User.Link(mainUser.GetID(), &UserIdentityLink{
Provider: auth0.String("auth0"),
UserID: secondaryUser.ID,
ConnectionID: cs.ID,
})
if err != nil {
t.Error(err)
}
jsonLinkedIdentities, err := json.Marshal(linkedIdentities)
if err != nil {
t.Error(err)
}
t.Logf("%v\n", string(jsonLinkedIdentities))

unlinkedIdentities, err := m.User.Unlink(mainUser.GetID(), "auth0", strings.TrimPrefix(secondaryUser.GetID(), "auth0|"))
if err != nil {
t.Error(err)
}
jsonUnlinkedIdentities, err := json.Marshal(unlinkedIdentities)
if err != nil {
t.Error(err)
}
t.Logf("%v\n", string(jsonUnlinkedIdentities))

t.Cleanup(func() {
m.User.Delete(mainUser.GetID())
m.User.Delete(secondaryUser.GetID())
})
})
}

func TestUserIdentity(t *testing.T) {
Expand Down