diff --git a/pkg/sso/client.go b/pkg/sso/client.go index 4e7df0b5..35714bf0 100644 --- a/pkg/sso/client.go +++ b/pkg/sso/client.go @@ -5,14 +5,15 @@ import ( "encoding/json" "errors" "fmt" - "github.com/google/go-querystring/query" - "github.com/workos/workos-go/v4/pkg/workos_errors" "net/http" "net/url" "strings" "sync" "time" + "github.com/google/go-querystring/query" + "github.com/workos/workos-go/v4/pkg/workos_errors" + "github.com/workos/workos-go/v4/internal/workos" "github.com/workos/workos-go/v4/pkg/common" ) @@ -255,6 +256,9 @@ type Profile struct { // The user's group memberships. Can be empty. Groups []string `json:"groups"` + // The mapped custom attributes from the identity provider. Can be empty. + CustomAttributes map[string]interface{} `json:"custom_attributes"` + // The raw response of Profile attributes from the identity provider RawAttributes map[string]interface{} `json:"raw_attributes"` } diff --git a/pkg/sso/client_test.go b/pkg/sso/client_test.go index 4b275c66..8b6dd6e6 100644 --- a/pkg/sso/client_test.go +++ b/pkg/sso/client_test.go @@ -158,12 +158,16 @@ func TestClientGetProfileAndToken(t *testing.T) { Role: common.RoleResponse{ Slug: "admin", }, - Groups: []string{"Admins", "Developers"}, + Groups: []string{"Admins", "Developers"}, + CustomAttributes: map[string]interface{}{ + "license": "professional", + }, RawAttributes: map[string]interface{}{ "idp_id": "123", "email": "foo@test.com", "first_name": "foo", "last_name": "bar", + "license": "professional", }, }, }, @@ -223,12 +227,16 @@ func profileAndTokenTestHandler(w http.ResponseWriter, r *http.Request) { Role: common.RoleResponse{ Slug: "admin", }, - Groups: []string{"Admins", "Developers"}, + Groups: []string{"Admins", "Developers"}, + CustomAttributes: map[string]interface{}{ + "license": "professional", + }, RawAttributes: map[string]interface{}{ "idp_id": "123", "email": "foo@test.com", "first_name": "foo", "last_name": "bar", + "license": "professional", }, }, }) @@ -270,12 +278,16 @@ func TestClientGetProfile(t *testing.T) { Role: common.RoleResponse{ Slug: "admin", }, - Groups: []string{"Admins", "Developers"}, + Groups: []string{"Admins", "Developers"}, + CustomAttributes: map[string]interface{}{ + "license": "professional", + }, RawAttributes: map[string]interface{}{ "idp_id": "123", "email": "foo@test.com", "first_name": "foo", "last_name": "bar", + "license": "professional", }, }, }, @@ -325,12 +337,16 @@ func profileTestHandler(w http.ResponseWriter, r *http.Request) { Role: common.RoleResponse{ Slug: "admin", }, - Groups: []string{"Admins", "Developers"}, + Groups: []string{"Admins", "Developers"}, + CustomAttributes: map[string]interface{}{ + "license": "professional", + }, RawAttributes: map[string]interface{}{ "idp_id": "123", "email": "foo@test.com", "first_name": "foo", "last_name": "bar", + "license": "professional", }, }, ) diff --git a/pkg/sso/sso_test.go b/pkg/sso/sso_test.go index e017f178..05e13525 100644 --- a/pkg/sso/sso_test.go +++ b/pkg/sso/sso_test.go @@ -37,12 +37,16 @@ func TestLogin(t *testing.T) { Role: common.RoleResponse{ Slug: "admin", }, - Groups: []string{"Admins", "Developers"}, + Groups: []string{"Admins", "Developers"}, + CustomAttributes: map[string]interface{}{ + "license": "professional", + }, RawAttributes: map[string]interface{}{ "idp_id": "123", "email": "foo@test.com", "first_name": "foo", "last_name": "bar", + "license": "professional", }, } @@ -172,12 +176,16 @@ func TestSsoGetProfile(t *testing.T) { Role: common.RoleResponse{ Slug: "admin", }, - Groups: []string{"Admins", "Developers"}, + Groups: []string{"Admins", "Developers"}, + CustomAttributes: map[string]interface{}{ + "license": "professional", + }, RawAttributes: map[string]interface{}{ "idp_id": "123", "email": "foo@test.com", "first_name": "foo", "last_name": "bar", + "license": "professional", }, } profileResponse, err := GetProfile(context.Background(), GetProfileOpts{