diff --git a/lib/workos/profile.rb b/lib/workos/profile.rb index f3c075a0..3a02ac62 100644 --- a/lib/workos/profile.rb +++ b/lib/workos/profile.rb @@ -10,8 +10,9 @@ class Profile include HashProvider attr_accessor :id, :email, :first_name, :last_name, :role, :groups, :organization_id, - :connection_id, :connection_type, :idp_id, :raw_attributes + :connection_id, :connection_type, :idp_id, :custom_attributes, :raw_attributes + # rubocop:disable Metrics/AbcSize def initialize(profile_json) hash = JSON.parse(profile_json, symbolize_names: true) @@ -25,8 +26,10 @@ def initialize(profile_json) @connection_id = hash[:connection_id] @connection_type = hash[:connection_type] @idp_id = hash[:idp_id] + @custom_attributes = hash[:custom_attributes] @raw_attributes = hash[:raw_attributes] end + # rubocop:enable Metrics/AbcSize def full_name [first_name, last_name].compact.join(' ') @@ -44,6 +47,7 @@ def to_json(*) connection_id: connection_id, connection_type: connection_type, idp_id: idp_id, + custom_attributes: custom_attributes, raw_attributes: raw_attributes, } end diff --git a/spec/lib/workos/sso_spec.rb b/spec/lib/workos/sso_spec.rb index 2703e358..d3037e63 100644 --- a/spec/lib/workos/sso_spec.rb +++ b/spec/lib/workos/sso_spec.rb @@ -307,6 +307,7 @@ }, groups: nil, organization_id: 'org_01FG53X8636WSNW2WEKB2C31ZB', + custom_attributes: {}, raw_attributes: { email: 'bob.loblaw@workos.com', family_name: 'Loblaw', @@ -381,6 +382,9 @@ }, groups: %w[Admins Developers], organization_id: 'org_01FG53X8636WSNW2WEKB2C31ZB', + custom_attributes: { + license: 'professional', + }, raw_attributes: { email: 'demo@workos-okta.com', first_name: 'WorkOS', @@ -388,6 +392,7 @@ idp_id: '00u1klkowm8EGah2H357', last_name: 'Demo', groups: %w[Admins Developers], + license: 'professional', }, } diff --git a/spec/support/fixtures/vcr_cassettes/sso/profile.yml b/spec/support/fixtures/vcr_cassettes/sso/profile.yml index 70e29abf..65d6dec3 100644 --- a/spec/support/fixtures/vcr_cassettes/sso/profile.yml +++ b/spec/support/fixtures/vcr_cassettes/sso/profile.yml @@ -67,7 +67,7 @@ http_interactions: body: encoding: UTF-8 string: - '{"object":"profile","id":"prof_01EEJTY9SZ1R350RB7B73SNBKF","organization_id":"org_01FG53X8636WSNW2WEKB2C31ZB","connection_id":"conn_01E83FVYZHY7DM4S9503JHV0R5","connection_type":"GoogleOAuth","idp_id":"116485463307139932699","email":"bob.loblaw@workos.com","first_name":"Bob","last_name":"Loblaw","role":{"slug":"member"},"raw_attributes":{"hd":"workos.com","id":"116485463307139932699","name":"Bob + '{"object":"profile","id":"prof_01EEJTY9SZ1R350RB7B73SNBKF","organization_id":"org_01FG53X8636WSNW2WEKB2C31ZB","connection_id":"conn_01E83FVYZHY7DM4S9503JHV0R5","connection_type":"GoogleOAuth","idp_id":"116485463307139932699","email":"bob.loblaw@workos.com","first_name":"Bob","last_name":"Loblaw","role":{"slug":"member"},"custom_attributes":{},"raw_attributes":{"hd":"workos.com","id":"116485463307139932699","name":"Bob Loblaw","email":"bob.loblaw@workos.com","locale":"en","picture":"https://lh3.googleusercontent.com/a-/AOh14GyO2hLlgZvteDQ3Ldi3_-RteZLya0hWH7247Cam=s96-c","given_name":"Bob","family_name":"Loblaw","verified_email":true}}' http_version: recorded_at: Tue, 18 May 2021 22:55:21 GMT diff --git a/spec/support/profile.txt b/spec/support/profile.txt index 796a201e..7e19a262 100644 --- a/spec/support/profile.txt +++ b/spec/support/profile.txt @@ -1 +1 @@ -{"profile":{"object":"profile","id":"prof_01DRA1XNSJDZ19A31F183ECQW5","email":"demo@workos-okta.com","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":"demo@workos-okta.com","first_name":"WorkOS","last_name":"Demo","groups":["Admins","Developers"],"idp_id":"00u1klkowm8EGah2H357"}},"access_token":"01DVX6QBS3EG6FHY2ESAA5Q65X"} +{"profile":{"object":"profile","id":"prof_01DRA1XNSJDZ19A31F183ECQW5","email":"demo@workos-okta.com","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":"demo@workos-okta.com","first_name":"WorkOS","last_name":"Demo","groups":["Admins","Developers"],"idp_id":"00u1klkowm8EGah2H357","license": "professional"}},"access_token":"01DVX6QBS3EG6FHY2ESAA5Q65X"}