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

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

import javax.servlet.http.HttpServletResponse;

/**
 * @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
智布道's avatar
智布道 已提交
19 20
    public void giteeTest() {
        HttpServletResponse response = null;
21 22 23 24 25 26 27 28 29
        AuthRequest authRequest = new AuthGiteeRequest(AuthConfig.builder()
                .clientId("clientId")
                .clientSecret("clientSecret")
                .redirectUri("redirectUri")
                .build());
        // 自动跳转到授权页面
        authRequest.authorize(response);
        // 返回授权页面,可自行调整
        authRequest.authorize();
智布道's avatar
智布道 已提交
30
        // 授权登录后会返回一个code,用这个code进行登录
智布道's avatar
智布道 已提交
31
        authRequest.login("code");
32 33 34
    }

    @Test
智布道's avatar
智布道 已提交
35 36
    public void githubTest() {
        HttpServletResponse response = null;
37 38 39 40 41 42 43 44 45
        AuthRequest authRequest = new AuthGithubRequest(AuthConfig.builder()
                .clientId("clientId")
                .clientSecret("clientSecret")
                .redirectUri("redirectUri")
                .build());
        // 自动跳转到授权页面
        authRequest.authorize(response);
        // 返回授权页面,可自行调整
        authRequest.authorize();
智布道's avatar
智布道 已提交
46
        // 授权登录后会返回一个code,用这个code进行登录
智布道's avatar
智布道 已提交
47
        authRequest.login("code");
48 49 50
    }

    @Test
智布道's avatar
智布道 已提交
51 52
    public void weiboTest() {
        HttpServletResponse response = null;
53 54 55 56 57 58 59 60 61
        AuthRequest authRequest = new AuthWeiboRequest(AuthConfig.builder()
                .clientId("clientId")
                .clientSecret("clientSecret")
                .redirectUri("redirectUri")
                .build());
        // 自动跳转到授权页面
        authRequest.authorize(response);
        // 返回授权页面,可自行调整
        authRequest.authorize();
智布道's avatar
智布道 已提交
62
        // 授权登录后会返回一个code,用这个code进行登录
智布道's avatar
智布道 已提交
63
        authRequest.login("code");
64
    }
智布道's avatar
智布道 已提交
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81

    @Test
    public void dingdingTest() {
        HttpServletResponse response = null;
        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());
        // 自动跳转到授权页面
//        authRequest.authorize(response);
        // 返回授权页面,可自行调整
        String url = authRequest.authorize();
        System.out.println(url);
        // 授权登录后会返回一个code,用这个code进行登录
//        authRequest.login("code");
    }
82
}