Skip to content
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
9 changes: 6 additions & 3 deletions lib/workos/sso/profile.ex
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ defmodule WorkOS.SSO.Profile do
first_name: String.t() | nil,
last_name: String.t() | nil,
groups: [String.t()] | nil,
raw_attributes: %{String.t() => any()} | nil
raw_attributes: %{String.t() => any()} | nil,
custom_attributes: %{String.t() => any()} | nil
}

@enforce_keys [:id, :idp_id, :connection_id, :connection_type, :email]
Expand All @@ -29,7 +30,8 @@ defmodule WorkOS.SSO.Profile do
:first_name,
:last_name,
:groups,
:raw_attributes
:raw_attributes,
:custom_attributes
]

@impl true
Expand All @@ -45,7 +47,8 @@ defmodule WorkOS.SSO.Profile do
first_name: map["first_name"],
last_name: map["last_name"],
groups: map["groups"],
raw_attributes: map["raw_attributes"]
raw_attributes: map["raw_attributes"],
custom_attributes: map["custom_attributes"]
}
end
end
6 changes: 6 additions & 0 deletions test/support/sso_client_mock.ex
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ defmodule WorkOS.SSO.ClientMock do
"first_name" => "foo",
"last_name" => "bar",
"groups" => groups
},
"custom_attributes" => %{
"sid" => "S-1-5-21-1004336348-1177238915-682003330-512"
}
}
}
Expand Down Expand Up @@ -74,6 +77,9 @@ defmodule WorkOS.SSO.ClientMock do
"email" => "foo@test.com",
"first_name" => "foo",
"last_name" => "bar"
},
"custom_attributes" => %{
"sid" => "S-1-5-21-1004336348-1177238915-682003330-512"
}
}

Expand Down
24 changes: 24 additions & 0 deletions test/workos/sso_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,19 @@ defmodule WorkOS.SSOTest do
refute is_nil(access_token)
refute is_nil(profile)
end

test "casts custom_attributes from the profile response", context do
opts = [code: "authorization_code"]

context |> ClientMock.get_profile_and_token(assert_fields: opts)

assert {:ok, %WorkOS.SSO.ProfileAndToken{profile: profile}} =
WorkOS.SSO.get_profile_and_token(opts |> Keyword.get(:code))

assert profile.custom_attributes == %{
"sid" => "S-1-5-21-1004336348-1177238915-682003330-512"
}
end
end

describe "get_profile" do
Expand All @@ -158,6 +171,17 @@ defmodule WorkOS.SSOTest do

refute is_nil(id)
end

test "casts custom_attributes from the profile response", context do
opts = [access_token: "access_token"]

context |> ClientMock.get_profile(assert_fields: opts)

assert {:ok, %WorkOS.SSO.Profile{custom_attributes: custom_attributes}} =
WorkOS.SSO.get_profile(opts |> Keyword.get(:access_token))

assert custom_attributes == %{"sid" => "S-1-5-21-1004336348-1177238915-682003330-512"}
end
end

describe "get_connection" do
Expand Down
Loading