AuthGiteeUrlBuilder.java 1.7 KB
Newer Older
1 2 3
package me.zhyd.oauth.url;

import me.zhyd.oauth.config.AuthSource;
智布道's avatar
智布道 已提交
4 5
import me.zhyd.oauth.exception.AuthException;
import me.zhyd.oauth.model.AuthResponseStatus;
6 7 8 9 10 11 12 13 14 15 16
import me.zhyd.oauth.url.entity.*;

import java.text.MessageFormat;

/**
 * Gitee相关的URL构建类
 *
 * @author yadong.zhang (yadong.zhang0415(a)gmail.com)
 * @version 1.0
 * @since 1.8
 */
智布道's avatar
智布道 已提交
17
public class AuthGiteeUrlBuilder extends AuthDefaultUrlBuilder {
18 19 20 21 22 23

    private static final String GITEE_ACCESS_TOKEN_PATTERN = "{0}?client_id={1}&client_secret={2}&grant_type=authorization_code&code={3}&redirect_uri={4}";
    private static final String GITEE_USER_INFO_PATTERN = "{0}?access_token={1}";
    private static final String GITEE_AUTHORIZE_PATTERN = "{0}?client_id={1}&response_type=code&redirect_uri={2}&state={3}";

    @Override
智布道's avatar
智布道 已提交
24 25
    public String getAccessTokenUrl(String code) {
        return MessageFormat.format(GITEE_ACCESS_TOKEN_PATTERN, AuthSource.GITEE.accessToken(), config.getClientId(), config.getClientSecret(), code, config.getRedirectUri());
26 27 28 29 30 31 32 33
    }

    @Override
    public String getUserInfoUrl(AuthUserInfoEntity userInfoEntity) {
        return MessageFormat.format(GITEE_USER_INFO_PATTERN, AuthSource.GITEE.userInfo(), userInfoEntity.getAccessToken());
    }

    @Override
智布道's avatar
智布道 已提交
34
    public String getAuthorizeUrl() {
35 36 37 38
        return MessageFormat.format(GITEE_AUTHORIZE_PATTERN, AuthSource.GITEE.authorize(), config.getClientId(), config.getRedirectUri(), this.getRealState(config.getState()));
    }

    @Override
智布道's avatar
智布道 已提交
39
    public String getRefreshUrl(String refreshToken) {
智布道's avatar
智布道 已提交
40
        throw new AuthException(AuthResponseStatus.NOT_IMPLEMENTED);
41 42 43
    }

    @Override
智布道's avatar
智布道 已提交
44
    public String getRevokeUrl(String accessToken) {
智布道's avatar
智布道 已提交
45
        throw new AuthException(AuthResponseStatus.NOT_IMPLEMENTED);
46 47
    }
}