AuthSource.java 2.1 KB
Newer Older
1
package me.zhyd.oauth.config;
智布道's avatar
智布道 已提交
2

3
import me.zhyd.oauth.enums.AuthResponseStatus;
4
import me.zhyd.oauth.exception.AuthException;
5
import me.zhyd.oauth.model.AuthCallback;
智布道's avatar
智布道 已提交
6 7

/**
8 9 10 11 12 13
 * OAuth平台的API地址的统一接口,提供以下方法:
 * 1) {@link AuthSource#authorize()}: 获取授权url. 必须实现
 * 2) {@link AuthSource#accessToken()}: 获取accessToken的url. 必须实现
 * 3) {@link AuthSource#userInfo()}: 获取用户信息的url. 必须实现
 * 4) {@link AuthSource#revoke()}: 获取取消授权的url. 非必须实现接口(部分平台不支持)
 * 5) {@link AuthSource#refresh()}: 获取刷新授权的url. 非必须实现接口(部分平台不支持)
14 15 16
 * <p>
 * 注:
 * ①、如需通过JustAuth扩展实现第三方授权,请参考{@link AuthDefaultSource}自行创建对应的枚举类并实现{@link AuthSource}接口
智布道's avatar
智布道 已提交
17
 * ②、如果不是使用的枚举类,那么在授权成功后获取用户信息时,需要单独处理source字段的赋值
18
 * ③、如果扩展了对应枚举类时,在{@link me.zhyd.oauth.request.AuthRequest#login(AuthCallback)}中可以通过{@code xx.toString()}获取对应的source
智布道's avatar
智布道 已提交
19 20
 *
 * @author yadong.zhang (yadong.zhang0415(a)gmail.com)
21
 * @version 1.0
智布道's avatar
智布道 已提交
22
 * @since 1.12.0
智布道's avatar
智布道 已提交
23
 */
24
public interface AuthSource {
智布道's avatar
智布道 已提交
25

智布道's avatar
智布道 已提交
26 27
    /**
     * 授权的api
智布道's avatar
智布道 已提交
28 29
     *
     * @return url
智布道's avatar
智布道 已提交
30
     */
31
    String authorize();
智布道's avatar
智布道 已提交
32

智布道's avatar
智布道 已提交
33 34
    /**
     * 获取accessToken的api
智布道's avatar
智布道 已提交
35 36
     *
     * @return url
智布道's avatar
智布道 已提交
37
     */
38
    String accessToken();
智布道's avatar
智布道 已提交
39

智布道's avatar
智布道 已提交
40 41
    /**
     * 获取用户信息的api
智布道's avatar
智布道 已提交
42 43
     *
     * @return url
智布道's avatar
智布道 已提交
44
     */
45
    String userInfo();
智布道's avatar
智布道 已提交
46

智布道's avatar
智布道 已提交
47 48
    /**
     * 取消授权的api
智布道's avatar
智布道 已提交
49 50
     *
     * @return url
智布道's avatar
智布道 已提交
51
     */
52
    default String revoke() {
智布道's avatar
智布道 已提交
53
        throw new AuthException(AuthResponseStatus.UNSUPPORTED);
54
    }
智布道's avatar
智布道 已提交
55

智布道's avatar
智布道 已提交
56 57
    /**
     * 刷新授权的api
智布道's avatar
智布道 已提交
58 59
     *
     * @return url
智布道's avatar
智布道 已提交
60
     */
61
    default String refresh() {
智布道's avatar
智布道 已提交
62
        throw new AuthException(AuthResponseStatus.UNSUPPORTED);
63
    }
智布道's avatar
智布道 已提交
64 65 66 67 68 69 70 71 72 73 74 75

    /**
     * 获取Source的字符串名字
     *
     * @return name
     */
    default String getName() {
        if (this instanceof Enum) {
            return String.valueOf(this);
        }
        return this.getClass().getSimpleName();
    }
H
Hongwei Peng 已提交
76
}