authing_ruby 1.1.0 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: aa6593330f870f1b2559fe53cbeb0ed09a06cff11a5c79ea728d328a57136f58
4
- data.tar.gz: a037af3385879a07abb47ab49b23712944b0999ace92d9d291bc4a701d090eff
3
+ metadata.gz: b36719926968b5a3c6b66874c4f804b9c6b78d4f37cfb3ade0a2bee71de464a0
4
+ data.tar.gz: a177866df7eb186c9deae48b8f8cc5b868b6256f634ac8ad389b31dfae271056
5
5
  SHA512:
6
- metadata.gz: fd1b2564b11854460730bafe77947659f0ef22b97ee5be871549882837eee2cea373f9fc7303843e044a22d37d93829a95c347c4a4e4216a484470337857dc51
7
- data.tar.gz: cbb759903d06dbb5be96d472f32c713983efb56ad736460a4c880f898343fe99d4aaa63cbceefe073ef69cc2e7309c1c0667734f9af588cbcddf78cc295aa324
6
+ metadata.gz: 42a6dc27513b5573bd0ee10bd73fb0c16610977ade77243ee40839be412f23e6fa68df217a44a1f88f9bd169d601107ce9d03a55ca8dd6f83540902da70a3c31
7
+ data.tar.gz: 913bea2c6b8a7731ff001482481751c080c8500afcb40b693fc8fba2b095d42106461925a2144a620c4badba49ff2c2389d0d20e9ca9b88d6dfa2a03061caa27
@@ -1,10 +1,15 @@
1
- # 类似于 JS SDK 里 src/lib/graphqlapi.ts 的用途
2
- # 把一些 garpqhlClient.request 封装起来,里面包含了 const query = AccessTokenDocument;
1
+ # 类似 JS SDK 里 src/lib/graphqlapi.ts 的用途,把请求进行封装
3
2
 
4
3
  # 使用示例
5
4
  # graphqlAPI = AuthingRuby::GraphQLAPI.new
6
5
  # graphqlAPI.getAccessToken(graphqlClient, variables)
7
6
 
7
+ # 一共有三个参数
8
+ # (garpqhlClient, tokenProvider = nil, variables = nil)
9
+ # garpqhlClient 是 lib/authing_ruby/common/GraphqlClient.rb
10
+ # tokenProvider 是 lib/authing_ruby/authentication/AuthenticationTokenProvider.rb
11
+ # variables 就是参数
12
+
8
13
  module AuthingRuby
9
14
  class GraphQLAPI
10
15
 
@@ -112,12 +117,18 @@ module AuthingRuby
112
117
  return _graphql_mutation_request("resetPassword", garpqhlClient, tokenProvider, variables)
113
118
  end
114
119
 
120
+ # 更新用户手机号码
121
+ def updatePhone(garpqhlClient, tokenProvider = nil, variables = nil)
122
+ return _graphql_mutation_request("updatePhone", garpqhlClient, tokenProvider, variables)
123
+ end
124
+
115
125
  def bindPhone(garpqhlClient, tokenProvider = nil, variables = nil)
116
126
  return _graphql_mutation_request("bindPhone", garpqhlClient, tokenProvider, variables)
117
127
  end
118
128
 
119
129
  # 太多同样写法的 method 了,稍微抽象一下
120
130
  # 这个负责发 mutation 的 request
131
+ # 第一个参数 gql_file_name 就是文件名
121
132
  def _graphql_mutation_request(gql_file_name, garpqhlClient, tokenProvider, variables)
122
133
  file = File.open("#{@folder_mutation}/#{gql_file_name}.gql");
123
134
  return _graphql_request(file, garpqhlClient, tokenProvider, variables)
@@ -692,6 +692,30 @@ module AuthingRuby
692
692
  end
693
693
  end
694
694
 
695
+ # 更新用户手机号
696
+ # 更新用户手机号。和修改邮箱一样,默认情况下,如果用户当前已经绑定了手机号,需要同时验证原有手机号(目前账号绑定的手机号)和当前邮箱(将要绑定的手机号)。
697
+ # 也就是说,用户 A 当前绑定的手机号为 15888888888,想修改为 15899999999,那么就需要同时验证这两个手机号。
698
+ # 开发者也可以选择不开启 “验证原有手机号“ ,可以在 Authing 控制台 的 设置目录下的安全信息模块进行关闭。
699
+ # 用户首次绑定手机号请使用 bindPhone 接口。
700
+ def updatePhone(phone, phoneCode, oldPhone, oldPhoneCode)
701
+ graphqlAPI = AuthingRuby::GraphQLAPI.new
702
+ variables = {
703
+ "phone": phone,
704
+ "phoneCode": phoneCode,
705
+ }
706
+ variables['oldPhone'] = oldPhone if oldPhone
707
+ variables['oldPhoneCode'] = oldPhoneCode if oldPhoneCode
708
+
709
+ hash = graphqlAPI.updatePhone(@graphqlClient, @tokenProvider, variables)
710
+ user = hash.dig("data", "updatePhone")
711
+ if user
712
+ setCurrentUser(user)
713
+ return user
714
+ else
715
+ return hash
716
+ end
717
+ end
718
+
695
719
  # 通过短信验证码重置密码
696
720
  def resetPasswordByPhoneCode(phone, code, newPassword)
697
721
  publicKey = @publicKeyManager.getPublicKey()
@@ -0,0 +1,63 @@
1
+ mutation updatePhone(
2
+ $phone: String!
3
+ $phoneCode: String!
4
+ $oldPhone: String
5
+ $oldPhoneCode: String
6
+ ) {
7
+ updatePhone(
8
+ phone: $phone
9
+ phoneCode: $phoneCode
10
+ oldPhone: $oldPhone
11
+ oldPhoneCode: $oldPhoneCode
12
+ ) {
13
+ id
14
+ arn
15
+ userPoolId
16
+ status
17
+ username
18
+ email
19
+ emailVerified
20
+ phone
21
+ phoneVerified
22
+ unionid
23
+ openid
24
+ nickname
25
+ registerSource
26
+ photo
27
+ password
28
+ oauth
29
+ token
30
+ tokenExpiredAt
31
+ loginsCount
32
+ lastLogin
33
+ lastIP
34
+ signedUp
35
+ blocked
36
+ isDeleted
37
+ device
38
+ browser
39
+ company
40
+ name
41
+ givenName
42
+ familyName
43
+ middleName
44
+ profile
45
+ preferredUsername
46
+ website
47
+ gender
48
+ birthdate
49
+ zoneinfo
50
+ locale
51
+ address
52
+ formatted
53
+ streetAddress
54
+ locality
55
+ region
56
+ postalCode
57
+ city
58
+ province
59
+ country
60
+ createdAt
61
+ updatedAt
62
+ }
63
+ }
@@ -209,10 +209,6 @@ class TestAuthenticationClient < Minitest::Test
209
209
  assert(result.dig('id') != nil, result)
210
210
  end
211
211
 
212
- # 测试: 更新用户手机号
213
- def test_updatePhone
214
- end
215
-
216
212
  # 绑定邮箱
217
213
  def test_bindEmail
218
214
  end
@@ -12,7 +12,7 @@
12
12
 
13
13
  require "minitest/autorun"
14
14
  require "./lib/authing_ruby.rb"
15
- require "./lib/test/helper.rb"
15
+ require "./lib/authing_ruby/test/helper.rb"
16
16
  require 'dotenv'
17
17
  Dotenv.load('.env.test')
18
18
 
@@ -97,5 +97,48 @@ class TestSMSandEmail < Minitest::Test
97
97
  # 清理工作:测完了删除第一步注册的用户
98
98
  user_id = user['id']
99
99
  @managementClient.users.delete(user_id)
100
- end
101
- end
100
+ end
101
+
102
+ # 测试: 更新用户手机号
103
+ # ruby ./lib/authing_ruby/test/mini_test/TestSMSandEmail.rb -n test_updatePhone
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
+ def test_updatePhone
106
+ # 前提条件:先确保有一个用户是自己的手机号,可以直接进 Authing 手工新建一个用户。新建时给设定手机号和密码,手机号可以随便填比如13511112222
107
+ # 填写对应手机号, 以及密码
108
+ phone = '13511112222'
109
+ password = '123456789'
110
+ # 登录
111
+ user = @authenticationClient.loginByPhonePassword(phone, password)
112
+ # 填写另一个要绑定的新手机号(可以填你自己的,这样才能收到短信)
113
+ phone = '13556136684'
114
+
115
+ # 发送验证码 (把下面发短信这一行先取消注释, 收到短信后再注释上)
116
+ # puts manual_send_SMS(phone); return;
117
+
118
+ # 填写收到的短信验证码
119
+ code = '4874'
120
+
121
+ # 默认情况下,如果用户当前已经绑定了手机号,需要同时验证原有手机号
122
+ # 开发者也可以选择不开启 “验证原有手机号“ ,可以在 Authing 控制台 的 设置目录下的安全信息模块进行关闭。
123
+ # 单个用户池 -> 设置 -> 安全信息 -> 用户池安全设置 -> 修改手机号时是否验证旧手机号 -> 点击开关,切换为关闭 -> 右上角"保存"
124
+ # 由于没有2个手机号,这里是关闭后再测试
125
+ oldPhone = nil
126
+ oldPhoneCode = nil
127
+
128
+ updatePhoneResult = @authenticationClient.updatePhone(phone, code, oldPhone, oldPhoneCode)
129
+ puts updatePhoneResult
130
+ assert(updatePhoneResult.dig('id') != nil)
131
+
132
+ # 错误:
133
+ # {:code=>2020, :message=>"尚未登录,无访问权限", :data=>nil}
134
+ # {:code=>500, :message=>"该手机号已被绑定", :data=>nil}
135
+ # {:code=>2230, :message=>"新手机号和旧手机号一样", :data=>nil}
136
+ # {:code=>500, :message=>"修改手机号必须验证原来的手机号。", :data=>nil}
137
+ # {:code=>500, :message=>"验证码已过期", :data=>nil}
138
+ # {:code=>500, :message=>"验证码不正确!", :data=>nil}
139
+
140
+ # 成功会返回 User
141
+ # {"id"=>"60b5b17a9cf59b23b2bcbccb", "arn"=>"arn:cn:authing:60800b8ee5b66b23128b4980:user:60b5b17a9cf59b23b2bcbccb", "userPoolId"=>"60800b8ee5b66b23128b4980", "status"=>"Activated", "username"=>"测试更新手机号", "email"=>nil, "emailVerified"=>false, "phone"=>"13556136684", "phoneVerified"=>true, "unionid"=>nil, "openid"=>nil, "nickname"=>nil, "registerSource"=>["import:manual"], "photo"=>"https://files.authing.co/authing-console/default-user-avatar.png", "password"=>"871fde109c2f0f463cc35e0c3e840932", "oauth"=>nil, "token"=>"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiI2MGI1YjE3YTljZjU5YjIzYjJiY2JjY2IiLCJiaXJ0aGRhdGUiOm51bGwsImZhbWlseV9uYW1lIjpudWxsLCJnZW5kZXIiOiJVIiwiZ2l2ZW5fbmFtZSI6bnVsbCwibG9jYWxlIjpudWxsLCJtaWRkbGVfbmFtZSI6bnVsbCwibmFtZSI6bnVsbCwibmlja25hbWUiOm51bGwsInBpY3R1cmUiOiJodHRwczovL2ZpbGVzLmF1dGhpbmcuY28vYXV0aGluZy1jb25zb2xlL2RlZmF1bHQtdXNlci1hdmF0YXIucG5nIiwicHJlZmVycmVkX3VzZXJuYW1lIjpudWxsLCJwcm9maWxlIjpudWxsLCJ1cGRhdGVkX2F0IjoiMjAyMS0wNi0wMVQwNDoxNjo1MS41NDBaIiwid2Vic2l0ZSI6bnVsbCwiem9uZWluZm8iOm51bGwsImFkZHJlc3MiOnsiY291bnRyeSI6bnVsbCwicG9zdGFsX2NvZG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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-06-01T04:03:06+00:00", "updatedAt"=>"2021-06-01T04:17:12+00:00"}
142
+ end
143
+
144
+ end
@@ -2,5 +2,5 @@
2
2
  # https://github.com/Authing/authing.js/blob/cf4757d09de3b44c3c3f4509ae8c8715c9f302a2/src/lib/version.ts
3
3
 
4
4
  module AuthingRuby
5
- VERSION = "1.1.0".freeze
5
+ VERSION = "1.1.1".freeze
6
6
  end
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.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - 郑诚(Zheng Cheng)
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-05-25 00:00:00.000000000 Z
11
+ date: 2021-06-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest
@@ -189,6 +189,7 @@ files:
189
189
  - lib/authing_ruby/graphql/mutations/resetPassword.gql
190
190
  - lib/authing_ruby/graphql/mutations/sendEmail.gql
191
191
  - lib/authing_ruby/graphql/mutations/updatePassword.gql
192
+ - lib/authing_ruby/graphql/mutations/updatePhone.gql
192
193
  - lib/authing_ruby/graphql/mutations/updateUser.gql
193
194
  - lib/authing_ruby/graphql/queries/accessToken.gql
194
195
  - lib/authing_ruby/graphql/queries/checkLoginStatus.gql