authing_ruby 1.0.6 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (125) hide show
  1. checksums.yaml +4 -4
  2. data/lib/authing_ruby/GraphQLAPI.rb +14 -3
  3. data/lib/authing_ruby/authentication/AuthenticationClient.rb +71 -60
  4. data/lib/authing_ruby/common/GraphqlClient.rb +42 -4
  5. data/lib/authing_ruby/graphql/mutations/updatePhone.gql +63 -0
  6. data/lib/authing_ruby/management/ManagementClient.rb +1 -1
  7. data/lib/authing_ruby/management/ManagementTokenProvider.rb +7 -3
  8. data/lib/authing_ruby/test/js_sdk_test/2.registerByPhoneCode.js +130 -0
  9. data/lib/authing_ruby/test/js_sdk_test/3.sendSMS.js +23 -0
  10. data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/browser/index.min.js +1 -1
  11. data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/main/lib/authentication/AuthenticationClient.d.ts +41 -1
  12. data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/main/lib/authentication/AuthenticationClient.js +60 -2
  13. data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/main/lib/authentication/QrCodeAuthenticationClient.js +6 -3
  14. data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/main/lib/authentication/SocialAuthenticationClient.d.ts +4 -0
  15. data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/main/lib/authentication/SocialAuthenticationClient.js +6 -5
  16. data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/main/lib/authentication/types.d.ts +10 -0
  17. data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/main/lib/authentication/types.js +1 -1
  18. data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/main/lib/common/GraphqlClient.js +10 -8
  19. data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/main/lib/common/HttpClient.js +17 -15
  20. data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/main/lib/graphqlapi.d.ts +12 -1
  21. data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/main/lib/graphqlapi.js +192 -2
  22. data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/main/lib/management/ApplicationsManagementClient.js +5 -3
  23. data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/main/lib/management/GroupsManagementClient.d.ts +5 -1
  24. data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/main/lib/management/GroupsManagementClient.js +29 -11
  25. data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/main/lib/management/ManagementClient.d.ts +5 -0
  26. data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/main/lib/management/ManagementClient.js +15 -2
  27. data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/main/lib/management/OrgManagementClient.d.ts +34 -1
  28. data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/main/lib/management/OrgManagementClient.js +71 -3
  29. data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/main/lib/management/RolesManagementClient.d.ts +6 -1
  30. data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/main/lib/management/RolesManagementClient.js +45 -10
  31. data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/main/lib/management/UsersManagementClient.d.ts +34 -3
  32. data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/main/lib/management/UsersManagementClient.js +189 -52
  33. data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/main/lib/management/types.d.ts +10 -0
  34. data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/main/lib/management/types.js +1 -1
  35. data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/main/lib/utils.d.ts +1 -1
  36. data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/main/lib/utils.js +1 -1
  37. data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/main/lib/version.d.ts +1 -1
  38. data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/main/lib/version.js +2 -2
  39. data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/main/types/graphql.v2.d.ts +661 -32
  40. data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/main/types/graphql.v2.js +30 -19
  41. data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/module/lib/authentication/AuthenticationClient.d.ts +41 -1
  42. data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/module/lib/authentication/AuthenticationClient.js +61 -3
  43. data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/module/lib/authentication/QrCodeAuthenticationClient.js +6 -3
  44. data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/module/lib/authentication/SocialAuthenticationClient.d.ts +4 -0
  45. data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/module/lib/authentication/SocialAuthenticationClient.js +6 -5
  46. data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/module/lib/authentication/types.d.ts +10 -0
  47. data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/module/lib/authentication/types.js +1 -1
  48. data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/module/lib/common/GraphqlClient.js +10 -8
  49. data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/module/lib/common/HttpClient.js +17 -15
  50. data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/module/lib/graphqlapi.d.ts +12 -1
  51. data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/module/lib/graphqlapi.js +192 -2
  52. data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/module/lib/management/ApplicationsManagementClient.js +5 -3
  53. data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/module/lib/management/GroupsManagementClient.d.ts +5 -1
  54. data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/module/lib/management/GroupsManagementClient.js +30 -12
  55. data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/module/lib/management/ManagementClient.d.ts +5 -0
  56. data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/module/lib/management/ManagementClient.js +15 -2
  57. data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/module/lib/management/OrgManagementClient.d.ts +34 -1
  58. data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/module/lib/management/OrgManagementClient.js +72 -4
  59. data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/module/lib/management/RolesManagementClient.d.ts +6 -1
  60. data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/module/lib/management/RolesManagementClient.js +46 -11
  61. data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/module/lib/management/UsersManagementClient.d.ts +34 -3
  62. data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/module/lib/management/UsersManagementClient.js +190 -53
  63. data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/module/lib/management/types.d.ts +10 -0
  64. data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/module/lib/management/types.js +1 -1
  65. data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/module/lib/utils.d.ts +1 -1
  66. data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/module/lib/utils.js +1 -1
  67. data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/module/lib/version.d.ts +1 -1
  68. data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/module/lib/version.js +2 -2
  69. data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/module/types/graphql.v2.d.ts +661 -32
  70. data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/module/types/graphql.v2.js +29 -18
  71. data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/umd/lib/authentication/AuthenticationClient.d.ts +41 -1
  72. data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/umd/lib/authentication/AuthenticationClient.js +60 -2
  73. data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/umd/lib/authentication/QrCodeAuthenticationClient.js +6 -3
  74. data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/umd/lib/authentication/SocialAuthenticationClient.d.ts +4 -0
  75. data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/umd/lib/authentication/SocialAuthenticationClient.js +6 -5
  76. data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/umd/lib/authentication/types.d.ts +10 -0
  77. data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/umd/lib/authentication/types.js +1 -1
  78. data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/umd/lib/common/GraphqlClient.js +10 -8
  79. data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/umd/lib/common/HttpClient.js +17 -15
  80. data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/umd/lib/graphqlapi.d.ts +12 -1
  81. data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/umd/lib/graphqlapi.js +192 -2
  82. data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/umd/lib/management/ApplicationsManagementClient.js +5 -3
  83. data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/umd/lib/management/GroupsManagementClient.d.ts +5 -1
  84. data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/umd/lib/management/GroupsManagementClient.js +29 -11
  85. data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/umd/lib/management/ManagementClient.d.ts +5 -0
  86. data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/umd/lib/management/ManagementClient.js +15 -2
  87. data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/umd/lib/management/OrgManagementClient.d.ts +34 -1
  88. data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/umd/lib/management/OrgManagementClient.js +71 -3
  89. data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/umd/lib/management/RolesManagementClient.d.ts +6 -1
  90. data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/umd/lib/management/RolesManagementClient.js +45 -10
  91. data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/umd/lib/management/UsersManagementClient.d.ts +34 -3
  92. data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/umd/lib/management/UsersManagementClient.js +189 -52
  93. data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/umd/lib/management/types.d.ts +10 -0
  94. data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/umd/lib/management/types.js +1 -1
  95. data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/umd/lib/utils.d.ts +1 -1
  96. data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/umd/lib/utils.js +1 -1
  97. data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/umd/lib/version.d.ts +1 -1
  98. data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/umd/lib/version.js +2 -2
  99. data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/umd/types/graphql.v2.d.ts +661 -32
  100. data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/umd/types/graphql.v2.js +30 -19
  101. data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/package.json +1 -1
  102. data/lib/authing_ruby/test/js_sdk_test/node_modules/dotenv/CHANGELOG.md +210 -0
  103. data/lib/authing_ruby/test/js_sdk_test/node_modules/dotenv/LICENSE +23 -0
  104. data/lib/authing_ruby/test/js_sdk_test/node_modules/dotenv/README.md +275 -0
  105. data/lib/authing_ruby/test/js_sdk_test/node_modules/dotenv/config.js +11 -0
  106. data/lib/authing_ruby/test/js_sdk_test/node_modules/dotenv/lib/cli-options.js +13 -0
  107. data/lib/authing_ruby/test/js_sdk_test/node_modules/dotenv/lib/env-options.js +18 -0
  108. data/lib/authing_ruby/test/js_sdk_test/node_modules/dotenv/lib/main.js +118 -0
  109. data/lib/authing_ruby/test/js_sdk_test/node_modules/dotenv/package.json +57 -0
  110. data/lib/authing_ruby/test/js_sdk_test/node_modules/dotenv/types/index.d.ts +59 -0
  111. data/lib/authing_ruby/test/js_sdk_test/node_modules/dotenv/types/test.ts +19 -0
  112. data/lib/authing_ruby/test/js_sdk_test/node_modules/dotenv/types/tsconfig.json +15 -0
  113. data/lib/authing_ruby/test/js_sdk_test/node_modules/dotenv/types/tslint.json +6 -0
  114. data/lib/authing_ruby/test/js_sdk_test/node_modules/follow-redirects/index.js +0 -4
  115. data/lib/authing_ruby/test/js_sdk_test/node_modules/follow-redirects/package.json +1 -1
  116. data/lib/authing_ruby/test/js_sdk_test/package-lock.json +7 -7
  117. data/lib/authing_ruby/test/js_sdk_test/package.json +3 -2
  118. data/lib/authing_ruby/test/js_sdk_test/yarn.lock +71 -0
  119. data/lib/authing_ruby/test/mini_test/TestAuthenticationClient.rb +36 -22
  120. data/lib/authing_ruby/test/mini_test/TestManagementClient.rb +3 -2
  121. data/lib/authing_ruby/test/mini_test/TestSMSandEmail.rb +46 -3
  122. data/lib/authing_ruby/test/sms.rb +18 -0
  123. data/lib/authing_ruby/utils/utils.rb +68 -0
  124. data/lib/authing_ruby/version.rb +1 -1
  125. metadata +19 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f715d06d523db7c6675bb78664544871ca51cdcad5403a68cd5890a34e44cfba
4
- data.tar.gz: ca8224e0c0664cc5279cf10fee3e50ede62d3f5190bacb75e0231f590421d29b
3
+ metadata.gz: b36719926968b5a3c6b66874c4f804b9c6b78d4f37cfb3ade0a2bee71de464a0
4
+ data.tar.gz: a177866df7eb186c9deae48b8f8cc5b868b6256f634ac8ad389b31dfae271056
5
5
  SHA512:
6
- metadata.gz: 44bef546ff4b178aa91d014870ea1e32662d85cd32cbafda3e2267308c05ed0fe938575351cb72840d83d7b511244e7ed3452f20667df4ae5c854e548e7b4ac5
7
- data.tar.gz: f061dd79f1a2c626b718bf4a74ae58428957134032dcf90cf8c3cfd00f2e05a2b0148a3148ed54f7d0e29739756d6f0f7b1f1d86af969ba9386cd6959460a79e
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
 
@@ -15,7 +20,7 @@ module AuthingRuby
15
20
  end
16
21
 
17
22
  def getCurrentUser(garpqhlClient, tokenProvider, variables)
18
- return _graphql_query_request("getCurrentUser", garpqhlClient, nil, variables)
23
+ return _graphql_query_request("user", garpqhlClient, tokenProvider, variables)
19
24
  end
20
25
 
21
26
  def sendEmail(garpqhlClient, variables)
@@ -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)
@@ -39,6 +39,11 @@ module AuthingRuby
39
39
  @tokenEndPointAuthMethod = options.fetch(:tokenEndPointAuthMethod, 'client_secret_post')
40
40
  @introspectionEndPointAuthMethod = options.fetch(:introspectionEndPointAuthMethod, 'client_secret_post')
41
41
  @revocationEndPointAuthMethod = options.fetch(:revocationEndPointAuthMethod, 'client_secret_post')
42
+
43
+ token = options.fetch(:token, nil)
44
+ if token
45
+ setToken(token)
46
+ end
42
47
  end
43
48
 
44
49
  # 使用邮箱+密码注册 (完成, 测试通过)
@@ -63,11 +68,10 @@ module AuthingRuby
63
68
  }
64
69
  }
65
70
  graphqlAPI = AuthingRuby::GraphQLAPI.new
66
- res = graphqlAPI.registerByEmail(@graphqlClient, variables)
67
- json = JSON.parse(res)
68
- user = json.dig('data', 'registerByEmail')
71
+ hash = graphqlAPI.registerByEmail(@graphqlClient, variables)
72
+ user = hash.dig('data', 'registerByEmail')
69
73
  return user if user
70
- return json
74
+ return hash
71
75
  end
72
76
 
73
77
  # 使用用户名注册
@@ -91,11 +95,10 @@ module AuthingRuby
91
95
  }
92
96
  }
93
97
  graphqlAPI = AuthingRuby::GraphQLAPI.new
94
- res = graphqlAPI.registerByUsername(@graphqlClient, variables)
95
- json = JSON.parse(res)
96
- user = json.dig('data', 'registerByUsername')
98
+ hash = graphqlAPI.registerByUsername(@graphqlClient, variables)
99
+ user = hash.dig('data', 'registerByUsername')
97
100
  return user if user
98
- return json
101
+ return hash
99
102
  end
100
103
 
101
104
  # 发送短信验证码
@@ -133,11 +136,10 @@ module AuthingRuby
133
136
  }
134
137
  }
135
138
  graphqlAPI = AuthingRuby::GraphQLAPI.new
136
- res = graphqlAPI.registerByPhoneCode(@graphqlClient, variables)
137
- json = JSON.parse(res)
138
- user = json.dig('data', 'registerByPhoneCode')
139
+ hash = graphqlAPI.registerByPhoneCode(@graphqlClient, variables)
140
+ user = hash.dig('data', 'registerByPhoneCode')
139
141
  return user if user
140
- return json
142
+ return hash
141
143
  end
142
144
 
143
145
  # 使用邮箱登录
@@ -158,14 +160,13 @@ module AuthingRuby
158
160
  }
159
161
  }
160
162
  graphqlAPI = AuthingRuby::GraphQLAPI.new
161
- res = graphqlAPI.loginByEmail(@graphqlClient, variables)
162
- json = JSON.parse(res)
163
- user = json.dig('data', 'loginByEmail')
163
+ hash = graphqlAPI.loginByEmail(@graphqlClient, variables)
164
+ user = hash.dig('data', 'loginByEmail')
164
165
  if user
165
166
  setCurrentUser(user);
166
167
  return user
167
168
  end
168
- return json
169
+ return hash
169
170
  end
170
171
 
171
172
  # 使用用户名登录
@@ -186,14 +187,13 @@ module AuthingRuby
186
187
  }
187
188
  }
188
189
  graphqlAPI = AuthingRuby::GraphQLAPI.new
189
- res = graphqlAPI.loginByUsername(@graphqlClient, variables)
190
- json = JSON.parse(res)
191
- user = json.dig('data', 'loginByUsername')
190
+ hash = graphqlAPI.loginByUsername(@graphqlClient, variables)
191
+ user = hash.dig('data', 'loginByUsername')
192
192
  if user
193
193
  setCurrentUser(user);
194
194
  return user
195
195
  end
196
- return json
196
+ return hash
197
197
  end
198
198
 
199
199
  # 使用手机号验证码登录
@@ -210,14 +210,13 @@ module AuthingRuby
210
210
  }
211
211
  }
212
212
  graphqlAPI = AuthingRuby::GraphQLAPI.new
213
- res = graphqlAPI.loginByPhoneCode(@graphqlClient, variables)
214
- json = JSON.parse(res)
215
- user = json.dig('data', 'loginByPhoneCode')
213
+ hash = graphqlAPI.loginByPhoneCode(@graphqlClient, variables)
214
+ user = hash.dig('data', 'loginByPhoneCode')
216
215
  if user
217
216
  setCurrentUser(user);
218
217
  return user
219
218
  end
220
- return json
219
+ return hash
221
220
  end
222
221
 
223
222
  # 使用手机号密码登录
@@ -237,17 +236,13 @@ module AuthingRuby
237
236
  }
238
237
  }
239
238
  graphqlAPI = AuthingRuby::GraphQLAPI.new
240
- res = graphqlAPI.loginByPhonePassword(@graphqlClient, variables)
241
- json = JSON.parse(res)
242
- user = json.dig('data', 'loginByPhonePassword')
239
+ hash = graphqlAPI.loginByPhonePassword(@graphqlClient, variables)
240
+ user = hash.dig('data', 'loginByPhonePassword')
243
241
  if user
244
242
  setCurrentUser(user);
245
243
  return user
246
244
  end
247
- return json
248
- end
249
-
250
- def checkLoginStatus
245
+ return hash
251
246
  end
252
247
 
253
248
  # 发送邮件
@@ -260,11 +255,10 @@ module AuthingRuby
260
255
  "scene": scene,
261
256
  }
262
257
  graphqlAPI = AuthingRuby::GraphQLAPI.new
263
- res = graphqlAPI.sendEmail(@graphqlClient, variables)
264
- json = JSON.parse(res)
265
- data = json.dig('data')
258
+ hash = graphqlAPI.sendEmail(@graphqlClient, variables)
259
+ data = hash.dig('data')
266
260
  return data if data
267
- return json
261
+ return hash
268
262
  # {"sendEmail":{"message":"","code":200}}
269
263
  end
270
264
 
@@ -272,14 +266,13 @@ module AuthingRuby
272
266
  # 返回:用户信息
273
267
  def getCurrentUser()
274
268
  graphqlAPI = AuthingRuby::GraphQLAPI.new
275
- res = graphqlAPI.getCurrentUser(@graphqlClient, @tokenProvider, variables)
276
- json = JSON.parse(res)
277
- user = json.dig("data", "user")
269
+ hash = graphqlAPI.getCurrentUser(@graphqlClient, @tokenProvider, {})
270
+ user = hash.dig("data", "user")
278
271
  if user
279
272
  setCurrentUser(user)
280
273
  return user
281
274
  else
282
- return json
275
+ return hash
283
276
  end
284
277
  end
285
278
 
@@ -604,9 +597,8 @@ module AuthingRuby
604
597
  "id": userId,
605
598
  "input": updates
606
599
  }
607
- res = graphqlAPI.updateUser(@graphqlClient, @tokenProvider, variables)
608
- json = JSON.parse(res)
609
- updated_user = json.dig('data', 'updateUser')
600
+ hash = graphqlAPI.updateUser(@graphqlClient, @tokenProvider, variables)
601
+ updated_user = hash.dig('data', 'updateUser')
610
602
  if updated_user
611
603
  # 如果更新成功,返回更新后的用户
612
604
  setCurrentUser(updated_user)
@@ -614,7 +606,7 @@ module AuthingRuby
614
606
  else
615
607
  # 如果更新失败,返回原结果
616
608
  # {"errors"=>[{"message"=>{"code"=>2020, "message"=>"尚未登录,无访问权限"}, "locations"=>[{"line"=>2, "column"=>3}], "path"=>["updateUser"], "extensions"=>{"code"=>"INTERNAL_SERVER_ERROR"}}], "data"=>nil}
617
- return json
609
+ return hash
618
610
  end
619
611
  end
620
612
 
@@ -656,18 +648,16 @@ module AuthingRuby
656
648
  def checkPasswordStrength(password)
657
649
  graphqlAPI = AuthingRuby::GraphQLAPI.new
658
650
  variables = { "password": password }
659
- res = graphqlAPI.checkPasswordStrength(@graphqlClient, @tokenProvider, variables)
660
- json = JSON.parse(res)
661
- return json.dig("data", "checkPasswordStrength")
651
+ hash = graphqlAPI.checkPasswordStrength(@graphqlClient, @tokenProvider, variables)
652
+ return hash.dig("data", "checkPasswordStrength")
662
653
  end
663
654
 
664
655
  # 检测 Token 登录状态
665
656
  def checkLoginStatus(token)
666
657
  graphqlAPI = AuthingRuby::GraphQLAPI.new
667
658
  variables = { "token": token }
668
- res = graphqlAPI.checkLoginStatus(@graphqlClient, @tokenProvider, variables)
669
- json = JSON.parse(res)
670
- return json.dig("data", "checkLoginStatus")
659
+ hash = graphqlAPI.checkLoginStatus(@graphqlClient, @tokenProvider, variables)
660
+ return hash.dig("data", "checkLoginStatus")
671
661
  end
672
662
 
673
663
  # 更新用户密码
@@ -680,9 +670,8 @@ module AuthingRuby
680
670
  "oldPassword": oldPasswordEncrypted,
681
671
  }
682
672
  graphqlAPI = AuthingRuby::GraphQLAPI.new
683
- res = graphqlAPI.updatePassword(@graphqlClient, @tokenProvider, variables)
684
- json = JSON.parse(res)
685
- return json.dig("data", "updatePassword")
673
+ hash = graphqlAPI.updatePassword(@graphqlClient, @tokenProvider, variables)
674
+ return hash.dig("data", "updatePassword")
686
675
  end
687
676
 
688
677
  # 绑定手机号
@@ -693,14 +682,37 @@ module AuthingRuby
693
682
  "phone": phone,
694
683
  "phoneCode": phoneCode,
695
684
  }
696
- res = graphqlAPI.bindPhone(@graphqlClient, @tokenProvider, variables)
697
- json = JSON.parse(res)
698
- user = json.dig("data", "bindPhone")
685
+ hash = graphqlAPI.bindPhone(@graphqlClient, @tokenProvider, variables)
686
+ user = hash.dig("data", "bindPhone")
699
687
  if user
700
688
  setCurrentUser(user);
701
689
  return user;
702
690
  else
703
- return json
691
+ return hash
692
+ end
693
+ end
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
704
716
  end
705
717
  end
706
718
 
@@ -715,11 +727,10 @@ module AuthingRuby
715
727
  "newPassword": newPasswordEncrypted,
716
728
  }
717
729
  graphqlAPI = AuthingRuby::GraphQLAPI.new
718
- resp = graphqlAPI.resetPassword(@graphqlClient, @tokenProvider, variables)
719
- json = JSON.parse(resp)
720
- result = json.dig("data", "resetPassword") # {"message":"重置密码成功!","code":200}
730
+ hash = graphqlAPI.resetPassword(@graphqlClient, @tokenProvider, variables)
731
+ result = hash.dig("data", "resetPassword") # {"message":"重置密码成功!","code":200}
721
732
  return result if result
722
- return json
733
+ return hash
723
734
  end
724
735
 
725
736
  def generateCodeChallenge()
@@ -14,6 +14,8 @@ module AuthingRuby
14
14
  @options = options
15
15
  end
16
16
 
17
+ # 发请求
18
+ # 成功或失败都返回 Hash
17
19
  def request(options)
18
20
  headers = {
19
21
  'content-type': 'application/json',
@@ -28,10 +30,46 @@ module AuthingRuby
28
30
  headers['Authorization'] = "Bearer #{token}"
29
31
  end
30
32
 
31
- json = options.fetch(:json, nil)
32
- # puts "@endpoint #{@endpoint}"
33
- response = HTTP.headers(headers).post(@endpoint, json: json)
34
- return response.body.to_s
33
+ option_json = options.fetch(:json, nil)
34
+ response = HTTP.headers(headers).post(@endpoint, json: option_json)
35
+
36
+ # 如果直接拿 body,它的类型是:
37
+ # puts response.body
38
+ # puts response.body.class.name # HTTP::Response::Body
39
+
40
+ # 如果转成 String:
41
+ # puts response.body.to_s
42
+ # puts response.body.to_s.class.name # String
43
+
44
+ hash = JSON.parse(response.body.to_s)
45
+
46
+ # 这里的错误处理代码参照的 JS SDK (src/lib/common/GraphqlClient.ts)
47
+ if hash['errors'] == nil
48
+ # 如果没错误
49
+ return hash
50
+ else
51
+ # 如果有错误, 最后返回这3个字段就行
52
+ code = nil
53
+ message = nil
54
+ data = nil
55
+
56
+ hash['errors'].each do |e|
57
+ if e['message']
58
+ message = e['message']
59
+ code = message['code']
60
+ message = message['message']
61
+ data = message['data']
62
+ end
63
+ end
64
+
65
+ # 返回 Hash
66
+ obj = {
67
+ code: code,
68
+ message: message,
69
+ data: data
70
+ }
71
+ return obj
72
+ end
35
73
  end
36
74
 
37
75
  end
@@ -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
+ }