authing_ruby 1.1.1 → 1.1.2
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/authing_ruby/management/ManagementTokenProvider.rb +2 -5
- data/lib/authing_ruby/management/UsersManagementClient.rb +4 -6
- data/lib/authing_ruby/test/helper.rb +6 -2
- data/lib/authing_ruby/test/mini_test/TestApplicationsManagementClient.rb +2 -2
- data/lib/authing_ruby/test/mini_test/TestManagementClient.rb +28 -41
- data/lib/authing_ruby/test/mini_test/TestSMSandEmail.rb +6 -5
- data/lib/authing_ruby/version.rb +1 -1
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4203f8f2932fcacc6405c533a530d779fef455827507dbb35292813d4c916244
|
4
|
+
data.tar.gz: d62015f96cd7b5ffb283dcc69db496954632f3468894fd2ddf189a3f71dc8ba3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a31bd62c0ddcf683dfb87427e241f24ccf32582d8848cc14764c2b0f496e6f10d49aa691cfb09a820fbfffcddb54ca67f0a82a307e125dcf4fa5dcc8bfe5e4e7
|
7
|
+
data.tar.gz: 24a19d114a8a24a4438e32c9d3b4c1209e1f75c7ec81efb068ce0fe4da0417bfd6279a65150f48f0c66f89f292aab6c3f21afee38dac754b8fe3840aeb54f5e8
|
@@ -69,9 +69,8 @@ module AuthingRuby
|
|
69
69
|
secret: @options.fetch(:secret, nil),
|
70
70
|
}
|
71
71
|
api = AuthingRuby::GraphQLAPI.new
|
72
|
-
|
72
|
+
hash = api.getAccessToken(@graphqlClient, variables)
|
73
73
|
# {"data":{"accessToken":{"accessToken":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJkYXRhIjp7InR5cGUiOiJ1[省略]ZWE2NjE3IiwidXNlcks2lkIjoiNjA3YjBiMTVhYWIzYTgwNWY3ZWE2NjE3IiwiX2lkIjoiNjA3YjBiMTVhYWIzYTgwNWY3ZWE2NjE3IiwicGhvbmz3Mzk5M30.K7pwyvbxypeiOlYRsTIlLXY2xyk94tTd-CATQ85jYqM","exp":1620873993,"iat":1619577993}}}
|
74
|
-
hash = JSON.parse(res)
|
75
74
|
return hash.dig("data", "accessToken", "accessToken")
|
76
75
|
end
|
77
76
|
|
@@ -81,11 +80,9 @@ module AuthingRuby
|
|
81
80
|
if accessToken == nil
|
82
81
|
raise "无法刷新 token, 因为初始化时没有传入 accessToken"
|
83
82
|
end
|
84
|
-
|
83
|
+
hash = api.refreshAccessToken(@graphqlClient, {
|
85
84
|
accessToken: accessToken
|
86
85
|
})
|
87
|
-
hash = JSON.parse(res)
|
88
|
-
# puts hash
|
89
86
|
# {"errors"=>[{"message"=>{"code"=>500, "message"=>"该 token 在黑名单中"}, "locations"=>[{"line"=>2, "column"=>5}], "path"=>["refreshAccessToken"], "extensions"=>{"code"=>"INTERNAL_SERVER_ERROR", "exception"=>{"name"=>"TokenInBlackListError"}}}], "data"=>nil}
|
90
87
|
if hash.dig("errors")
|
91
88
|
return hash
|
@@ -116,9 +116,8 @@ module AuthingRuby
|
|
116
116
|
"phone": phone,
|
117
117
|
}
|
118
118
|
graphqlAPI = AuthingRuby::GraphQLAPI.new
|
119
|
-
|
120
|
-
|
121
|
-
return json.dig('data', "isUserExists")
|
119
|
+
hash = graphqlAPI.isUserExists(@graphqlClient, @tokenProvider, variables)
|
120
|
+
return hash.dig('data', "isUserExists")
|
122
121
|
end
|
123
122
|
|
124
123
|
# 查找用户
|
@@ -138,9 +137,8 @@ module AuthingRuby
|
|
138
137
|
"externalId": externalId,
|
139
138
|
}
|
140
139
|
graphqlAPI = AuthingRuby::GraphQLAPI.new
|
141
|
-
|
142
|
-
|
143
|
-
return json
|
140
|
+
hash = graphqlAPI.findUser(@graphqlClient, @tokenProvider, variables)
|
141
|
+
return hash
|
144
142
|
end
|
145
143
|
|
146
144
|
# TODO
|
@@ -1,8 +1,8 @@
|
|
1
|
-
# ruby ./lib/test/mini_test/TestApplicationsManagementClient.rb
|
1
|
+
# ruby ./lib/authing_ruby/test/mini_test/TestApplicationsManagementClient.rb
|
2
2
|
|
3
3
|
require "minitest/autorun"
|
4
4
|
require "./lib/authing_ruby.rb"
|
5
|
-
require "./lib/test/helper.rb"
|
5
|
+
require "./lib/authing_ruby/test/helper.rb"
|
6
6
|
require 'dotenv'
|
7
7
|
Dotenv.load('.env.test')
|
8
8
|
|
@@ -18,24 +18,26 @@ class TestManagementClient < Minitest::Test
|
|
18
18
|
end
|
19
19
|
|
20
20
|
# 创建用户
|
21
|
-
# ruby ./lib/test/mini_test/TestManagementClient.rb -n test_users_create
|
21
|
+
# ruby ./lib/authing_ruby/test/mini_test/TestManagementClient.rb -n test_users_create
|
22
22
|
def test_users_create
|
23
23
|
managementClient = AuthingRuby::ManagementClient.new(@options)
|
24
|
+
random_phone = "135#{@helper.randomNumString(8)}"
|
24
25
|
userInfo = {
|
25
|
-
username: @helper.randomString, # 随机字符串,比如 "mpflok"
|
26
|
+
# username: @helper.randomString, # 随机字符串,比如 "mpflok"
|
26
27
|
# username: 'SpongeBob3', # 或者明确指定用户名
|
27
|
-
|
28
|
+
phone: random_phone,
|
29
|
+
password: '123456789',
|
28
30
|
}
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
#
|
31
|
+
puts userInfo
|
32
|
+
hash = managementClient.users.create(userInfo)
|
33
|
+
|
34
|
+
# 成功
|
33
35
|
# {"data":{"createUser":{"id":"608ab9828eab7e35e81bd732","arn":"arn:cn:authing:60800b8ee5b66b23128b4980:user:608ab9828eab7e35e81bd732","userPoolId":"60800b8ee5b66b23128b4980","status":"Activated","username":"SpongeBob2","email":null,"emailVerified":false,"phone":null,"phoneVerified":false,"unionid":null,"openid":null,"nickname":null,"registerSource":["import:manual"],"photo":"default-user-avatar.png","password":"91b133c2e13e40852505946b7e0c2f04","oauth":null,"token":null,"tokenExpiredAt":null,"loginsCount":0,"lastLogin":null,"lastIP":null,"signedUp":null,"blocked":false,"isDeleted":false,"device":null,"browser":null,"company":null,"name":null,"givenName":null,"familyName":null,"middleName":null,"profile":null,"preferredUsername":null,"website":null,"gender":"U","birthdate":null,"zoneinfo":null,"locale":null,"address":null,"formatted":null,"streetAddress":null,"locality":null,"region":null,"postalCode":null,"city":null,"province":null,"country":null,"createdAt":"2021-04-29T13:49:54+00:00","updatedAt":"2021-04-29T13:49:54+00:00","externalId":null}}}
|
34
36
|
|
35
|
-
#
|
37
|
+
# 失败
|
36
38
|
# {"errors":[{"message":{"code":2026,"message":"用户已存在,请勿重复创建!"},"locations":[{"line":2,"column":3}],"path":["createUser"],"extensions":{"code":"INTERNAL_SERVER_ERROR"}}],"data":null}
|
37
39
|
|
38
|
-
assert(
|
40
|
+
assert(hash.dig("data", "createUser") != nil, hash)
|
39
41
|
end
|
40
42
|
|
41
43
|
# 创建用户
|
@@ -49,10 +51,8 @@ class TestManagementClient < Minitest::Test
|
|
49
51
|
loginsCount: 2, # 原有用户系统记录的用户登录次数
|
50
52
|
signedUp: '2020-10-15T17:55:37+08:00' # 原有用户系统记录的用户注册时间
|
51
53
|
}
|
52
|
-
|
53
|
-
|
54
|
-
json = JSON.parse(res)
|
55
|
-
assert(json.dig("data", "createUser") != nil, json)
|
54
|
+
hash = managementClient.users.create(userInfo)
|
55
|
+
assert(hash.dig("data", "createUser") != nil, hash)
|
56
56
|
end
|
57
57
|
|
58
58
|
# 创建一个用户, 并返回这个用户
|
@@ -67,14 +67,13 @@ class TestManagementClient < Minitest::Test
|
|
67
67
|
end
|
68
68
|
|
69
69
|
managementClient = AuthingRuby::ManagementClient.new(@options)
|
70
|
-
|
71
|
-
|
72
|
-
user = json.dig("data", "createUser")
|
70
|
+
hash = managementClient.users.create(userInfo)
|
71
|
+
user = hash.dig("data", "createUser")
|
73
72
|
return user
|
74
73
|
end
|
75
74
|
|
76
75
|
# 更新用户
|
77
|
-
# ruby ./lib/test/mini_test/TestManagementClient.rb -n test_update_user
|
76
|
+
# ruby ./lib/authing_ruby/test/mini_test/TestManagementClient.rb -n test_update_user
|
78
77
|
def test_update_user
|
79
78
|
# 第一步:创建用户
|
80
79
|
user = create_random_user()
|
@@ -82,15 +81,14 @@ class TestManagementClient < Minitest::Test
|
|
82
81
|
|
83
82
|
# 第二步:更新用户
|
84
83
|
managementClient = AuthingRuby::ManagementClient.new(@options)
|
85
|
-
|
84
|
+
hash = managementClient.users.update(user_id, {
|
86
85
|
nickname: 'Nick',
|
87
86
|
})
|
88
87
|
# puts res2
|
89
88
|
# 如果失败
|
90
89
|
# {"errors":[{"message":{"code":2004,"message":"用户不存在"},"locations":[{"line":2,"column":3}],"path":["updateUser"],"extensions":{"code":"INTERNAL_SERVER_ERROR"}}],"data":null}
|
91
90
|
|
92
|
-
|
93
|
-
assert(json2.dig("data", "updateUser") != nil, json2)
|
91
|
+
assert(hash.dig("data", "updateUser") != nil, hash)
|
94
92
|
end
|
95
93
|
|
96
94
|
# 测试通过 ID 获取用户信息
|
@@ -100,26 +98,20 @@ class TestManagementClient < Minitest::Test
|
|
100
98
|
user_id = user.dig("id")
|
101
99
|
|
102
100
|
managementClient = AuthingRuby::ManagementClient.new(@options)
|
103
|
-
|
104
|
-
|
105
|
-
json = JSON.parse(res)
|
106
|
-
assert(json.dig("data", "user") != nil, json)
|
101
|
+
hash = managementClient.users.detail(user_id)
|
102
|
+
assert(hash.dig("data", "user") != nil, hash)
|
107
103
|
end
|
108
104
|
|
109
105
|
# 测试删除用户
|
110
|
-
# ruby ./lib/test/mini_test/TestManagementClient.rb -n test_delete
|
106
|
+
# ruby ./lib/authing_ruby/test/mini_test/TestManagementClient.rb -n test_delete
|
111
107
|
def test_delete
|
112
108
|
user = create_random_user()
|
113
109
|
user_id = user.dig("id")
|
114
110
|
|
115
111
|
managementClient = AuthingRuby::ManagementClient.new(@options)
|
116
|
-
|
117
|
-
|
118
|
-
# puts res
|
112
|
+
hash = managementClient.users.delete(user_id)
|
119
113
|
# {"data":{"deleteUser":{"message":"删除成功!","code":200}}}
|
120
|
-
|
121
|
-
json = JSON.parse(res)
|
122
|
-
assert(json.dig("data", "deleteUser") != nil, json)
|
114
|
+
assert(hash.dig("data", "deleteUser") != nil, hash)
|
123
115
|
end
|
124
116
|
|
125
117
|
# 测试删除多个用户
|
@@ -134,22 +126,17 @@ class TestManagementClient < Minitest::Test
|
|
134
126
|
user_ids = [user1_id, user2_id]
|
135
127
|
|
136
128
|
managementClient = AuthingRuby::ManagementClient.new(@options)
|
137
|
-
|
138
|
-
# puts res
|
129
|
+
hash = managementClient.users.deleteMany(user_ids)
|
139
130
|
# {"data":{"deleteUsers":{"message":"删除成功!","code":200}}}
|
140
|
-
|
141
|
-
json = JSON.parse(res)
|
142
|
-
assert(json.dig("data", "deleteUsers") != nil, json)
|
131
|
+
assert(hash.dig("data", "deleteUsers") != nil, hash)
|
143
132
|
end
|
144
133
|
|
145
134
|
# 测试获取用户列表
|
146
135
|
# ruby ./lib/test/mini_test/TestManagementClient.rb -n test_list
|
147
136
|
def test_list
|
148
137
|
managementClient = AuthingRuby::ManagementClient.new(@options)
|
149
|
-
|
150
|
-
|
151
|
-
json = JSON.parse(res)
|
152
|
-
assert(json.dig("data", "users") != nil, json)
|
138
|
+
hash = managementClient.users.list()
|
139
|
+
assert(hash.dig("data", "users") != nil, hash)
|
153
140
|
end
|
154
141
|
|
155
142
|
# 测试 检查用户是否存在 (返回 true | false)
|
@@ -173,7 +160,7 @@ class TestManagementClient < Minitest::Test
|
|
173
160
|
end
|
174
161
|
|
175
162
|
# 测试 查找用户 (返回这个用户)
|
176
|
-
# ruby ./lib/test/mini_test/TestManagementClient.rb -n test_find
|
163
|
+
# ruby ./lib/authing_ruby/test/mini_test/TestManagementClient.rb -n test_find
|
177
164
|
def test_find
|
178
165
|
# 第一步:先创建用户
|
179
166
|
userInfo = {
|
@@ -103,16 +103,17 @@ class TestSMSandEmail < Minitest::Test
|
|
103
103
|
# ruby ./lib/authing_ruby/test/mini_test/TestSMSandEmail.rb -n test_updatePhone
|
104
104
|
# 文档: https://docs.authing.cn/v2/reference/sdk-for-node/authentication/AuthenticationClient.html#%E6%9B%B4%E6%96%B0%E7%94%A8%E6%88%B7%E6%89%8B%E6%9C%BA%E5%8F%B7
|
105
105
|
def test_updatePhone
|
106
|
-
#
|
107
|
-
|
106
|
+
# 前提条件:先确保有一个现有用户,可以进 Authing 手工新建一个,新建时设定手机号和密码,手机号随便填如 13511112222 密码 123456789
|
107
|
+
|
108
|
+
# 先登录:
|
108
109
|
phone = '13511112222'
|
109
110
|
password = '123456789'
|
110
|
-
# 登录
|
111
111
|
user = @authenticationClient.loginByPhonePassword(phone, password)
|
112
|
-
|
112
|
+
|
113
|
+
# 填写要绑定的新手机号(可以填你自己的,这样才能收到短信)
|
113
114
|
phone = '13556136684'
|
114
115
|
|
115
|
-
#
|
116
|
+
# 给新手机号发送短信验证码 (把下面这行先取消注释, 收到短信后再注释上)
|
116
117
|
# puts manual_send_SMS(phone); return;
|
117
118
|
|
118
119
|
# 填写收到的短信验证码
|
data/lib/authing_ruby/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: authing_ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- 郑诚(Zheng Cheng)
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-06-
|
11
|
+
date: 2021-06-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: minitest
|
@@ -689,7 +689,7 @@ homepage: https://github.com/1c7/authing_ruby
|
|
689
689
|
licenses:
|
690
690
|
- MIT
|
691
691
|
metadata: {}
|
692
|
-
post_install_message:
|
692
|
+
post_install_message:
|
693
693
|
rdoc_options: []
|
694
694
|
require_paths:
|
695
695
|
- lib
|
@@ -704,8 +704,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
704
704
|
- !ruby/object:Gem::Version
|
705
705
|
version: '0'
|
706
706
|
requirements: []
|
707
|
-
rubygems_version: 3.0.
|
708
|
-
signing_key:
|
707
|
+
rubygems_version: 3.0.9
|
708
|
+
signing_key:
|
709
709
|
specification_version: 4
|
710
710
|
summary: Authing 的 Ruby SDK
|
711
711
|
test_files: []
|