authing_ruby 1.0.9 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/authing_ruby/authentication/AuthenticationClient.rb +43 -61
- data/lib/authing_ruby/common/GraphqlClient.rb +7 -9
- data/lib/authing_ruby/test/mini_test/TestAuthenticationClient.rb +9 -6
- data/lib/authing_ruby/test/mini_test/TestManagementClient.rb +2 -2
- data/lib/authing_ruby/version.rb +1 -1
- 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: aa6593330f870f1b2559fe53cbeb0ed09a06cff11a5c79ea728d328a57136f58
|
4
|
+
data.tar.gz: a037af3385879a07abb47ab49b23712944b0999ace92d9d291bc4a701d090eff
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fd1b2564b11854460730bafe77947659f0ef22b97ee5be871549882837eee2cea373f9fc7303843e044a22d37d93829a95c347c4a4e4216a484470337857dc51
|
7
|
+
data.tar.gz: cbb759903d06dbb5be96d472f32c713983efb56ad736460a4c880f898343fe99d4aaa63cbceefe073ef69cc2e7309c1c0667734f9af588cbcddf78cc295aa324
|
@@ -68,11 +68,10 @@ module AuthingRuby
|
|
68
68
|
}
|
69
69
|
}
|
70
70
|
graphqlAPI = AuthingRuby::GraphQLAPI.new
|
71
|
-
|
72
|
-
|
73
|
-
user = json.dig('data', 'registerByEmail')
|
71
|
+
hash = graphqlAPI.registerByEmail(@graphqlClient, variables)
|
72
|
+
user = hash.dig('data', 'registerByEmail')
|
74
73
|
return user if user
|
75
|
-
return
|
74
|
+
return hash
|
76
75
|
end
|
77
76
|
|
78
77
|
# 使用用户名注册
|
@@ -96,11 +95,10 @@ module AuthingRuby
|
|
96
95
|
}
|
97
96
|
}
|
98
97
|
graphqlAPI = AuthingRuby::GraphQLAPI.new
|
99
|
-
|
100
|
-
|
101
|
-
user = json.dig('data', 'registerByUsername')
|
98
|
+
hash = graphqlAPI.registerByUsername(@graphqlClient, variables)
|
99
|
+
user = hash.dig('data', 'registerByUsername')
|
102
100
|
return user if user
|
103
|
-
return
|
101
|
+
return hash
|
104
102
|
end
|
105
103
|
|
106
104
|
# 发送短信验证码
|
@@ -138,14 +136,10 @@ module AuthingRuby
|
|
138
136
|
}
|
139
137
|
}
|
140
138
|
graphqlAPI = AuthingRuby::GraphQLAPI.new
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
return user if user
|
146
|
-
return json
|
147
|
-
end
|
148
|
-
return res
|
139
|
+
hash = graphqlAPI.registerByPhoneCode(@graphqlClient, variables)
|
140
|
+
user = hash.dig('data', 'registerByPhoneCode')
|
141
|
+
return user if user
|
142
|
+
return hash
|
149
143
|
end
|
150
144
|
|
151
145
|
# 使用邮箱登录
|
@@ -166,14 +160,13 @@ module AuthingRuby
|
|
166
160
|
}
|
167
161
|
}
|
168
162
|
graphqlAPI = AuthingRuby::GraphQLAPI.new
|
169
|
-
|
170
|
-
|
171
|
-
user = json.dig('data', 'loginByEmail')
|
163
|
+
hash = graphqlAPI.loginByEmail(@graphqlClient, variables)
|
164
|
+
user = hash.dig('data', 'loginByEmail')
|
172
165
|
if user
|
173
166
|
setCurrentUser(user);
|
174
167
|
return user
|
175
168
|
end
|
176
|
-
return
|
169
|
+
return hash
|
177
170
|
end
|
178
171
|
|
179
172
|
# 使用用户名登录
|
@@ -194,14 +187,13 @@ module AuthingRuby
|
|
194
187
|
}
|
195
188
|
}
|
196
189
|
graphqlAPI = AuthingRuby::GraphQLAPI.new
|
197
|
-
|
198
|
-
|
199
|
-
user = json.dig('data', 'loginByUsername')
|
190
|
+
hash = graphqlAPI.loginByUsername(@graphqlClient, variables)
|
191
|
+
user = hash.dig('data', 'loginByUsername')
|
200
192
|
if user
|
201
193
|
setCurrentUser(user);
|
202
194
|
return user
|
203
195
|
end
|
204
|
-
return
|
196
|
+
return hash
|
205
197
|
end
|
206
198
|
|
207
199
|
# 使用手机号验证码登录
|
@@ -218,14 +210,13 @@ module AuthingRuby
|
|
218
210
|
}
|
219
211
|
}
|
220
212
|
graphqlAPI = AuthingRuby::GraphQLAPI.new
|
221
|
-
|
222
|
-
|
223
|
-
user = json.dig('data', 'loginByPhoneCode')
|
213
|
+
hash = graphqlAPI.loginByPhoneCode(@graphqlClient, variables)
|
214
|
+
user = hash.dig('data', 'loginByPhoneCode')
|
224
215
|
if user
|
225
216
|
setCurrentUser(user);
|
226
217
|
return user
|
227
218
|
end
|
228
|
-
return
|
219
|
+
return hash
|
229
220
|
end
|
230
221
|
|
231
222
|
# 使用手机号密码登录
|
@@ -245,14 +236,13 @@ module AuthingRuby
|
|
245
236
|
}
|
246
237
|
}
|
247
238
|
graphqlAPI = AuthingRuby::GraphQLAPI.new
|
248
|
-
|
249
|
-
|
250
|
-
user = json.dig('data', 'loginByPhonePassword')
|
239
|
+
hash = graphqlAPI.loginByPhonePassword(@graphqlClient, variables)
|
240
|
+
user = hash.dig('data', 'loginByPhonePassword')
|
251
241
|
if user
|
252
242
|
setCurrentUser(user);
|
253
243
|
return user
|
254
244
|
end
|
255
|
-
return
|
245
|
+
return hash
|
256
246
|
end
|
257
247
|
|
258
248
|
# 发送邮件
|
@@ -265,11 +255,10 @@ module AuthingRuby
|
|
265
255
|
"scene": scene,
|
266
256
|
}
|
267
257
|
graphqlAPI = AuthingRuby::GraphQLAPI.new
|
268
|
-
|
269
|
-
|
270
|
-
data = json.dig('data')
|
258
|
+
hash = graphqlAPI.sendEmail(@graphqlClient, variables)
|
259
|
+
data = hash.dig('data')
|
271
260
|
return data if data
|
272
|
-
return
|
261
|
+
return hash
|
273
262
|
# {"sendEmail":{"message":"","code":200}}
|
274
263
|
end
|
275
264
|
|
@@ -277,14 +266,13 @@ module AuthingRuby
|
|
277
266
|
# 返回:用户信息
|
278
267
|
def getCurrentUser()
|
279
268
|
graphqlAPI = AuthingRuby::GraphQLAPI.new
|
280
|
-
|
281
|
-
|
282
|
-
user = json.dig("data", "user")
|
269
|
+
hash = graphqlAPI.getCurrentUser(@graphqlClient, @tokenProvider, {})
|
270
|
+
user = hash.dig("data", "user")
|
283
271
|
if user
|
284
272
|
setCurrentUser(user)
|
285
273
|
return user
|
286
274
|
else
|
287
|
-
return
|
275
|
+
return hash
|
288
276
|
end
|
289
277
|
end
|
290
278
|
|
@@ -609,9 +597,8 @@ module AuthingRuby
|
|
609
597
|
"id": userId,
|
610
598
|
"input": updates
|
611
599
|
}
|
612
|
-
|
613
|
-
|
614
|
-
updated_user = json.dig('data', 'updateUser')
|
600
|
+
hash = graphqlAPI.updateUser(@graphqlClient, @tokenProvider, variables)
|
601
|
+
updated_user = hash.dig('data', 'updateUser')
|
615
602
|
if updated_user
|
616
603
|
# 如果更新成功,返回更新后的用户
|
617
604
|
setCurrentUser(updated_user)
|
@@ -619,7 +606,7 @@ module AuthingRuby
|
|
619
606
|
else
|
620
607
|
# 如果更新失败,返回原结果
|
621
608
|
# {"errors"=>[{"message"=>{"code"=>2020, "message"=>"尚未登录,无访问权限"}, "locations"=>[{"line"=>2, "column"=>3}], "path"=>["updateUser"], "extensions"=>{"code"=>"INTERNAL_SERVER_ERROR"}}], "data"=>nil}
|
622
|
-
return
|
609
|
+
return hash
|
623
610
|
end
|
624
611
|
end
|
625
612
|
|
@@ -661,18 +648,16 @@ module AuthingRuby
|
|
661
648
|
def checkPasswordStrength(password)
|
662
649
|
graphqlAPI = AuthingRuby::GraphQLAPI.new
|
663
650
|
variables = { "password": password }
|
664
|
-
|
665
|
-
|
666
|
-
return json.dig("data", "checkPasswordStrength")
|
651
|
+
hash = graphqlAPI.checkPasswordStrength(@graphqlClient, @tokenProvider, variables)
|
652
|
+
return hash.dig("data", "checkPasswordStrength")
|
667
653
|
end
|
668
654
|
|
669
655
|
# 检测 Token 登录状态
|
670
656
|
def checkLoginStatus(token)
|
671
657
|
graphqlAPI = AuthingRuby::GraphQLAPI.new
|
672
658
|
variables = { "token": token }
|
673
|
-
|
674
|
-
|
675
|
-
return json.dig("data", "checkLoginStatus")
|
659
|
+
hash = graphqlAPI.checkLoginStatus(@graphqlClient, @tokenProvider, variables)
|
660
|
+
return hash.dig("data", "checkLoginStatus")
|
676
661
|
end
|
677
662
|
|
678
663
|
# 更新用户密码
|
@@ -685,9 +670,8 @@ module AuthingRuby
|
|
685
670
|
"oldPassword": oldPasswordEncrypted,
|
686
671
|
}
|
687
672
|
graphqlAPI = AuthingRuby::GraphQLAPI.new
|
688
|
-
|
689
|
-
|
690
|
-
return json.dig("data", "updatePassword")
|
673
|
+
hash = graphqlAPI.updatePassword(@graphqlClient, @tokenProvider, variables)
|
674
|
+
return hash.dig("data", "updatePassword")
|
691
675
|
end
|
692
676
|
|
693
677
|
# 绑定手机号
|
@@ -698,14 +682,13 @@ module AuthingRuby
|
|
698
682
|
"phone": phone,
|
699
683
|
"phoneCode": phoneCode,
|
700
684
|
}
|
701
|
-
|
702
|
-
|
703
|
-
user = json.dig("data", "bindPhone")
|
685
|
+
hash = graphqlAPI.bindPhone(@graphqlClient, @tokenProvider, variables)
|
686
|
+
user = hash.dig("data", "bindPhone")
|
704
687
|
if user
|
705
688
|
setCurrentUser(user);
|
706
689
|
return user;
|
707
690
|
else
|
708
|
-
return
|
691
|
+
return hash
|
709
692
|
end
|
710
693
|
end
|
711
694
|
|
@@ -720,11 +703,10 @@ module AuthingRuby
|
|
720
703
|
"newPassword": newPasswordEncrypted,
|
721
704
|
}
|
722
705
|
graphqlAPI = AuthingRuby::GraphQLAPI.new
|
723
|
-
|
724
|
-
|
725
|
-
result = json.dig("data", "resetPassword") # {"message":"重置密码成功!","code":200}
|
706
|
+
hash = graphqlAPI.resetPassword(@graphqlClient, @tokenProvider, variables)
|
707
|
+
result = hash.dig("data", "resetPassword") # {"message":"重置密码成功!","code":200}
|
726
708
|
return result if result
|
727
|
-
return
|
709
|
+
return hash
|
728
710
|
end
|
729
711
|
|
730
712
|
def generateCodeChallenge()
|
@@ -14,9 +14,8 @@ module AuthingRuby
|
|
14
14
|
@options = options
|
15
15
|
end
|
16
16
|
|
17
|
-
#
|
18
|
-
#
|
19
|
-
# 如果失败,返回 Hash
|
17
|
+
# 发请求
|
18
|
+
# 成功或失败都返回 Hash
|
20
19
|
def request(options)
|
21
20
|
headers = {
|
22
21
|
'content-type': 'application/json',
|
@@ -42,20 +41,19 @@ module AuthingRuby
|
|
42
41
|
# puts response.body.to_s
|
43
42
|
# puts response.body.to_s.class.name # String
|
44
43
|
|
45
|
-
|
44
|
+
hash = JSON.parse(response.body.to_s)
|
46
45
|
|
47
46
|
# 这里的错误处理代码参照的 JS SDK (src/lib/common/GraphqlClient.ts)
|
48
|
-
if
|
49
|
-
#
|
50
|
-
|
51
|
-
return body_as_string
|
47
|
+
if hash['errors'] == nil
|
48
|
+
# 如果没错误
|
49
|
+
return hash
|
52
50
|
else
|
53
51
|
# 如果有错误, 最后返回这3个字段就行
|
54
52
|
code = nil
|
55
53
|
message = nil
|
56
54
|
data = nil
|
57
55
|
|
58
|
-
|
56
|
+
hash['errors'].each do |e|
|
59
57
|
if e['message']
|
60
58
|
message = e['message']
|
61
59
|
code = message['code']
|
@@ -1,5 +1,5 @@
|
|
1
1
|
# 测试内容: 用户认证模块-认证核心模块
|
2
|
-
# 如何运行: ruby
|
2
|
+
# 如何运行: ruby ./lib/authing_ruby/test/mini_test/TestAuthenticationClient.rb
|
3
3
|
|
4
4
|
require "minitest/autorun" # Minitest
|
5
5
|
require "./lib/authing_ruby.rb" # 模块主文件
|
@@ -21,20 +21,20 @@ class TestAuthenticationClient < Minitest::Test
|
|
21
21
|
end
|
22
22
|
|
23
23
|
# 测试: 手机号+验证码+密码 注册
|
24
|
+
# 需要手动测试(填验证码)
|
24
25
|
# ruby ./lib/authing_ruby/test/mini_test/TestAuthenticationClient.rb -n test_registerByPhoneCode
|
25
26
|
def test_registerByPhoneCode
|
26
27
|
phone = '13556136684'
|
27
28
|
code = '8086'
|
28
29
|
password = '1234567890'
|
29
30
|
res = @authenticationClient.registerByPhoneCode(phone, code, password)
|
30
|
-
puts '拿到的结果是:-----'
|
31
|
-
puts res
|
31
|
+
# puts '拿到的结果是:-----'
|
32
|
+
# puts res
|
32
33
|
# {:code=>2026, :message=>"用户已存在,请直接登录!", :data=>nil}
|
33
34
|
# {:code=>2001, :message=>"验证码不正确!", :data=>nil}
|
34
35
|
|
35
36
|
# 如果成功
|
36
37
|
# {"id"=>"60ad0c49d6e166f9fe23ba4d", "arn"=>"arn:cn:authing:60ab26fe478f98290befefaa:user:60ad0c49d6e166f9fe23ba4d", "userPoolId"=>"60ab26fe478f98290befefaa", "status"=>"Activated", "username"=>nil, "email"=>nil, "emailVerified"=>false, "phone"=>"13556136684", "phoneVerified"=>true, "unionid"=>nil, "openid"=>nil, "nickname"=>nil, "registerSource"=>["basic:phone-code"], "photo"=>"default-user-avatar.png", "password"=>"0361a6088087f31edd172c4f6076c0e6", "oauth"=>nil, "token"=>nil, "tokenExpiredAt"=>nil, "loginsCount"=>0, "lastLogin"=>nil, "lastIP"=>nil, "signedUp"=>nil, "blocked"=>false, "isDeleted"=>false, "device"=>nil, "browser"=>nil, "company"=>nil, "name"=>nil, "givenName"=>nil, "familyName"=>nil, "middleName"=>nil, "profile"=>nil, "preferredUsername"=>nil, "website"=>nil, "gender"=>"U", "birthdate"=>nil, "zoneinfo"=>nil, "locale"=>nil, "address"=>nil, "formatted"=>nil, "streetAddress"=>nil, "locality"=>nil, "region"=>nil, "postalCode"=>nil, "city"=>nil, "province"=>nil, "country"=>nil, "createdAt"=>"2021-05-25T14:40:09+00:00", "updatedAt"=>"2021-05-25T14:40:09+00:00", "externalId"=>nil}
|
37
|
-
assert(res.dig('id'), res)
|
38
38
|
end
|
39
39
|
|
40
40
|
# 测试邮箱+密码注册
|
@@ -138,11 +138,13 @@ class TestAuthenticationClient < Minitest::Test
|
|
138
138
|
end
|
139
139
|
|
140
140
|
# 测试: 修改用户资料
|
141
|
-
#
|
141
|
+
# 需要手动测试(确保用户名+密码账号的确存在)
|
142
|
+
# ruby ./lib/authing_ruby/test/mini_test/TestAuthenticationClient.rb -n test_updateProfile
|
142
143
|
def test_updateProfile
|
143
144
|
# 先登录
|
144
145
|
username = 'zhengcheng123'
|
145
146
|
password = "123456789"
|
147
|
+
@authenticationClient.registerByUsername(username, password)
|
146
148
|
@authenticationClient.loginByUsername(username, password)
|
147
149
|
|
148
150
|
# 进行第一次修改
|
@@ -220,11 +222,12 @@ class TestAuthenticationClient < Minitest::Test
|
|
220
222
|
end
|
221
223
|
|
222
224
|
# 测试: 检测 Token 登录状态
|
223
|
-
# ruby
|
225
|
+
# ruby ./lib/authing_ruby/test/mini_test/TestAuthenticationClient.rb -n test_checkLoginStatus
|
224
226
|
def test_checkLoginStatus
|
225
227
|
# 第一步:先登录然后获取 token
|
226
228
|
username = 'zhengcheng123'
|
227
229
|
password = "123456789"
|
230
|
+
@authenticationClient.registerByUsername(username, password)
|
228
231
|
user = @authenticationClient.loginByUsername(username, password)
|
229
232
|
token = user.dig("token")
|
230
233
|
|
@@ -9,8 +9,8 @@ Dotenv.load('.env.test')
|
|
9
9
|
class TestManagementClient < Minitest::Test
|
10
10
|
def setup
|
11
11
|
@options = {
|
12
|
-
|
13
|
-
host: 'https://core.authing.co', # 2021-5-13 他们临时使用 .co,过几天等他们恢复了 .cn 这里就改回 .cn
|
12
|
+
host: 'https://core.authing.cn',
|
13
|
+
# host: 'https://core.authing.co', # 2021-5-13 他们临时使用 .co,过几天等他们恢复了 .cn 这里就改回 .cn
|
14
14
|
userPoolId: ENV["userPoolId"],
|
15
15
|
secret: ENV["secret"],
|
16
16
|
}
|
data/lib/authing_ruby/version.rb
CHANGED