Skip to content

Commit

Permalink
Add the ability to specify invite type
Browse files Browse the repository at this point in the history
  • Loading branch information
dorsha committed Nov 1, 2023
1 parent 0580ecd commit 3b256f6
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
10 changes: 9 additions & 1 deletion descope/internal/mgmt/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,15 @@ func makeCreateUserRequest(loginID, email, phone, displayName, picture string, r
req["test"] = true
}
if options != nil {
req["inviteUrl"] = options.InviteURL
if len(options.InviteURL) > 0 {
req["inviteUrl"] = options.InviteURL
}
if options.SendMail != nil {
req["sendMail"] = *options.SendMail
}
if options.SendSMS != nil {
req["sendSMS"] = *options.SendSMS
}
}
return req
}
Expand Down
16 changes: 15 additions & 1 deletion descope/internal/mgmt/user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ func TestUserCreateSuccess(t *testing.T) {
"email": "[email protected]",
}}
ca := map[string]any{"ak": "av"}
i := 0
m := newTestMgmt(nil, helpers.DoOkWithBody(func(r *http.Request) {
require.Equal(t, r.Header.Get("Authorization"), "Bearer a:key")
req := map[string]any{}
Expand All @@ -27,6 +28,15 @@ func TestUserCreateSuccess(t *testing.T) {
require.Equal(t, "foo", roleNames[0])
require.Nil(t, req["test"])
assert.EqualValues(t, ca, req["customAttributes"])

if i == 2 {
assert.True(t, true, req["sendSMS"])
assert.EqualValues(t, false, req["sendMail"])
} else {
assert.Nil(t, req["sendSMS"])
assert.Nil(t, req["sendMail"])
}
i++
}, response))
user := &descope.UserRequest{}
user.Email = "[email protected]"
Expand All @@ -42,7 +52,9 @@ func TestUserCreateSuccess(t *testing.T) {
require.NotNil(t, res)
require.Equal(t, "[email protected]", res.Email)

res, err = m.User().Invite("abc", user, &descope.InviteOptions{InviteURL: "https://some.domain.com"})
sendSMS := true
sendMail := false
res, err = m.User().Invite("abc", user, &descope.InviteOptions{InviteURL: "https://some.domain.com", SendSMS: &sendSMS, SendMail: &sendMail})
require.NoError(t, err)
require.NotNil(t, res)
require.Equal(t, "[email protected]", res.Email)
Expand All @@ -66,6 +78,8 @@ func TestUserCreateSuccessWithOptions(t *testing.T) {
require.Nil(t, req["test"])
assert.EqualValues(t, ca, req["customAttributes"])
assert.EqualValues(t, "https://some.domain.com", req["inviteUrl"])
assert.Nil(t, req["sendMail"])
assert.Nil(t, req["sendSMS"])
}, response))
user := &descope.UserRequest{}
user.Email = "[email protected]"
Expand Down
2 changes: 2 additions & 0 deletions descope/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,8 @@ func NewToken(JWT string, token jwt.Token) *Token {

type InviteOptions struct {
InviteURL string `json:"inviteUrl,omitempty"`
SendMail *bool `json:"sendMail,omitempty"` // send invite via mail, default is according to project settings
SendSMS *bool `json:"sendSMS,omitempty"` // send invite via text message, default is according to project settings
}

type User struct {
Expand Down

0 comments on commit 3b256f6

Please sign in to comment.