authing_ruby 1.0.8 → 1.1.3
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/GraphQLAPI.rb +13 -2
- data/lib/authing_ruby/authentication/AuthenticationClient.rb +66 -57
- 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 +2 -2
- data/lib/authing_ruby/management/ManagementTokenProvider.rb +9 -8
- data/lib/authing_ruby/management/UsersManagementClient.rb +4 -6
- data/lib/authing_ruby/test/helper.rb +6 -2
- 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/TestApplicationsManagementClient.rb +2 -2
- data/lib/authing_ruby/test/mini_test/TestAuthenticationClient.rb +27 -13
- data/lib/authing_ruby/test/mini_test/TestManagementClient.rb +31 -43
- data/lib/authing_ruby/test/mini_test/TestSMSandEmail.rb +47 -3
- data/lib/authing_ruby/test/sms.rb +18 -0
- data/lib/authing_ruby/utils/utils.rb +32 -1
- data/lib/authing_ruby/version.rb +1 -1
- metadata +23 -6
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: c96f70bbb6209a350729fc7acb3c8f8aa44c65065059dc1d9314e4c1889cf9fe
|
|
4
|
+
data.tar.gz: ab3be4af6af5885d93978830d633bdcc8cce304405d2faa625a8deed9e9bfdf5
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: edce71334d03757b966483dd0789fe18c4b1b7d0718c3459cec99247a4b99394a6c559eda07850b43f0134666640a737e1e32564878960168c53fc9ddd488df8
|
|
7
|
+
data.tar.gz: ad7033895474b78be0c9e79bea67f547173d90f9b05417fecacf8272cf85d36d5ff6c0cc10171593b7e784fcff4344a0096ecbca3be00cae992ea2b6734c2fc2
|
|
@@ -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
|
|
|
@@ -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)
|
|
@@ -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,11 +136,10 @@ module AuthingRuby
|
|
|
138
136
|
}
|
|
139
137
|
}
|
|
140
138
|
graphqlAPI = AuthingRuby::GraphQLAPI.new
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
user = json.dig('data', 'registerByPhoneCode')
|
|
139
|
+
hash = graphqlAPI.registerByPhoneCode(@graphqlClient, variables)
|
|
140
|
+
user = hash.dig('data', 'registerByPhoneCode')
|
|
144
141
|
return user if user
|
|
145
|
-
return
|
|
142
|
+
return hash
|
|
146
143
|
end
|
|
147
144
|
|
|
148
145
|
# 使用邮箱登录
|
|
@@ -163,14 +160,13 @@ module AuthingRuby
|
|
|
163
160
|
}
|
|
164
161
|
}
|
|
165
162
|
graphqlAPI = AuthingRuby::GraphQLAPI.new
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
user = json.dig('data', 'loginByEmail')
|
|
163
|
+
hash = graphqlAPI.loginByEmail(@graphqlClient, variables)
|
|
164
|
+
user = hash.dig('data', 'loginByEmail')
|
|
169
165
|
if user
|
|
170
166
|
setCurrentUser(user);
|
|
171
167
|
return user
|
|
172
168
|
end
|
|
173
|
-
return
|
|
169
|
+
return hash
|
|
174
170
|
end
|
|
175
171
|
|
|
176
172
|
# 使用用户名登录
|
|
@@ -191,14 +187,13 @@ module AuthingRuby
|
|
|
191
187
|
}
|
|
192
188
|
}
|
|
193
189
|
graphqlAPI = AuthingRuby::GraphQLAPI.new
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
user = json.dig('data', 'loginByUsername')
|
|
190
|
+
hash = graphqlAPI.loginByUsername(@graphqlClient, variables)
|
|
191
|
+
user = hash.dig('data', 'loginByUsername')
|
|
197
192
|
if user
|
|
198
193
|
setCurrentUser(user);
|
|
199
194
|
return user
|
|
200
195
|
end
|
|
201
|
-
return
|
|
196
|
+
return hash
|
|
202
197
|
end
|
|
203
198
|
|
|
204
199
|
# 使用手机号验证码登录
|
|
@@ -215,14 +210,13 @@ module AuthingRuby
|
|
|
215
210
|
}
|
|
216
211
|
}
|
|
217
212
|
graphqlAPI = AuthingRuby::GraphQLAPI.new
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
user = json.dig('data', 'loginByPhoneCode')
|
|
213
|
+
hash = graphqlAPI.loginByPhoneCode(@graphqlClient, variables)
|
|
214
|
+
user = hash.dig('data', 'loginByPhoneCode')
|
|
221
215
|
if user
|
|
222
216
|
setCurrentUser(user);
|
|
223
217
|
return user
|
|
224
218
|
end
|
|
225
|
-
return
|
|
219
|
+
return hash
|
|
226
220
|
end
|
|
227
221
|
|
|
228
222
|
# 使用手机号密码登录
|
|
@@ -242,14 +236,13 @@ module AuthingRuby
|
|
|
242
236
|
}
|
|
243
237
|
}
|
|
244
238
|
graphqlAPI = AuthingRuby::GraphQLAPI.new
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
user = json.dig('data', 'loginByPhonePassword')
|
|
239
|
+
hash = graphqlAPI.loginByPhonePassword(@graphqlClient, variables)
|
|
240
|
+
user = hash.dig('data', 'loginByPhonePassword')
|
|
248
241
|
if user
|
|
249
242
|
setCurrentUser(user);
|
|
250
243
|
return user
|
|
251
244
|
end
|
|
252
|
-
return
|
|
245
|
+
return hash
|
|
253
246
|
end
|
|
254
247
|
|
|
255
248
|
# 发送邮件
|
|
@@ -262,11 +255,10 @@ module AuthingRuby
|
|
|
262
255
|
"scene": scene,
|
|
263
256
|
}
|
|
264
257
|
graphqlAPI = AuthingRuby::GraphQLAPI.new
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
data = json.dig('data')
|
|
258
|
+
hash = graphqlAPI.sendEmail(@graphqlClient, variables)
|
|
259
|
+
data = hash.dig('data')
|
|
268
260
|
return data if data
|
|
269
|
-
return
|
|
261
|
+
return hash
|
|
270
262
|
# {"sendEmail":{"message":"","code":200}}
|
|
271
263
|
end
|
|
272
264
|
|
|
@@ -274,14 +266,13 @@ module AuthingRuby
|
|
|
274
266
|
# 返回:用户信息
|
|
275
267
|
def getCurrentUser()
|
|
276
268
|
graphqlAPI = AuthingRuby::GraphQLAPI.new
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
user = json.dig("data", "user")
|
|
269
|
+
hash = graphqlAPI.getCurrentUser(@graphqlClient, @tokenProvider, {})
|
|
270
|
+
user = hash.dig("data", "user")
|
|
280
271
|
if user
|
|
281
272
|
setCurrentUser(user)
|
|
282
273
|
return user
|
|
283
274
|
else
|
|
284
|
-
return
|
|
275
|
+
return hash
|
|
285
276
|
end
|
|
286
277
|
end
|
|
287
278
|
|
|
@@ -606,9 +597,8 @@ module AuthingRuby
|
|
|
606
597
|
"id": userId,
|
|
607
598
|
"input": updates
|
|
608
599
|
}
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
updated_user = json.dig('data', 'updateUser')
|
|
600
|
+
hash = graphqlAPI.updateUser(@graphqlClient, @tokenProvider, variables)
|
|
601
|
+
updated_user = hash.dig('data', 'updateUser')
|
|
612
602
|
if updated_user
|
|
613
603
|
# 如果更新成功,返回更新后的用户
|
|
614
604
|
setCurrentUser(updated_user)
|
|
@@ -616,7 +606,7 @@ module AuthingRuby
|
|
|
616
606
|
else
|
|
617
607
|
# 如果更新失败,返回原结果
|
|
618
608
|
# {"errors"=>[{"message"=>{"code"=>2020, "message"=>"尚未登录,无访问权限"}, "locations"=>[{"line"=>2, "column"=>3}], "path"=>["updateUser"], "extensions"=>{"code"=>"INTERNAL_SERVER_ERROR"}}], "data"=>nil}
|
|
619
|
-
return
|
|
609
|
+
return hash
|
|
620
610
|
end
|
|
621
611
|
end
|
|
622
612
|
|
|
@@ -658,18 +648,16 @@ module AuthingRuby
|
|
|
658
648
|
def checkPasswordStrength(password)
|
|
659
649
|
graphqlAPI = AuthingRuby::GraphQLAPI.new
|
|
660
650
|
variables = { "password": password }
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
return json.dig("data", "checkPasswordStrength")
|
|
651
|
+
hash = graphqlAPI.checkPasswordStrength(@graphqlClient, @tokenProvider, variables)
|
|
652
|
+
return hash.dig("data", "checkPasswordStrength")
|
|
664
653
|
end
|
|
665
654
|
|
|
666
655
|
# 检测 Token 登录状态
|
|
667
656
|
def checkLoginStatus(token)
|
|
668
657
|
graphqlAPI = AuthingRuby::GraphQLAPI.new
|
|
669
658
|
variables = { "token": token }
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
return json.dig("data", "checkLoginStatus")
|
|
659
|
+
hash = graphqlAPI.checkLoginStatus(@graphqlClient, @tokenProvider, variables)
|
|
660
|
+
return hash.dig("data", "checkLoginStatus")
|
|
673
661
|
end
|
|
674
662
|
|
|
675
663
|
# 更新用户密码
|
|
@@ -682,9 +670,8 @@ module AuthingRuby
|
|
|
682
670
|
"oldPassword": oldPasswordEncrypted,
|
|
683
671
|
}
|
|
684
672
|
graphqlAPI = AuthingRuby::GraphQLAPI.new
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
return json.dig("data", "updatePassword")
|
|
673
|
+
hash = graphqlAPI.updatePassword(@graphqlClient, @tokenProvider, variables)
|
|
674
|
+
return hash.dig("data", "updatePassword")
|
|
688
675
|
end
|
|
689
676
|
|
|
690
677
|
# 绑定手机号
|
|
@@ -695,14 +682,37 @@ module AuthingRuby
|
|
|
695
682
|
"phone": phone,
|
|
696
683
|
"phoneCode": phoneCode,
|
|
697
684
|
}
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
user = json.dig("data", "bindPhone")
|
|
685
|
+
hash = graphqlAPI.bindPhone(@graphqlClient, @tokenProvider, variables)
|
|
686
|
+
user = hash.dig("data", "bindPhone")
|
|
701
687
|
if user
|
|
702
688
|
setCurrentUser(user);
|
|
703
689
|
return user;
|
|
704
690
|
else
|
|
705
|
-
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
|
|
706
716
|
end
|
|
707
717
|
end
|
|
708
718
|
|
|
@@ -717,11 +727,10 @@ module AuthingRuby
|
|
|
717
727
|
"newPassword": newPasswordEncrypted,
|
|
718
728
|
}
|
|
719
729
|
graphqlAPI = AuthingRuby::GraphQLAPI.new
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
result = json.dig("data", "resetPassword") # {"message":"重置密码成功!","code":200}
|
|
730
|
+
hash = graphqlAPI.resetPassword(@graphqlClient, @tokenProvider, variables)
|
|
731
|
+
result = hash.dig("data", "resetPassword") # {"message":"重置密码成功!","code":200}
|
|
723
732
|
return result if result
|
|
724
|
-
return
|
|
733
|
+
return hash
|
|
725
734
|
end
|
|
726
735
|
|
|
727
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
|
+
}
|
|
@@ -13,11 +13,11 @@ module AuthingRuby
|
|
|
13
13
|
@userPoolId = options.fetch(:userPoolId, nil)
|
|
14
14
|
@secret = options.fetch(:secret, nil)
|
|
15
15
|
@appId = options.fetch(:appId, nil)
|
|
16
|
-
@host = options.fetch(:host,
|
|
16
|
+
@host = options.fetch(:host, 'https://core.authing.cn')
|
|
17
17
|
@accessToken = options.fetch(:accessToken, nil)
|
|
18
18
|
|
|
19
19
|
if @userPoolId == nil && @appId == nil
|
|
20
|
-
|
|
20
|
+
raise '请提供 userPoolId 或 appId!'
|
|
21
21
|
end
|
|
22
22
|
|
|
23
23
|
graphqlApiEndpointV2 = "#{@host}/graphql/v2"
|
|
@@ -16,8 +16,8 @@ module AuthingRuby
|
|
|
16
16
|
@_accessToken = nil
|
|
17
17
|
@_accessTokenExpriredAt = nil # 过期时间
|
|
18
18
|
|
|
19
|
-
accessToken = options.fetch(:accessToken, nil)
|
|
20
19
|
# 如果 options 里传入了 accessToken
|
|
20
|
+
accessToken = options.fetch(:accessToken, nil)
|
|
21
21
|
if accessToken
|
|
22
22
|
@_accessToken = accessToken;
|
|
23
23
|
decoded_token_array = JWT.decode @_accessToken, nil, false # 试着解析一下
|
|
@@ -46,6 +46,7 @@ module AuthingRuby
|
|
|
46
46
|
def _getAccessTokenFromServer
|
|
47
47
|
accessToken = nil;
|
|
48
48
|
secret = @options.fetch(:secret, nil)
|
|
49
|
+
|
|
49
50
|
if secret
|
|
50
51
|
accessToken = getClientWhenSdkInit()
|
|
51
52
|
else
|
|
@@ -68,20 +69,20 @@ module AuthingRuby
|
|
|
68
69
|
secret: @options.fetch(:secret, nil),
|
|
69
70
|
}
|
|
70
71
|
api = AuthingRuby::GraphQLAPI.new
|
|
71
|
-
|
|
72
|
+
hash = api.getAccessToken(@graphqlClient, variables)
|
|
72
73
|
# {"data":{"accessToken":{"accessToken":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJkYXRhIjp7InR5cGUiOiJ1[省略]ZWE2NjE3IiwidXNlcks2lkIjoiNjA3YjBiMTVhYWIzYTgwNWY3ZWE2NjE3IiwiX2lkIjoiNjA3YjBiMTVhYWIzYTgwNWY3ZWE2NjE3IiwicGhvbmz3Mzk5M30.K7pwyvbxypeiOlYRsTIlLXY2xyk94tTd-CATQ85jYqM","exp":1620873993,"iat":1619577993}}}
|
|
73
|
-
hash = JSON.parse(res)
|
|
74
74
|
return hash.dig("data", "accessToken", "accessToken")
|
|
75
75
|
end
|
|
76
76
|
|
|
77
|
-
# TODO 还需要做什么?
|
|
78
77
|
def refreshToken
|
|
79
78
|
api = AuthingRuby::GraphQLAPI.new
|
|
80
|
-
|
|
81
|
-
|
|
79
|
+
accessToken = @options.fetch(:accessToken, nil)
|
|
80
|
+
if accessToken == nil
|
|
81
|
+
raise "无法刷新 token, 因为初始化时没有传入 accessToken"
|
|
82
|
+
end
|
|
83
|
+
hash = api.refreshAccessToken(@graphqlClient, {
|
|
84
|
+
accessToken: accessToken
|
|
82
85
|
})
|
|
83
|
-
hash = JSON.parse(res)
|
|
84
|
-
# puts hash
|
|
85
86
|
# {"errors"=>[{"message"=>{"code"=>500, "message"=>"该 token 在黑名单中"}, "locations"=>[{"line"=>2, "column"=>5}], "path"=>["refreshAccessToken"], "extensions"=>{"code"=>"INTERNAL_SERVER_ERROR", "exception"=>{"name"=>"TokenInBlackListError"}}}], "data"=>nil}
|
|
86
87
|
if hash.dig("errors")
|
|
87
88
|
return hash
|