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.
- checksums.yaml +4 -4
- data/lib/authing_ruby/GraphQLAPI.rb +14 -3
- data/lib/authing_ruby/authentication/AuthenticationClient.rb +71 -60
- data/lib/authing_ruby/common/GraphqlClient.rb +42 -4
- data/lib/authing_ruby/graphql/mutations/updatePhone.gql +63 -0
- data/lib/authing_ruby/management/ManagementClient.rb +1 -1
- data/lib/authing_ruby/management/ManagementTokenProvider.rb +7 -3
- data/lib/authing_ruby/test/js_sdk_test/2.registerByPhoneCode.js +130 -0
- data/lib/authing_ruby/test/js_sdk_test/3.sendSMS.js +23 -0
- data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/browser/index.min.js +1 -1
- data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/main/lib/authentication/AuthenticationClient.d.ts +41 -1
- data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/main/lib/authentication/AuthenticationClient.js +60 -2
- data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/main/lib/authentication/QrCodeAuthenticationClient.js +6 -3
- data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/main/lib/authentication/SocialAuthenticationClient.d.ts +4 -0
- data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/main/lib/authentication/SocialAuthenticationClient.js +6 -5
- data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/main/lib/authentication/types.d.ts +10 -0
- data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/main/lib/authentication/types.js +1 -1
- data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/main/lib/common/GraphqlClient.js +10 -8
- data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/main/lib/common/HttpClient.js +17 -15
- data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/main/lib/graphqlapi.d.ts +12 -1
- data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/main/lib/graphqlapi.js +192 -2
- data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/main/lib/management/ApplicationsManagementClient.js +5 -3
- data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/main/lib/management/GroupsManagementClient.d.ts +5 -1
- data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/main/lib/management/GroupsManagementClient.js +29 -11
- data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/main/lib/management/ManagementClient.d.ts +5 -0
- data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/main/lib/management/ManagementClient.js +15 -2
- data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/main/lib/management/OrgManagementClient.d.ts +34 -1
- data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/main/lib/management/OrgManagementClient.js +71 -3
- data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/main/lib/management/RolesManagementClient.d.ts +6 -1
- data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/main/lib/management/RolesManagementClient.js +45 -10
- data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/main/lib/management/UsersManagementClient.d.ts +34 -3
- data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/main/lib/management/UsersManagementClient.js +189 -52
- data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/main/lib/management/types.d.ts +10 -0
- data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/main/lib/management/types.js +1 -1
- data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/main/lib/utils.d.ts +1 -1
- data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/main/lib/utils.js +1 -1
- data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/main/lib/version.d.ts +1 -1
- data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/main/lib/version.js +2 -2
- data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/main/types/graphql.v2.d.ts +661 -32
- data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/main/types/graphql.v2.js +30 -19
- data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/module/lib/authentication/AuthenticationClient.d.ts +41 -1
- data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/module/lib/authentication/AuthenticationClient.js +61 -3
- data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/module/lib/authentication/QrCodeAuthenticationClient.js +6 -3
- data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/module/lib/authentication/SocialAuthenticationClient.d.ts +4 -0
- data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/module/lib/authentication/SocialAuthenticationClient.js +6 -5
- data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/module/lib/authentication/types.d.ts +10 -0
- data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/module/lib/authentication/types.js +1 -1
- data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/module/lib/common/GraphqlClient.js +10 -8
- data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/module/lib/common/HttpClient.js +17 -15
- data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/module/lib/graphqlapi.d.ts +12 -1
- data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/module/lib/graphqlapi.js +192 -2
- data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/module/lib/management/ApplicationsManagementClient.js +5 -3
- data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/module/lib/management/GroupsManagementClient.d.ts +5 -1
- data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/module/lib/management/GroupsManagementClient.js +30 -12
- data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/module/lib/management/ManagementClient.d.ts +5 -0
- data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/module/lib/management/ManagementClient.js +15 -2
- data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/module/lib/management/OrgManagementClient.d.ts +34 -1
- data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/module/lib/management/OrgManagementClient.js +72 -4
- data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/module/lib/management/RolesManagementClient.d.ts +6 -1
- data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/module/lib/management/RolesManagementClient.js +46 -11
- data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/module/lib/management/UsersManagementClient.d.ts +34 -3
- data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/module/lib/management/UsersManagementClient.js +190 -53
- data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/module/lib/management/types.d.ts +10 -0
- data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/module/lib/management/types.js +1 -1
- data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/module/lib/utils.d.ts +1 -1
- data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/module/lib/utils.js +1 -1
- data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/module/lib/version.d.ts +1 -1
- data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/module/lib/version.js +2 -2
- data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/module/types/graphql.v2.d.ts +661 -32
- data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/module/types/graphql.v2.js +29 -18
- data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/umd/lib/authentication/AuthenticationClient.d.ts +41 -1
- data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/umd/lib/authentication/AuthenticationClient.js +60 -2
- data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/umd/lib/authentication/QrCodeAuthenticationClient.js +6 -3
- data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/umd/lib/authentication/SocialAuthenticationClient.d.ts +4 -0
- data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/umd/lib/authentication/SocialAuthenticationClient.js +6 -5
- data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/umd/lib/authentication/types.d.ts +10 -0
- data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/umd/lib/authentication/types.js +1 -1
- data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/umd/lib/common/GraphqlClient.js +10 -8
- data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/umd/lib/common/HttpClient.js +17 -15
- data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/umd/lib/graphqlapi.d.ts +12 -1
- data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/umd/lib/graphqlapi.js +192 -2
- data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/umd/lib/management/ApplicationsManagementClient.js +5 -3
- data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/umd/lib/management/GroupsManagementClient.d.ts +5 -1
- data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/umd/lib/management/GroupsManagementClient.js +29 -11
- data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/umd/lib/management/ManagementClient.d.ts +5 -0
- data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/umd/lib/management/ManagementClient.js +15 -2
- data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/umd/lib/management/OrgManagementClient.d.ts +34 -1
- data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/umd/lib/management/OrgManagementClient.js +71 -3
- data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/umd/lib/management/RolesManagementClient.d.ts +6 -1
- data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/umd/lib/management/RolesManagementClient.js +45 -10
- data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/umd/lib/management/UsersManagementClient.d.ts +34 -3
- data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/umd/lib/management/UsersManagementClient.js +189 -52
- data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/umd/lib/management/types.d.ts +10 -0
- data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/umd/lib/management/types.js +1 -1
- data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/umd/lib/utils.d.ts +1 -1
- data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/umd/lib/utils.js +1 -1
- data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/umd/lib/version.d.ts +1 -1
- data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/umd/lib/version.js +2 -2
- data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/umd/types/graphql.v2.d.ts +661 -32
- data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/build/umd/types/graphql.v2.js +30 -19
- data/lib/authing_ruby/test/js_sdk_test/node_modules/authing-js-sdk/package.json +1 -1
- data/lib/authing_ruby/test/js_sdk_test/node_modules/dotenv/CHANGELOG.md +210 -0
- data/lib/authing_ruby/test/js_sdk_test/node_modules/dotenv/LICENSE +23 -0
- data/lib/authing_ruby/test/js_sdk_test/node_modules/dotenv/README.md +275 -0
- data/lib/authing_ruby/test/js_sdk_test/node_modules/dotenv/config.js +11 -0
- data/lib/authing_ruby/test/js_sdk_test/node_modules/dotenv/lib/cli-options.js +13 -0
- data/lib/authing_ruby/test/js_sdk_test/node_modules/dotenv/lib/env-options.js +18 -0
- data/lib/authing_ruby/test/js_sdk_test/node_modules/dotenv/lib/main.js +118 -0
- data/lib/authing_ruby/test/js_sdk_test/node_modules/dotenv/package.json +57 -0
- data/lib/authing_ruby/test/js_sdk_test/node_modules/dotenv/types/index.d.ts +59 -0
- data/lib/authing_ruby/test/js_sdk_test/node_modules/dotenv/types/test.ts +19 -0
- data/lib/authing_ruby/test/js_sdk_test/node_modules/dotenv/types/tsconfig.json +15 -0
- data/lib/authing_ruby/test/js_sdk_test/node_modules/dotenv/types/tslint.json +6 -0
- data/lib/authing_ruby/test/js_sdk_test/node_modules/follow-redirects/index.js +0 -4
- data/lib/authing_ruby/test/js_sdk_test/node_modules/follow-redirects/package.json +1 -1
- data/lib/authing_ruby/test/js_sdk_test/package-lock.json +7 -7
- data/lib/authing_ruby/test/js_sdk_test/package.json +3 -2
- data/lib/authing_ruby/test/js_sdk_test/yarn.lock +71 -0
- data/lib/authing_ruby/test/mini_test/TestAuthenticationClient.rb +36 -22
- data/lib/authing_ruby/test/mini_test/TestManagementClient.rb +3 -2
- data/lib/authing_ruby/test/mini_test/TestSMSandEmail.rb +46 -3
- data/lib/authing_ruby/test/sms.rb +18 -0
- data/lib/authing_ruby/utils/utils.rb +68 -0
- data/lib/authing_ruby/version.rb +1 -1
- metadata +19 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b36719926968b5a3c6b66874c4f804b9c6b78d4f37cfb3ade0a2bee71de464a0
|
4
|
+
data.tar.gz: a177866df7eb186c9deae48b8f8cc5b868b6256f634ac8ad389b31dfae271056
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 42a6dc27513b5573bd0ee10bd73fb0c16610977ade77243ee40839be412f23e6fa68df217a44a1f88f9bd169d601107ce9d03a55ca8dd6f83540902da70a3c31
|
7
|
+
data.tar.gz: 913bea2c6b8a7731ff001482481751c080c8500afcb40b693fc8fba2b095d42106461925a2144a620c4badba49ff2c2389d0d20e9ca9b88d6dfa2a03061caa27
|
@@ -1,10 +1,15 @@
|
|
1
|
-
#
|
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("
|
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
|
-
|
67
|
-
|
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
|
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
|
-
|
95
|
-
|
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
|
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
|
-
|
137
|
-
|
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
|
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
|
-
|
162
|
-
|
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
|
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
|
-
|
190
|
-
|
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
|
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
|
-
|
214
|
-
|
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
|
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
|
-
|
241
|
-
|
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
|
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
|
-
|
264
|
-
|
265
|
-
data = json.dig('data')
|
258
|
+
hash = graphqlAPI.sendEmail(@graphqlClient, variables)
|
259
|
+
data = hash.dig('data')
|
266
260
|
return data if data
|
267
|
-
return
|
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
|
-
|
276
|
-
|
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
|
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
|
-
|
608
|
-
|
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
|
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
|
-
|
660
|
-
|
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
|
-
|
669
|
-
|
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
|
-
|
684
|
-
|
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
|
-
|
697
|
-
|
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
|
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
|
-
|
719
|
-
|
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
|
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
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
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
|
+
}
|