JustAuth/src/test/java/me/zhyd/oauth/AuthRequestTest.java
2019-03-22 18:03:26 +08:00

71 lines
2.4 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package me.zhyd.oauth;
import me.zhyd.oauth.config.AuthConfig;
import me.zhyd.oauth.request.*;
import org.junit.Test;
import java.io.IOException;
/**
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
* @version 1.0
* @website https://www.zhyd.me
* @date 2019/2/18 13:10
* @since 1.8
*/
public class AuthRequestTest {
@Test
public void giteeTest() throws IOException {
AuthRequest authRequest = new AuthGiteeRequest(AuthConfig.builder()
.clientId("clientId")
.clientSecret("clientSecret")
.redirectUri("redirectUri")
.build());
// 返回授权页面,可自行调整
authRequest.authorize();
// 授权登录后会返回一个code用这个code进行登录
authRequest.login("code");
}
@Test
public void githubTest() throws IOException {
AuthRequest authRequest = new AuthGithubRequest(AuthConfig.builder()
.clientId("clientId")
.clientSecret("clientSecret")
.redirectUri("redirectUri")
.build());
// 返回授权页面,可自行调整
authRequest.authorize();
// 授权登录后会返回一个code用这个code进行登录
authRequest.login("code");
}
@Test
public void weiboTest() throws IOException {
AuthRequest authRequest = new AuthWeiboRequest(AuthConfig.builder()
.clientId("clientId")
.clientSecret("clientSecret")
.redirectUri("redirectUri")
.build());
// 返回授权页面,可自行调整
authRequest.authorize();
// 授权登录后会返回一个code用这个code进行登录
authRequest.login("code");
}
@Test
public void dingdingTest() {
AuthRequest authRequest = new AuthDingTalkRequest(AuthConfig.builder()
.clientId("dingoa2q6o3fomfk6vdqzy")
.clientSecret("d5w75-R-yNtQsq_Ya_r50gOsKOy9WlmrlUOJkUJXKvsQp7NDPRHsj0epJriiN3yO")
.redirectUri("http://61.149.7.121:8443/oauth/dingtalk/callback")
.build());
// 返回授权页面,可自行调整
String url = authRequest.authorize();
System.out.println(url);
// 授权登录后会返回一个code用这个code进行登录
// authRequest.login("code");
}
}