Skip to content

Commit 0f540c8

Browse files
authored
Add custom_attributes field to SSO Profile. (#360)
1 parent a418cc1 commit 0f540c8

File tree

4 files changed

+12
-3
lines changed

4 files changed

+12
-3
lines changed

lib/workos/profile.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ class Profile
1010
include HashProvider
1111

1212
attr_accessor :id, :email, :first_name, :last_name, :role, :groups, :organization_id,
13-
:connection_id, :connection_type, :idp_id, :raw_attributes
13+
:connection_id, :connection_type, :idp_id, :custom_attributes, :raw_attributes
1414

15+
# rubocop:disable Metrics/AbcSize
1516
def initialize(profile_json)
1617
hash = JSON.parse(profile_json, symbolize_names: true)
1718

@@ -25,8 +26,10 @@ def initialize(profile_json)
2526
@connection_id = hash[:connection_id]
2627
@connection_type = hash[:connection_type]
2728
@idp_id = hash[:idp_id]
29+
@custom_attributes = hash[:custom_attributes]
2830
@raw_attributes = hash[:raw_attributes]
2931
end
32+
# rubocop:enable Metrics/AbcSize
3033

3134
def full_name
3235
[first_name, last_name].compact.join(' ')
@@ -44,6 +47,7 @@ def to_json(*)
4447
connection_id: connection_id,
4548
connection_type: connection_type,
4649
idp_id: idp_id,
50+
custom_attributes: custom_attributes,
4751
raw_attributes: raw_attributes,
4852
}
4953
end

spec/lib/workos/sso_spec.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,7 @@
307307
},
308308
groups: nil,
309309
organization_id: 'org_01FG53X8636WSNW2WEKB2C31ZB',
310+
custom_attributes: {},
310311
raw_attributes: {
311312
312313
family_name: 'Loblaw',
@@ -381,13 +382,17 @@
381382
},
382383
groups: %w[Admins Developers],
383384
organization_id: 'org_01FG53X8636WSNW2WEKB2C31ZB',
385+
custom_attributes: {
386+
license: 'professional',
387+
},
384388
raw_attributes: {
385389
386390
first_name: 'WorkOS',
387391
id: 'prof_01DRA1XNSJDZ19A31F183ECQW5',
388392
idp_id: '00u1klkowm8EGah2H357',
389393
last_name: 'Demo',
390394
groups: %w[Admins Developers],
395+
license: 'professional',
391396
},
392397
}
393398

spec/support/fixtures/vcr_cassettes/sso/profile.yml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

spec/support/profile.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"profile":{"object":"profile","id":"prof_01DRA1XNSJDZ19A31F183ECQW5","email":"[email protected]","first_name":"WorkOS","organization_id":"org_01FG53X8636WSNW2WEKB2C31ZB","connection_id":"conn_01EMH8WAK20T42N2NBMNBCYHAG","connection_type":"OktaSAML","last_name":"Demo","role":{"slug": "admin"},"groups":["Admins","Developers"],"idp_id":"00u1klkowm8EGah2H357","raw_attributes":{"id":"prof_01DRA1XNSJDZ19A31F183ECQW5","email":"[email protected]","first_name":"WorkOS","last_name":"Demo","groups":["Admins","Developers"],"idp_id":"00u1klkowm8EGah2H357"}},"access_token":"01DVX6QBS3EG6FHY2ESAA5Q65X"}
1+
{"profile":{"object":"profile","id":"prof_01DRA1XNSJDZ19A31F183ECQW5","email":"[email protected]","first_name":"WorkOS","organization_id":"org_01FG53X8636WSNW2WEKB2C31ZB","connection_id":"conn_01EMH8WAK20T42N2NBMNBCYHAG","connection_type":"OktaSAML","last_name":"Demo","role":{"slug": "admin"},"groups":["Admins","Developers"],"idp_id":"00u1klkowm8EGah2H357","custom_attributes":{"license": "professional"},"raw_attributes":{"id":"prof_01DRA1XNSJDZ19A31F183ECQW5","email":"[email protected]","first_name":"WorkOS","last_name":"Demo","groups":["Admins","Developers"],"idp_id":"00u1klkowm8EGah2H357","license": "professional"}},"access_token":"01DVX6QBS3EG6FHY2ESAA5Q65X"}

0 commit comments

Comments
 (0)