AuthTaobaoUrlBuilder.java 1.6 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;
智布道's avatar
智布道 已提交
6
import me.zhyd.oauth.url.entity.AuthUserInfoEntity;
7 8 9 10 11 12 13 14 15 16

import java.text.MessageFormat;

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

    private static final String TAOBAO_AUTHORIZE_PATTERN = "{0}?response_type=code&client_id={1}&redirect_uri={2}&state={3}&view=web";
    private static final String TAOBAO_ACCESS_TOKEN_PATTERN = "{0}?client_id={1}&client_secret={2}&code={3}&redirect_uri={4}&grant_type=authorization_code";

    @Override
智布道's avatar
智布道 已提交
23 24
    public String getAccessTokenUrl(String code) {
        return MessageFormat.format(TAOBAO_ACCESS_TOKEN_PATTERN, AuthSource.TAOBAO.accessToken(), config.getClientId(), config.getClientSecret(), code, config.getRedirectUri());
25 26 27 28
    }

    @Override
    public String getUserInfoUrl(AuthUserInfoEntity userInfoEntity) {
智布道's avatar
智布道 已提交
29
        throw new AuthException(AuthResponseStatus.NOT_IMPLEMENTED);
30 31 32
    }

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

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

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