AuthRequestTest.java 2.2 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
package me.zhyd.oauth;

import me.zhyd.oauth.config.AuthConfig;
import me.zhyd.oauth.request.AuthGiteeRequest;
import me.zhyd.oauth.request.AuthGithubRequest;
import me.zhyd.oauth.request.AuthRequest;
import me.zhyd.oauth.request.AuthWeiboRequest;
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
    public void giteeTest(HttpServletResponse response) {
        AuthRequest authRequest = new AuthGiteeRequest(AuthConfig.builder()
                .clientId("clientId")
                .clientSecret("clientSecret")
                .redirectUri("redirectUri")
                .build());
        // 自动跳转到授权页面
        authRequest.authorize(response);
        // 返回授权页面,可自行调整
        authRequest.authorize();
智布道's avatar
智布道 已提交
32 33
        // 授权登陆后会返回一个code,用这个code进行登录
        authRequest.login("code");
34 35 36 37 38 39 40 41 42 43 44 45 46
    }

    @Test
    public void githubTest(HttpServletResponse response) {
        AuthRequest authRequest = new AuthGithubRequest(AuthConfig.builder()
                .clientId("clientId")
                .clientSecret("clientSecret")
                .redirectUri("redirectUri")
                .build());
        // 自动跳转到授权页面
        authRequest.authorize(response);
        // 返回授权页面,可自行调整
        authRequest.authorize();
智布道's avatar
智布道 已提交
47 48
        // 授权登陆后会返回一个code,用这个code进行登录
        authRequest.login("code");
49 50 51 52 53 54 55 56 57 58 59 60 61
    }

    @Test
    public void weiboTest(HttpServletResponse response) {
        AuthRequest authRequest = new AuthWeiboRequest(AuthConfig.builder()
                .clientId("clientId")
                .clientSecret("clientSecret")
                .redirectUri("redirectUri")
                .build());
        // 自动跳转到授权页面
        authRequest.authorize(response);
        // 返回授权页面,可自行调整
        authRequest.authorize();
智布道's avatar
智布道 已提交
62 63
        // 授权登陆后会返回一个code,用这个code进行登录
        authRequest.login("code");
64 65
    }
}