Skip to content

Commit

Permalink
Add 'password_hash' and 'password_hash_type' to User creation
Browse files Browse the repository at this point in the history
  • Loading branch information
amadeo-workos committed Apr 5, 2024
1 parent 41befc1 commit e958f14
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 6 deletions.
2 changes: 1 addition & 1 deletion internal/workos/workos.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ package workos

const (
// Version represents the SDK version number.
Version = "v4.4.1"
Version = "v4.4.2"
)
12 changes: 7 additions & 5 deletions pkg/usermanagement/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,11 +173,13 @@ type ListUsersOpts struct {
}

type CreateUserOpts struct {
Email string `json:"email"`
Password string `json:"password,omitempty"`
FirstName string `json:"first_name,omitempty"`
LastName string `json:"last_name,omitempty"`
EmailVerified bool `json:"email_verified,omitempty"`
Email string `json:"email"`
Password string `json:"password,omitempty"`
PasswordHash string `json:"password_hash,omitempty"`
PasswordHashType PasswordHashType `json:"password_hash_type,omitempty"`
FirstName string `json:"first_name,omitempty"`
LastName string `json:"last_name,omitempty"`
EmailVerified bool `json:"email_verified,omitempty"`
}

// The algorithm originally used to hash the password.
Expand Down
31 changes: 31 additions & 0 deletions pkg/usermanagement/usermanagement_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,37 @@ func TestUserManagementCreateUser(t *testing.T) {
require.Equal(t, expectedResponse, userRes)
}

func TestUserManagementCreateUserPasswordHash(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(createUserTestHandler))
defer server.Close()

DefaultClient = mockClient(server)

SetAPIKey("test")

expectedResponse := User{
ID: "user_01E3JC5F5Z1YJNPGVYWV9SX6GH",
Email: "[email protected]",
FirstName: "Marcelina",
LastName: "Davis",
EmailVerified: true,
CreatedAt: "2021-06-25T19:07:33.155Z",
UpdatedAt: "2021-06-25T19:07:33.155Z",
}

userRes, err := CreateUser(context.Background(), CreateUserOpts{
Email: "[email protected]",
FirstName: "Marcelina",
LastName: "Davis",
EmailVerified: true,
PasswordHash: "$2b$10$dXS6RadWKYIqs6vOwqKZceLuCIqz6S81t06.yOkGJbbfeO9go4fai",
PasswordHashType: "bcrypt",
})

require.NoError(t, err)
require.Equal(t, expectedResponse, userRes)
}

func TestUserManagementUpdateUser(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(updateUserTestHandler))
defer server.Close()
Expand Down

0 comments on commit e958f14

Please sign in to comment.