cognito_rails 1.5.0 → 1.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/cognito_rails/model.rb +10 -3
- data/lib/cognito_rails/version.rb +1 -1
- data/spec/cognito_rails/user_spec.rb +12 -0
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: ba2d4e841753b9cd8ee9405f3cf611d55c69d59ba308278b5571a8f2000fab95
|
|
4
|
+
data.tar.gz: cfe2bed1bc6691c2b66cd0a1ee4abd25356f7a18cf02f3a0d051207d632f52ee
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b68f5ce7e60a6f1429062666aa2632902276e004d62ede96706b7adceda29d5d7c6103b352a718e47bad39380fd41be57b24326e4f2b7009b44612d9d7e83ae1
|
|
7
|
+
data.tar.gz: 26912cfe1cfb2aa7d2d26a579766fa28a2d03d0ae52eafc5be1a669168c7073b5b29cb17a61763a2657e8a87112462e7d92e113578f3711da602deaba370c82e
|
data/lib/cognito_rails/model.rb
CHANGED
|
@@ -50,6 +50,13 @@ module CognitoRails
|
|
|
50
50
|
end
|
|
51
51
|
end
|
|
52
52
|
|
|
53
|
+
def sync_from_cognito_id!(external_id)
|
|
54
|
+
user_data = User.with_credentials(self).find_raw(external_id)
|
|
55
|
+
sync_user!(user_data) do |user|
|
|
56
|
+
yield user, user_data if block_given?
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
|
|
53
60
|
private
|
|
54
61
|
|
|
55
62
|
def sync_user!(user_data)
|
|
@@ -57,8 +64,9 @@ module CognitoRails
|
|
|
57
64
|
return if external_id.blank?
|
|
58
65
|
|
|
59
66
|
user = find_or_initialize_by(_cognito_attribute_name => external_id)
|
|
60
|
-
|
|
61
|
-
user.
|
|
67
|
+
attributes = user_data.respond_to?(:attributes) ? user_data.attributes : user_data.user_attributes
|
|
68
|
+
user.email = User.extract_cognito_attribute(attributes, :email)
|
|
69
|
+
user.phone = User.extract_cognito_attribute(attributes, :phone_number) if user.respond_to?(:phone)
|
|
62
70
|
_cognito_resolve_custom_attribute(user, user_data)
|
|
63
71
|
|
|
64
72
|
yield user if block_given?
|
|
@@ -134,7 +142,6 @@ module CognitoRails
|
|
|
134
142
|
|
|
135
143
|
def cognito_scope
|
|
136
144
|
@cognito_scope ||= User.with_credentials(self.class)
|
|
137
|
-
|
|
138
145
|
end
|
|
139
146
|
|
|
140
147
|
class_methods do
|
|
@@ -200,6 +200,18 @@ RSpec.describe CognitoRails::User, type: :model do
|
|
|
200
200
|
end
|
|
201
201
|
end
|
|
202
202
|
|
|
203
|
+
context '#sync_from_cognito_id!' do
|
|
204
|
+
before do
|
|
205
|
+
expect(fake_cognito_client).to receive(:admin_get_user)
|
|
206
|
+
.and_return(build_cognito_user_data(sample_cognito_email))
|
|
207
|
+
end
|
|
208
|
+
it 'imports the user correctly' do
|
|
209
|
+
user = User.sync_from_cognito_id!(sample_cognito_id)
|
|
210
|
+
expect(user).to be_a(User)
|
|
211
|
+
expect(user.email).to eq(sample_cognito_email)
|
|
212
|
+
end
|
|
213
|
+
end
|
|
214
|
+
|
|
203
215
|
it '#sync_to_cognito!' do
|
|
204
216
|
User.create!(email: sample_cognito_email)
|
|
205
217
|
|