Skip to content

Commit 99fb717

Browse files
authored
Add custom_attributes field to SSO Profile. (#422)
1 parent 73d050e commit 99fb717

File tree

3 files changed

+36
-8
lines changed

3 files changed

+36
-8
lines changed

pkg/sso/client.go

+6-2
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@ import (
55
"encoding/json"
66
"errors"
77
"fmt"
8-
"github.com/google/go-querystring/query"
9-
"github.com/workos/workos-go/v4/pkg/workos_errors"
108
"net/http"
119
"net/url"
1210
"strings"
1311
"sync"
1412
"time"
1513

14+
"github.com/google/go-querystring/query"
15+
"github.com/workos/workos-go/v4/pkg/workos_errors"
16+
1617
"github.com/workos/workos-go/v4/internal/workos"
1718
"github.com/workos/workos-go/v4/pkg/common"
1819
)
@@ -255,6 +256,9 @@ type Profile struct {
255256
// The user's group memberships. Can be empty.
256257
Groups []string `json:"groups"`
257258

259+
// The mapped custom attributes from the identity provider. Can be empty.
260+
CustomAttributes map[string]interface{} `json:"custom_attributes"`
261+
258262
// The raw response of Profile attributes from the identity provider
259263
RawAttributes map[string]interface{} `json:"raw_attributes"`
260264
}

pkg/sso/client_test.go

+20-4
Original file line numberDiff line numberDiff line change
@@ -158,12 +158,16 @@ func TestClientGetProfileAndToken(t *testing.T) {
158158
Role: common.RoleResponse{
159159
Slug: "admin",
160160
},
161-
Groups: []string{"Admins", "Developers"},
161+
Groups: []string{"Admins", "Developers"},
162+
CustomAttributes: map[string]interface{}{
163+
"license": "professional",
164+
},
162165
RawAttributes: map[string]interface{}{
163166
"idp_id": "123",
164167
"email": "[email protected]",
165168
"first_name": "foo",
166169
"last_name": "bar",
170+
"license": "professional",
167171
},
168172
},
169173
},
@@ -223,12 +227,16 @@ func profileAndTokenTestHandler(w http.ResponseWriter, r *http.Request) {
223227
Role: common.RoleResponse{
224228
Slug: "admin",
225229
},
226-
Groups: []string{"Admins", "Developers"},
230+
Groups: []string{"Admins", "Developers"},
231+
CustomAttributes: map[string]interface{}{
232+
"license": "professional",
233+
},
227234
RawAttributes: map[string]interface{}{
228235
"idp_id": "123",
229236
"email": "[email protected]",
230237
"first_name": "foo",
231238
"last_name": "bar",
239+
"license": "professional",
232240
},
233241
},
234242
})
@@ -270,12 +278,16 @@ func TestClientGetProfile(t *testing.T) {
270278
Role: common.RoleResponse{
271279
Slug: "admin",
272280
},
273-
Groups: []string{"Admins", "Developers"},
281+
Groups: []string{"Admins", "Developers"},
282+
CustomAttributes: map[string]interface{}{
283+
"license": "professional",
284+
},
274285
RawAttributes: map[string]interface{}{
275286
"idp_id": "123",
276287
"email": "[email protected]",
277288
"first_name": "foo",
278289
"last_name": "bar",
290+
"license": "professional",
279291
},
280292
},
281293
},
@@ -325,12 +337,16 @@ func profileTestHandler(w http.ResponseWriter, r *http.Request) {
325337
Role: common.RoleResponse{
326338
Slug: "admin",
327339
},
328-
Groups: []string{"Admins", "Developers"},
340+
Groups: []string{"Admins", "Developers"},
341+
CustomAttributes: map[string]interface{}{
342+
"license": "professional",
343+
},
329344
RawAttributes: map[string]interface{}{
330345
"idp_id": "123",
331346
"email": "[email protected]",
332347
"first_name": "foo",
333348
"last_name": "bar",
349+
"license": "professional",
334350
},
335351
},
336352
)

pkg/sso/sso_test.go

+10-2
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,16 @@ func TestLogin(t *testing.T) {
3737
Role: common.RoleResponse{
3838
Slug: "admin",
3939
},
40-
Groups: []string{"Admins", "Developers"},
40+
Groups: []string{"Admins", "Developers"},
41+
CustomAttributes: map[string]interface{}{
42+
"license": "professional",
43+
},
4144
RawAttributes: map[string]interface{}{
4245
"idp_id": "123",
4346
"email": "[email protected]",
4447
"first_name": "foo",
4548
"last_name": "bar",
49+
"license": "professional",
4650
},
4751
}
4852

@@ -172,12 +176,16 @@ func TestSsoGetProfile(t *testing.T) {
172176
Role: common.RoleResponse{
173177
Slug: "admin",
174178
},
175-
Groups: []string{"Admins", "Developers"},
179+
Groups: []string{"Admins", "Developers"},
180+
CustomAttributes: map[string]interface{}{
181+
"license": "professional",
182+
},
176183
RawAttributes: map[string]interface{}{
177184
"idp_id": "123",
178185
"email": "[email protected]",
179186
"first_name": "foo",
180187
"last_name": "bar",
188+
"license": "professional",
181189
},
182190
}
183191
profileResponse, err := GetProfile(context.Background(), GetProfileOpts{

0 commit comments

Comments
 (0)