AuthRequestTest.java 15.4 KB
Newer Older
1
package me.zhyd.oauth.request;
2 3

import me.zhyd.oauth.config.AuthConfig;
智布道's avatar
智布道 已提交
4
import me.zhyd.oauth.model.AuthCallback;
5
import me.zhyd.oauth.model.AuthResponse;
智布道's avatar
智布道 已提交
6
import me.zhyd.oauth.request.*;
7 8 9 10 11 12 13 14
import org.junit.Test;

/**
 * @author yadong.zhang (yadong.zhang0415(a)gmail.com)
 */
public class AuthRequestTest {

    @Test
15
    public void giteeTest() {
16
        AuthRequest authRequest = new AuthGiteeRequest(AuthConfig.builder()
17 18
            .clientId("clientId")
            .clientSecret("clientSecret")
19
            .redirectUri("http://redirectUri")
20
            .build());
21
        // 返回授权页面,可自行跳转
22
        authRequest.authorize("state");
智布道's avatar
智布道 已提交
23
        // 授权登录后会返回code(auth_code(仅限支付宝)、authorization_code(仅限华为))、state,1.8.0版本后,可以用AuthCallback类作为回调接口的入参
24
        // 注:JustAuth默认保存state的时效为3分钟,3分钟内未使用则会自动清除过期的state
智布道's avatar
智布道 已提交
25
        authRequest.login(new AuthCallback());
26 27 28
    }

    @Test
29
    public void githubTest() {
30
        AuthRequest authRequest = new AuthGithubRequest(AuthConfig.builder()
31 32
            .clientId("clientId")
            .clientSecret("clientSecret")
33
            .redirectUri("http://redirectUri")
34
            .build());
35
        // 返回授权页面,可自行跳转
36
        authRequest.authorize("state");
智布道's avatar
智布道 已提交
37
        // 授权登录后会返回code(auth_code(仅限支付宝)、authorization_code(仅限华为))、state,1.8.0版本后,可以用AuthCallback类作为回调接口的入参
38
        // 注:JustAuth默认保存state的时效为3分钟,3分钟内未使用则会自动清除过期的state
智布道's avatar
智布道 已提交
39
        authRequest.login(new AuthCallback());
40 41 42
    }

    @Test
43
    public void weiboTest() {
44
        AuthRequest authRequest = new AuthWeiboRequest(AuthConfig.builder()
45 46
            .clientId("clientId")
            .clientSecret("clientSecret")
47
            .redirectUri("http://redirectUri")
48
            .build());
49
        // 返回授权页面,可自行跳转
50
        authRequest.authorize("state");
智布道's avatar
智布道 已提交
51
        // 授权登录后会返回code(auth_code(仅限支付宝)、authorization_code(仅限华为))、state,1.8.0版本后,可以用AuthCallback类作为回调接口的入参
52
        // 注:JustAuth默认保存state的时效为3分钟,3分钟内未使用则会自动清除过期的state
智布道's avatar
智布道 已提交
53
        authRequest.login(new AuthCallback());
54
    }
智布道's avatar
智布道 已提交
55 56 57 58

    @Test
    public void dingdingTest() {
        AuthRequest authRequest = new AuthDingTalkRequest(AuthConfig.builder()
59 60
            .clientId("clientId")
            .clientSecret("clientSecret")
61
            .redirectUri("http://redirectUri")
62
            .build());
63
        // 返回授权页面,可自行跳转
64
        authRequest.authorize("state");
智布道's avatar
智布道 已提交
65
        // 授权登录后会返回code(auth_code(仅限支付宝)、authorization_code(仅限华为))、state,1.8.0版本后,可以用AuthCallback类作为回调接口的入参
66
        // 注:JustAuth默认保存state的时效为3分钟,3分钟内未使用则会自动清除过期的state
智布道's avatar
智布道 已提交
67
        authRequest.login(new AuthCallback());
68 69 70 71 72
    }

    @Test
    public void baiduTest() {
        AuthRequest authRequest = new AuthBaiduRequest(AuthConfig.builder()
73 74
            .clientId("clientId")
            .clientSecret("clientSecret")
75
            .redirectUri("http://redirectUri")
76
            .build());
77
        // 返回授权页面,可自行跳转
78
        authRequest.authorize("state");
智布道's avatar
智布道 已提交
79
        // 授权登录后会返回code(auth_code(仅限支付宝)、authorization_code(仅限华为))、state,1.8.0版本后,可以用AuthCallback类作为回调接口的入参
80
        // 注:JustAuth默认保存state的时效为3分钟,3分钟内未使用则会自动清除过期的state
智布道's avatar
智布道 已提交
81
        authRequest.login(new AuthCallback());
82 83 84 85 86
    }

    @Test
    public void codingTest() {
        AuthRequest authRequest = new AuthCodingRequest(AuthConfig.builder()
87 88
            .clientId("clientId")
            .clientSecret("clientSecret")
89
            .redirectUri("http://redirectUri")
90
            .build());
91
        // 返回授权页面,可自行跳转
92
        authRequest.authorize("state");
智布道's avatar
智布道 已提交
93
        // 授权登录后会返回code(auth_code(仅限支付宝)、authorization_code(仅限华为))、state,1.8.0版本后,可以用AuthCallback类作为回调接口的入参
94
        // 注:JustAuth默认保存state的时效为3分钟,3分钟内未使用则会自动清除过期的state
智布道's avatar
智布道 已提交
95
        authRequest.login(new AuthCallback());
96 97 98 99 100
    }

    @Test
    public void tencentCloudTest() {
        AuthRequest authRequest = new AuthTencentCloudRequest(AuthConfig.builder()
101 102
            .clientId("clientId")
            .clientSecret("clientSecret")
103
            .redirectUri("http://redirectUri")
104
            .build());
105
        // 返回授权页面,可自行跳转
106
        authRequest.authorize("state");
智布道's avatar
智布道 已提交
107
        // 授权登录后会返回code(auth_code(仅限支付宝)、authorization_code(仅限华为))、state,1.8.0版本后,可以用AuthCallback类作为回调接口的入参
108
        // 注:JustAuth默认保存state的时效为3分钟,3分钟内未使用则会自动清除过期的state
智布道's avatar
智布道 已提交
109
        authRequest.login(new AuthCallback());
110 111 112 113 114
    }

    @Test
    public void oschinaTest() {
        AuthRequest authRequest = new AuthOschinaRequest(AuthConfig.builder()
115 116
            .clientId("clientId")
            .clientSecret("clientSecret")
117
            .redirectUri("http://redirectUri")
118
            .build());
119
        // 返回授权页面,可自行跳转
120
        authRequest.authorize("state");
智布道's avatar
智布道 已提交
121
        // 授权登录后会返回code(auth_code(仅限支付宝)、authorization_code(仅限华为))、state,1.8.0版本后,可以用AuthCallback类作为回调接口的入参
122
        // 注:JustAuth默认保存state的时效为3分钟,3分钟内未使用则会自动清除过期的state
智布道's avatar
智布道 已提交
123 124 125 126 127 128
        authRequest.login(new AuthCallback());
    }

    @Test
    public void alipayTest() {
        AuthRequest authRequest = new AuthAlipayRequest(AuthConfig.builder()
129 130
            .clientId("clientId")
            .clientSecret("clientSecret")
131
            .redirectUri("http://redirectUri")
132 133
            .alipayPublicKey("publicKey")
            .build());
134
        // 返回授权页面,可自行跳转
135
        authRequest.authorize("state");
智布道's avatar
智布道 已提交
136
        // 授权登录后会返回code(auth_code(仅限支付宝)、authorization_code(仅限华为))、state,1.8.0版本后,可以用AuthCallback类作为回调接口的入参
137
        // 注:JustAuth默认保存state的时效为3分钟,3分钟内未使用则会自动清除过期的state
智布道's avatar
智布道 已提交
138
        AuthResponse login = authRequest.login(new AuthCallback());
智布道's avatar
智布道 已提交
139
    }
140

智布道's avatar
智布道 已提交
141 142 143
    @Test
    public void qqTest() {
        AuthRequest authRequest = new AuthQqRequest(AuthConfig.builder()
144 145
            .clientId("clientId")
            .clientSecret("clientSecret")
146
            .redirectUri("http://redirectUri")
147
            .build());
148
        // 返回授权页面,可自行跳转
149
        authRequest.authorize("state");
智布道's avatar
智布道 已提交
150
        // 授权登录后会返回code(auth_code(仅限支付宝)、authorization_code(仅限华为))、state,1.8.0版本后,可以用AuthCallback类作为回调接口的入参
151
        // 注:JustAuth默认保存state的时效为3分钟,3分钟内未使用则会自动清除过期的state
智布道's avatar
智布道 已提交
152
        AuthResponse login = authRequest.login(new AuthCallback());
智布道's avatar
智布道 已提交
153 154
    }

155 156 157
    @Test
    public void wechatTest() {
        AuthRequest authRequest = new AuthWeChatRequest(AuthConfig.builder()
158 159
            .clientId("clientId")
            .clientSecret("clientSecret")
160
            .redirectUri("http://redirectUri")
161
            .build());
162
        // 返回授权页面,可自行跳转
163
        authRequest.authorize("state");
智布道's avatar
智布道 已提交
164
        // 授权登录后会返回code(auth_code(仅限支付宝)、authorization_code(仅限华为))、state,1.8.0版本后,可以用AuthCallback类作为回调接口的入参
165
        // 注:JustAuth默认保存state的时效为3分钟,3分钟内未使用则会自动清除过期的state
智布道's avatar
智布道 已提交
166 167 168 169 170 171
        AuthResponse login = authRequest.login(new AuthCallback());
    }

    @Test
    public void taobaoTest() {
        AuthRequest authRequest = new AuthTaobaoRequest(AuthConfig.builder()
172 173
            .clientId("clientId")
            .clientSecret("clientSecret")
174
            .redirectUri("http://redirectUri")
175
            .build());
176
        // 返回授权页面,可自行跳转
177
        authRequest.authorize("state");
智布道's avatar
智布道 已提交
178
        // 授权登录后会返回code(auth_code(仅限支付宝)、authorization_code(仅限华为))、state,1.8.0版本后,可以用AuthCallback类作为回调接口的入参
179
        // 注:JustAuth默认保存state的时效为3分钟,3分钟内未使用则会自动清除过期的state
智布道's avatar
智布道 已提交
180
        AuthResponse login = authRequest.login(new AuthCallback());
181
    }
182 183 184 185

    @Test
    public void googleTest() {
        AuthRequest authRequest = new AuthGoogleRequest(AuthConfig.builder()
186 187
            .clientId("clientId")
            .clientSecret("clientSecret")
188
            .redirectUri("http://redirectUri")
189
            .build());
190
        // 返回授权页面,可自行跳转
191
        authRequest.authorize("state");
智布道's avatar
智布道 已提交
192
        // 授权登录后会返回code(auth_code(仅限支付宝)、authorization_code(仅限华为))、state,1.8.0版本后,可以用AuthCallback类作为回调接口的入参
193
        // 注:JustAuth默认保存state的时效为3分钟,3分钟内未使用则会自动清除过期的state
智布道's avatar
智布道 已提交
194
        AuthResponse login = authRequest.login(new AuthCallback());
195
    }
智布道's avatar
智布道 已提交
196 197 198 199

    @Test
    public void facebookTest() {
        AuthRequest authRequest = new AuthFacebookRequest(AuthConfig.builder()
200 201
            .clientId("clientId")
            .clientSecret("clientSecret")
202
            .redirectUri("https://redirectUri")
203
            .build());
204
        // 返回授权页面,可自行跳转
205
        authRequest.authorize("state");
智布道's avatar
智布道 已提交
206
        // 授权登录后会返回code(auth_code(仅限支付宝)、authorization_code(仅限华为))、state,1.8.0版本后,可以用AuthCallback类作为回调接口的入参
207
        // 注:JustAuth默认保存state的时效为3分钟,3分钟内未使用则会自动清除过期的state
智布道's avatar
智布道 已提交
208 209 210 211 212 213
        AuthResponse login = authRequest.login(new AuthCallback());
    }

    @Test
    public void douyinTest() {
        AuthRequest authRequest = new AuthDouyinRequest(AuthConfig.builder()
214 215
            .clientId("clientId")
            .clientSecret("clientSecret")
216
            .redirectUri("http://redirectUri")
217
            .build());
218
        // 返回授权页面,可自行跳转
219
        authRequest.authorize("state");
智布道's avatar
智布道 已提交
220
        // 授权登录后会返回code(auth_code(仅限支付宝)、authorization_code(仅限华为))、state,1.8.0版本后,可以用AuthCallback类作为回调接口的入参
221
        // 注:JustAuth默认保存state的时效为3分钟,3分钟内未使用则会自动清除过期的state
智布道's avatar
智布道 已提交
222 223 224 225 226 227
        AuthResponse login = authRequest.login(new AuthCallback());
    }

    @Test
    public void linkedinTest() {
        AuthRequest authRequest = new AuthLinkedinRequest(AuthConfig.builder()
228 229
            .clientId("clientId")
            .clientSecret("clientSecret")
230
            .redirectUri("http://redirectUri")
231
            .build());
232
        // 返回授权页面,可自行跳转
233
        authRequest.authorize("state");
智布道's avatar
智布道 已提交
234
        // 授权登录后会返回code(auth_code(仅限支付宝)、authorization_code(仅限华为))、state,1.8.0版本后,可以用AuthCallback类作为回调接口的入参
235
        // 注:JustAuth默认保存state的时效为3分钟,3分钟内未使用则会自动清除过期的state
智布道's avatar
智布道 已提交
236
        AuthResponse login = authRequest.login(new AuthCallback());
智布道's avatar
智布道 已提交
237
    }
238 239 240 241

    @Test
    public void microsoftTest() {
        AuthRequest authRequest = new AuthMicrosoftRequest(AuthConfig.builder()
242 243
            .clientId("clientId")
            .clientSecret("clientSecret")
244
            .redirectUri("http://redirectUri")
245
            .build());
246
        // 返回授权页面,可自行跳转
247
        authRequest.authorize("state");
智布道's avatar
智布道 已提交
248
        // 授权登录后会返回code(auth_code(仅限支付宝)、authorization_code(仅限华为))、state,1.8.0版本后,可以用AuthCallback类作为回调接口的入参
249
        // 注:JustAuth默认保存state的时效为3分钟,3分钟内未使用则会自动清除过期的state
智布道's avatar
智布道 已提交
250
        AuthResponse login = authRequest.login(new AuthCallback());
251
    }
252 253 254 255

    @Test
    public void miTest() {
        AuthRequest authRequest = new AuthMiRequest(AuthConfig.builder()
256 257
            .clientId("clientId")
            .clientSecret("clientSecret")
258
            .redirectUri("http://redirectUri")
259
            .build());
260
        // 返回授权页面,可自行跳转
261
        authRequest.authorize("state");
智布道's avatar
智布道 已提交
262
        // 授权登录后会返回code(auth_code(仅限支付宝)、authorization_code(仅限华为))、state,1.8.0版本后,可以用AuthCallback类作为回调接口的入参
263
        // 注:JustAuth默认保存state的时效为3分钟,3分钟内未使用则会自动清除过期的state
智布道's avatar
智布道 已提交
264 265 266 267 268 269
        AuthResponse login = authRequest.login(new AuthCallback());
    }

    @Test
    public void toutiaoTest() {
        AuthRequest authRequest = new AuthToutiaoRequest(AuthConfig.builder()
270 271
            .clientId("clientId")
            .clientSecret("clientSecret")
272
            .redirectUri("http://redirectUri")
273
            .build());
274
        // 返回授权页面,可自行跳转
275
        authRequest.authorize("state");
智布道's avatar
智布道 已提交
276
        // 授权登录后会返回code(auth_code(仅限支付宝)、authorization_code(仅限华为))、state,1.8.0版本后,可以用AuthCallback类作为回调接口的入参
277
        // 注:JustAuth默认保存state的时效为3分钟,3分钟内未使用则会自动清除过期的state
智布道's avatar
智布道 已提交
278
        AuthResponse login = authRequest.login(new AuthCallback());
279
    }
智布道's avatar
智布道 已提交
280 281 282 283 284 285

    @Test
    public void huaweiTest() {
        AuthRequest authRequest = new AuthHuaweiRequest(AuthConfig.builder()
            .clientId("clientId")
            .clientSecret("clientSecret")
286 287 288 289
            .redirectUri("http://redirectUri")
            .build());
        // 返回授权页面,可自行跳转
        authRequest.authorize("state");
智布道's avatar
智布道 已提交
290
        // 授权登录后会返回code(auth_code(仅限支付宝)、authorization_code(仅限华为))、state,1.8.0版本后,可以用AuthCallback类作为回调接口的入参
291 292 293 294 295 296 297 298 299 300 301
        // 注:JustAuth默认保存state的时效为3分钟,3分钟内未使用则会自动清除过期的state
        AuthResponse login = authRequest.login(new AuthCallback());
    }

    @Test
    public void weChatEnterpriseTest() {
        AuthRequest authRequest = new AuthWeChatEnterpriseRequest(AuthConfig.builder()
            .clientId("clientId")
            .clientSecret("clientSecret")
            .redirectUri("http://redirectUri")
            .agentId("agentId")
智布道's avatar
智布道 已提交
302 303 304
            .build());
        // 返回授权页面,可自行跳转
        authRequest.authorize("state");
智布道's avatar
智布道 已提交
305
        // 授权登录后会返回code(auth_code(仅限支付宝)、authorization_code(仅限华为))、state,1.8.0版本后,可以用AuthCallback类作为回调接口的入参
智布道's avatar
智布道 已提交
306 307 308
        // 注:JustAuth默认保存state的时效为3分钟,3分钟内未使用则会自动清除过期的state
        AuthResponse login = authRequest.login(new AuthCallback());
    }
309
}