提交 6b196456 编写于 作者: 智布道's avatar 智布道 👁

从UrlBuilder中拆分qq、淘宝、腾讯云和头条相关的URL

上级 af723a8b
......@@ -11,9 +11,12 @@ import me.zhyd.oauth.model.AuthCallback;
import me.zhyd.oauth.model.AuthToken;
import me.zhyd.oauth.model.AuthUser;
import me.zhyd.oauth.model.AuthUserGender;
import me.zhyd.oauth.url.QqUrlBuilder;
import me.zhyd.oauth.url.entity.AuthAccessTokenEntity;
import me.zhyd.oauth.url.entity.AuthAuthorizeEntity;
import me.zhyd.oauth.url.entity.AuthUserInfoEntity;
import me.zhyd.oauth.utils.GlobalAuthUtil;
import me.zhyd.oauth.utils.StringUtils;
import me.zhyd.oauth.utils.UrlBuilder;
import java.util.Map;
......@@ -27,13 +30,15 @@ import java.util.Map;
*/
public class AuthQqRequest extends BaseAuthRequest {
public AuthQqRequest(AuthConfig config) {
super(config, AuthSource.QQ);
super(config, AuthSource.QQ, new QqUrlBuilder());
}
@Override
protected AuthToken getAccessToken(AuthCallback authCallback) {
String accessTokenUrl = UrlBuilder.getQqAccessTokenUrl(config.getClientId(), config.getClientSecret(),
authCallback.getCode(), config.getRedirectUri());
String accessTokenUrl = this.urlBuilder.getAccessTokenUrl(AuthAccessTokenEntity.builder()
.config(config)
.code(authCallback.getCode())
.build());
HttpResponse response = HttpRequest.get(accessTokenUrl).execute();
Map<String, String> accessTokenObject = GlobalAuthUtil.parseStringToMap(response.body());
if (!accessTokenObject.containsKey("access_token")) {
......@@ -50,7 +55,11 @@ public class AuthQqRequest extends BaseAuthRequest {
protected AuthUser getUserInfo(AuthToken authToken) {
String accessToken = authToken.getAccessToken();
String openId = this.getOpenId(authToken);
HttpResponse response = HttpRequest.get(UrlBuilder.getQqUserInfoUrl(config.getClientId(), accessToken, openId))
HttpResponse response = HttpRequest.get(this.urlBuilder.getUserInfoUrl(AuthUserInfoEntity.builder()
.clientId(config.getClientId())
.accessToken(accessToken)
.openId(openId)
.build()))
.execute();
JSONObject object = JSONObject.parseObject(response.body());
if (object.getIntValue("ret") != 0) {
......@@ -81,13 +90,14 @@ public class AuthQqRequest extends BaseAuthRequest {
*/
@Override
public String authorize() {
return UrlBuilder.getQqAuthorizeUrl(config.getClientId(), config.getRedirectUri(), config.getState());
return this.urlBuilder.getAuthorizeUrl(AuthAuthorizeEntity.builder()
.config(config)
.build());
}
private String getOpenId(AuthToken authToken) {
String accessToken = authToken.getAccessToken();
HttpResponse response = HttpRequest.get(UrlBuilder.getQqOpenidUrl("https://graph.qq.com/oauth2.0/me", accessToken, config.isUnionId()))
.execute();
HttpResponse response = HttpRequest.get(this.urlBuilder.getOpenIdUrl(accessToken, config.isUnionId())).execute();
if (response.isOk()) {
String body = response.body();
String removePrefix = StrUtil.replace(body, "callback(", "");
......
......@@ -10,8 +10,10 @@ import me.zhyd.oauth.model.AuthCallback;
import me.zhyd.oauth.model.AuthToken;
import me.zhyd.oauth.model.AuthUser;
import me.zhyd.oauth.model.AuthUserGender;
import me.zhyd.oauth.url.TaobaoUrlBuilder;
import me.zhyd.oauth.url.entity.AuthAccessTokenEntity;
import me.zhyd.oauth.url.entity.AuthAuthorizeEntity;
import me.zhyd.oauth.utils.GlobalAuthUtil;
import me.zhyd.oauth.utils.UrlBuilder;
/**
* 淘宝登录
......@@ -23,7 +25,7 @@ import me.zhyd.oauth.utils.UrlBuilder;
public class AuthTaobaoRequest extends BaseAuthRequest {
public AuthTaobaoRequest(AuthConfig config) {
super(config, AuthSource.TAOBAO);
super(config, AuthSource.TAOBAO, new TaobaoUrlBuilder());
}
@Override
......@@ -34,8 +36,10 @@ public class AuthTaobaoRequest extends BaseAuthRequest {
@Override
protected AuthUser getUserInfo(AuthToken authToken) {
String accessCode = authToken.getAccessCode();
HttpResponse response = HttpRequest.post(UrlBuilder.getTaobaoAccessTokenUrl(this.config.getClientId(), this.config
.getClientSecret(), accessCode, this.config.getRedirectUri())).execute();
HttpResponse response = HttpRequest.post(this.urlBuilder.getAccessTokenUrl(AuthAccessTokenEntity.builder()
.config(config)
.code(accessCode)
.build())).execute();
JSONObject accessTokenObject = JSONObject.parseObject(response.body());
if (accessTokenObject.containsKey("error")) {
throw new AuthException(ResponseStatus.FAILURE + ":" + accessTokenObject.getString("error_description"));
......@@ -64,6 +68,8 @@ public class AuthTaobaoRequest extends BaseAuthRequest {
*/
@Override
public String authorize() {
return UrlBuilder.getTaobaoAuthorizeUrl(config.getClientId(), config.getRedirectUri(), config.getState());
return this.urlBuilder.getAuthorizeUrl(AuthAuthorizeEntity.builder()
.config(config)
.build());
}
}
......@@ -10,7 +10,10 @@ import me.zhyd.oauth.model.AuthCallback;
import me.zhyd.oauth.model.AuthToken;
import me.zhyd.oauth.model.AuthUser;
import me.zhyd.oauth.model.AuthUserGender;
import me.zhyd.oauth.utils.UrlBuilder;
import me.zhyd.oauth.url.TencentCloudUrlBuilder;
import me.zhyd.oauth.url.entity.AuthAccessTokenEntity;
import me.zhyd.oauth.url.entity.AuthAuthorizeEntity;
import me.zhyd.oauth.url.entity.AuthUserInfoEntity;
/**
* 腾讯云登录
......@@ -22,12 +25,15 @@ import me.zhyd.oauth.utils.UrlBuilder;
public class AuthTencentCloudRequest extends BaseAuthRequest {
public AuthTencentCloudRequest(AuthConfig config) {
super(config, AuthSource.TENCENT_CLOUD);
super(config, AuthSource.TENCENT_CLOUD, new TencentCloudUrlBuilder());
}
@Override
protected AuthToken getAccessToken(AuthCallback authCallback) {
String accessTokenUrl = UrlBuilder.getTencentCloudAccessTokenUrl(config.getClientId(), config.getClientSecret(), authCallback.getCode());
String accessTokenUrl = this.urlBuilder.getAccessTokenUrl(AuthAccessTokenEntity.builder()
.config(config)
.code(authCallback.getCode())
.build());
HttpResponse response = HttpRequest.get(accessTokenUrl).execute();
JSONObject accessTokenObject = JSONObject.parseObject(response.body());
if (accessTokenObject.getIntValue("code") != 0) {
......@@ -43,7 +49,9 @@ public class AuthTencentCloudRequest extends BaseAuthRequest {
@Override
protected AuthUser getUserInfo(AuthToken authToken) {
String accessToken = authToken.getAccessToken();
HttpResponse response = HttpRequest.get(UrlBuilder.getTencentCloudUserInfoUrl(accessToken)).execute();
HttpResponse response = HttpRequest.get(this.urlBuilder.getUserInfoUrl(AuthUserInfoEntity.builder()
.accessToken(accessToken)
.build())).execute();
JSONObject object = JSONObject.parseObject(response.body());
if (object.getIntValue("code") != 0) {
throw new AuthException(object.getString("msg"));
......@@ -72,6 +80,8 @@ public class AuthTencentCloudRequest extends BaseAuthRequest {
*/
@Override
public String authorize() {
return UrlBuilder.getTencentCloudAuthorizeUrl(config.getClientId(), config.getRedirectUri(), config.getState());
return this.urlBuilder.getAuthorizeUrl(AuthAuthorizeEntity.builder()
.config(config)
.build());
}
}
......@@ -7,8 +7,14 @@ import me.zhyd.oauth.config.AuthConfig;
import me.zhyd.oauth.config.AuthSource;
import me.zhyd.oauth.enums.AuthToutiaoErrorCode;
import me.zhyd.oauth.exception.AuthException;
import me.zhyd.oauth.model.*;
import me.zhyd.oauth.utils.UrlBuilder;
import me.zhyd.oauth.model.AuthCallback;
import me.zhyd.oauth.model.AuthToken;
import me.zhyd.oauth.model.AuthUser;
import me.zhyd.oauth.model.AuthUserGender;
import me.zhyd.oauth.url.ToutiaoUrlBuilder;
import me.zhyd.oauth.url.entity.AuthAccessTokenEntity;
import me.zhyd.oauth.url.entity.AuthAuthorizeEntity;
import me.zhyd.oauth.url.entity.AuthUserInfoEntity;
/**
* 今日头条登录
......@@ -20,12 +26,15 @@ import me.zhyd.oauth.utils.UrlBuilder;
public class AuthToutiaoRequest extends BaseAuthRequest {
public AuthToutiaoRequest(AuthConfig config) {
super(config, AuthSource.TOUTIAO);
super(config, AuthSource.TOUTIAO, new ToutiaoUrlBuilder());
}
@Override
protected AuthToken getAccessToken(AuthCallback authCallback) {
String accessTokenUrl = UrlBuilder.getToutiaoAccessTokenUrl(config.getClientId(), config.getClientSecret(), authCallback.getCode());
String accessTokenUrl = this.urlBuilder.getAccessTokenUrl(AuthAccessTokenEntity.builder()
.config(config)
.code(authCallback.getCode())
.build());
HttpResponse response = HttpRequest.get(accessTokenUrl).execute();
JSONObject accessTokenObject = JSONObject.parseObject(response.body());
......@@ -42,7 +51,10 @@ public class AuthToutiaoRequest extends BaseAuthRequest {
@Override
protected AuthUser getUserInfo(AuthToken authToken) {
HttpResponse userResponse = HttpRequest.get(UrlBuilder.getToutiaoUserInfoUrl(config.getClientId(), authToken.getAccessToken())).execute();
HttpResponse userResponse = HttpRequest.get(this.urlBuilder.getUserInfoUrl(AuthUserInfoEntity.builder()
.clientId(config.getClientId())
.accessToken(authToken.getAccessToken())
.build())).execute();
JSONObject userProfile = JSONObject.parseObject(userResponse.body());
......@@ -74,6 +86,8 @@ public class AuthToutiaoRequest extends BaseAuthRequest {
*/
@Override
public String authorize() {
return UrlBuilder.getToutiaoAuthorizeUrl(config.getClientId(), config.getRedirectUri(), config.getState());
return this.urlBuilder.getAuthorizeUrl(AuthAuthorizeEntity.builder()
.config(config)
.build());
}
}
package me.zhyd.oauth.url;
import me.zhyd.oauth.exception.AuthException;
import me.zhyd.oauth.request.ResponseStatus;
import me.zhyd.oauth.url.entity.*;
import me.zhyd.oauth.utils.StringUtils;
......@@ -50,6 +52,17 @@ public abstract class AbstractUrlBuilder {
*/
public abstract String getRevokeUrl(AuthRevokeEntity revokeEntity);
/**
* 获取openId的地址,目前只有qq平台需要,故不需要子类强制重写
*
* @param accessToken
* @param unionid
* @return
*/
public String getOpenIdUrl(String accessToken, boolean unionid) {
throw new AuthException(ResponseStatus.NOT_IMPLEMENTED);
}
/**
* 获取state,如果为空, 则默认去当前日期的时间戳
*
......
package me.zhyd.oauth.url;
import me.zhyd.oauth.config.AuthConfig;
import me.zhyd.oauth.config.AuthSource;
import me.zhyd.oauth.url.entity.*;
import java.text.MessageFormat;
/**
* QQ相关的URL构建类
*
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
* @version 1.0
* @since 1.8
*/
public class QqUrlBuilder extends AbstractUrlBuilder {
private static final String QQ_ACCESS_TOKEN_PATTERN = "{0}?client_id={1}&client_secret={2}&grant_type=authorization_code&code={3}&redirect_uri={4}";
private static final String QQ_USER_INFO_PATTERN = "{0}?oauth_consumer_key={1}&access_token={2}&openid={3}";
private static final String QQ_AUTHORIZE_PATTERN = "{0}?client_id={1}&response_type=code&redirect_uri={2}&state={3}";
private static final String QQ_OPENID_PATTERN = "{0}?access_token={1}&unionid={2}";
@Override
public String getAccessTokenUrl(AuthAccessTokenEntity accessTokenEntity) {
AuthConfig config = accessTokenEntity.getConfig();
return MessageFormat.format(QQ_ACCESS_TOKEN_PATTERN, AuthSource.QQ.accessToken(), config.getClientId(),
config.getClientSecret(), accessTokenEntity.getCode(), config.getRedirectUri());
}
@Override
public String getUserInfoUrl(AuthUserInfoEntity userInfoEntity) {
return MessageFormat.format(QQ_USER_INFO_PATTERN, AuthSource.QQ.userInfo(), userInfoEntity.getClientId(), userInfoEntity.getAccessToken(), userInfoEntity.getOpenId());
}
@Override
public String getAuthorizeUrl(AuthAuthorizeEntity authorizeEntity) {
AuthConfig config = authorizeEntity.getConfig();
return MessageFormat.format(QQ_AUTHORIZE_PATTERN, AuthSource.QQ.authorize(), config.getClientId(),
config.getRedirectUri(), this.getRealState(config.getState()));
}
@Override
public String getRefreshUrl(AuthRefreshTokenEntity refreshTokenEntity) {
return null;
}
@Override
public String getRevokeUrl(AuthRevokeEntity revokeEntity) {
return null;
}
@Override
public String getOpenIdUrl(String accessToken, boolean unionid) {
return MessageFormat.format(QQ_OPENID_PATTERN, "https://graph.qq.com/oauth2.0/me", accessToken, unionid ? 1 : 0);
}
}
package me.zhyd.oauth.url;
import me.zhyd.oauth.config.AuthConfig;
import me.zhyd.oauth.config.AuthSource;
import me.zhyd.oauth.url.entity.*;
import java.text.MessageFormat;
/**
* 淘宝相关的URL构建类
*
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
* @version 1.0
* @since 1.8
*/
public class TaobaoUrlBuilder extends AbstractUrlBuilder {
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
public String getAccessTokenUrl(AuthAccessTokenEntity accessTokenEntity) {
AuthConfig config = accessTokenEntity.getConfig();
return MessageFormat.format(TAOBAO_ACCESS_TOKEN_PATTERN, AuthSource.TAOBAO.accessToken(), config.getClientId(),
config.getClientSecret(), accessTokenEntity.getCode(), config.getRedirectUri());
}
@Override
public String getUserInfoUrl(AuthUserInfoEntity userInfoEntity) {
return null;
}
@Override
public String getAuthorizeUrl(AuthAuthorizeEntity authorizeEntity) {
AuthConfig config = authorizeEntity.getConfig();
return MessageFormat.format(TAOBAO_AUTHORIZE_PATTERN, AuthSource.TAOBAO.authorize(), config.getClientId(),
config.getRedirectUri(), this.getRealState(config.getState()));
}
@Override
public String getRefreshUrl(AuthRefreshTokenEntity refreshTokenEntity) {
return null;
}
@Override
public String getRevokeUrl(AuthRevokeEntity revokeEntity) {
return null;
}
}
package me.zhyd.oauth.url;
import me.zhyd.oauth.config.AuthConfig;
import me.zhyd.oauth.config.AuthSource;
import me.zhyd.oauth.url.entity.*;
import java.text.MessageFormat;
/**
* 今日头条相关的URL构建类
*
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
* @version 1.0
* @since 1.8
*/
public class TencentCloudUrlBuilder extends AbstractUrlBuilder {
private static final String TENCENT_ACCESS_TOKEN_PATTERN = "{0}?client_id={1}&client_secret={2}&grant_type=authorization_code&code={3}";
private static final String TENCENT_USER_INFO_PATTERN = "{0}?access_token={1}";
private static final String TENCENT_AUTHORIZE_PATTERN = "{0}?client_id={1}&response_type=code&redirect_uri={2}&scope=user&state={3}";
@Override
public String getAccessTokenUrl(AuthAccessTokenEntity accessTokenEntity) {
AuthConfig config = accessTokenEntity.getConfig();
return MessageFormat.format(TENCENT_ACCESS_TOKEN_PATTERN, AuthSource.TENCENT_CLOUD.accessToken(), config.getClientId(),
config.getClientSecret(), accessTokenEntity.getCode());
}
@Override
public String getUserInfoUrl(AuthUserInfoEntity userInfoEntity) {
return MessageFormat.format(TENCENT_USER_INFO_PATTERN, AuthSource.TENCENT_CLOUD.userInfo(), userInfoEntity.getAccessToken());
}
@Override
public String getAuthorizeUrl(AuthAuthorizeEntity authorizeEntity) {
AuthConfig config = authorizeEntity.getConfig();
return MessageFormat.format(TENCENT_AUTHORIZE_PATTERN, AuthSource.TENCENT_CLOUD.authorize(), config.getClientId(),
config.getRedirectUri(), this.getRealState(config.getState()));
}
@Override
public String getRefreshUrl(AuthRefreshTokenEntity refreshTokenEntity) {
return null;
}
@Override
public String getRevokeUrl(AuthRevokeEntity revokeEntity) {
return null;
}
}
package me.zhyd.oauth.url;
import me.zhyd.oauth.config.AuthConfig;
import me.zhyd.oauth.config.AuthSource;
import me.zhyd.oauth.url.entity.*;
import java.text.MessageFormat;
/**
* 今日头条相关的URL构建类
*
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
* @version 1.0
* @since 1.8
*/
public class ToutiaoUrlBuilder extends AbstractUrlBuilder {
private static final String TOUTIAO_ACCESS_TOKEN_PATTERN = "{0}?client_key={1}&client_secret={2}&code={3}&grant_type=authorize_code";
private static final String TOUTIAO_USER_INFO_PATTERN = "{0}?client_key={1}&access_token={2}";
private static final String TOUTIAO_AUTHORIZE_PATTERN = "{0}?client_key={1}&redirect_uri={2}&state={3}&response_type=code&auth_only=1&display=0";
@Override
public String getAccessTokenUrl(AuthAccessTokenEntity accessTokenEntity) {
AuthConfig config = accessTokenEntity.getConfig();
return MessageFormat.format(TOUTIAO_ACCESS_TOKEN_PATTERN, AuthSource.TOUTIAO.accessToken(), config.getClientId(),
config.getClientSecret(), accessTokenEntity.getCode());
}
@Override
public String getUserInfoUrl(AuthUserInfoEntity userInfoEntity) {
return MessageFormat.format(TOUTIAO_USER_INFO_PATTERN, AuthSource.TOUTIAO.userInfo(), userInfoEntity.getClientId(), userInfoEntity.getAccessToken());
}
@Override
public String getAuthorizeUrl(AuthAuthorizeEntity authorizeEntity) {
AuthConfig config = authorizeEntity.getConfig();
return MessageFormat.format(TOUTIAO_AUTHORIZE_PATTERN, AuthSource.TOUTIAO.authorize(), config.getClientId(),
config.getRedirectUri(), this.getRealState(config.getState()));
}
@Override
public String getRefreshUrl(AuthRefreshTokenEntity refreshTokenEntity) {
return null;
}
@Override
public String getRevokeUrl(AuthRevokeEntity revokeEntity) {
return null;
}
}
......@@ -23,4 +23,8 @@ public class AuthUserInfoEntity {
* 额外的属性
*/
private String extra;
/**
* client key
*/
private String clientId;
}
......@@ -42,23 +42,12 @@ public class UrlBuilder {
private static final String CODING_USER_INFO_PATTERN = "{0}?access_token={1}";
private static final String CODING_AUTHORIZE_PATTERN = "{0}?client_id={1}&response_type=code&redirect_uri={2}&scope=user&state={3}";
private static final String TENCENT_ACCESS_TOKEN_PATTERN = "{0}?client_id={1}&client_secret={2}&grant_type=authorization_code&code={3}";
private static final String TENCENT_USER_INFO_PATTERN = "{0}?access_token={1}";
private static final String TENCENT_AUTHORIZE_PATTERN = "{0}?client_id={1}&response_type=code&redirect_uri={2}&scope=user&state={3}";
private static final String OSCHINA_ACCESS_TOKEN_PATTERN = "{0}?client_id={1}&client_secret={2}&grant_type=authorization_code&code={3}&redirect_uri={4}&dataType=json";
private static final String OSCHINA_USER_INFO_PATTERN = "{0}?access_token={1}&dataType=json";
private static final String OSCHINA_AUTHORIZE_PATTERN = "{0}?client_id={1}&response_type=code&redirect_uri={2}&state={3}";
private static final String ALIPAY_AUTHORIZE_PATTERN = "{0}?app_id={1}&scope=auth_user&redirect_uri={2}&state={3}";
private static final String QQ_ACCESS_TOKEN_PATTERN = "{0}?client_id={1}&client_secret={2}&grant_type=authorization_code&code={3}&redirect_uri={4}";
private static final String QQ_USER_INFO_PATTERN = "{0}?oauth_consumer_key={1}&access_token={2}&openid={3}";
private static final String QQ_AUTHORIZE_PATTERN = "{0}?client_id={1}&response_type=code&redirect_uri={2}&state={3}";
private static final String QQ_OPENID_PATTERN = "{0}?access_token={1}&unionid={2}";
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";
private static final String FACEBOOK_AUTHORIZE_PATTERN = "{0}?client_id={1}&redirect_uri={2}&state={3}&response_type=code&scope=";
private static final String FACEBOOK_ACCESS_TOKEN_PATTERN = "{0}?client_id={1}&client_secret={2}&code={3}&redirect_uri={4}&grant_type=authorization_code";
......@@ -84,9 +73,6 @@ public class UrlBuilder {
private static final String MI_USER_INFO_PATTERN = "{0}?clientId={1}&token={2}";
private static final String MI_REFRESH_TOKEN_PATTERN = "{0}?client_id={1}&client_secret={2}&redirect_uri={3}&refresh_token={4}&grant_type=refresh_token";
private static final String TOUTIAO_ACCESS_TOKEN_PATTERN = "{0}?client_key={1}&client_secret={2}&code={3}&grant_type=authorize_code";
private static final String TOUTIAO_USER_INFO_PATTERN = "{0}?client_key={1}&access_token={2}";
private static final String TOUTIAO_AUTHORIZE_PATTERN = "{0}?client_key={1}&redirect_uri={2}&state={3}&response_type=code&auth_only=1&display=0";
/**
* 获取state,如果为空, 则默认去当前日期的时间戳
......@@ -305,40 +291,6 @@ public class UrlBuilder {
return MessageFormat.format(CODING_AUTHORIZE_PATTERN, AuthSource.CODING.authorize(), clientId, redirectUrl, getState(state));
}
/**
* 获取腾讯云开发者平台 token的接口地址
*
* @param clientId coding 应用的App Key
* @param clientSecret coding 应用的App Secret
* @param code coding 授权前的code,用来换token
* @return full url
*/
public static String getTencentCloudAccessTokenUrl(String clientId, String clientSecret, String code) {
return MessageFormat.format(TENCENT_ACCESS_TOKEN_PATTERN, AuthSource.TENCENT_CLOUD.accessToken(), clientId, clientSecret, code);
}
/**
* 获取腾讯云开发者平台用户详情的接口地址
*
* @param token coding 应用的token
* @return full url
*/
public static String getTencentCloudUserInfoUrl(String token) {
return MessageFormat.format(TENCENT_USER_INFO_PATTERN, AuthSource.TENCENT_CLOUD.userInfo(), token);
}
/**
* 获取腾讯云开发者平台授权地址
*
* @param clientId coding 应用的Client ID
* @param redirectUrl coding 应用授权成功后的回调地址
* @param state 随机字符串,用于保持会话状态,防止CSRF攻击
* @return full url
*/
public static String getTencentCloudAuthorizeUrl(String clientId, String redirectUrl, String state) {
return MessageFormat.format(TENCENT_AUTHORIZE_PATTERN, AuthSource.TENCENT_CLOUD.authorize(), clientId, redirectUrl, getState(state));
}
/**
* 获取oschina token的接口地址
*
......@@ -374,55 +326,6 @@ public class UrlBuilder {
return MessageFormat.format(OSCHINA_AUTHORIZE_PATTERN, AuthSource.OSCHINA.authorize(), clientId, redirectUrl, getState(state));
}
/**
* 获取qq token的接口地址
*
* @param clientId qq 应用的App Key
* @param clientSecret qq 应用的App Secret
* @param code qq 授权前的code,用来换token
* @param redirectUri 待跳转的页面
* @return full url
*/
public static String getQqAccessTokenUrl(String clientId, String clientSecret, String code, String redirectUri) {
return MessageFormat.format(QQ_ACCESS_TOKEN_PATTERN, AuthSource.QQ.accessToken(), clientId, clientSecret, code, redirectUri);
}
/**
* 获取qq用户详情的接口地址
*
* @param clientId qq 应用的clientId
* @param token qq 应用的token
* @param openId qq 应用的openId
* @return full url
*/
public static String getQqUserInfoUrl(String clientId, String token, String openId) {
return MessageFormat.format(QQ_USER_INFO_PATTERN, AuthSource.QQ.userInfo(), clientId, token, openId);
}
/**
* 获取qq授权地址
*
* @param clientId qq 应用的Client ID
* @param redirectUrl qq 应用授权成功后的回调地址
* @param state 随机字符串,用于保持会话状态,防止CSRF攻击
* @return full url
*/
public static String getQqAuthorizeUrl(String clientId, String redirectUrl, String state) {
return MessageFormat.format(QQ_AUTHORIZE_PATTERN, AuthSource.QQ.authorize(), clientId, redirectUrl, getState(state));
}
/**
* 获取qq授权地址
*
* @param url 获取qqopenid的api接口地址
* @param token qq 应用授权的token
* @param unionid 是否需要获取unionid,默认为false。注:获取unionid需要单独发送邮件申请权限,请个人视情况而定。参考链接:http://wiki.connect.qq.com/unionid%E4%BB%8B%E7%BB%8D
* @return full url
*/
public static String getQqOpenidUrl(String url, String token, boolean unionid) {
return MessageFormat.format(QQ_OPENID_PATTERN, url, token, unionid ? 1 : 0);
}
/**
* 获取alipay授权地址
*
......@@ -435,31 +338,6 @@ public class UrlBuilder {
return MessageFormat.format(ALIPAY_AUTHORIZE_PATTERN, AuthSource.ALIPAY.authorize(), clientId, redirectUrl, getState(state));
}
/**
* 获取Taobao token的接口地址: 淘宝的授权登录,在这一步就会返回用户信息
*
* @param clientId taobao 应用的App Key
* @param clientSecret taobao 应用的App Secret
* @param code taobao 授权前的code,用来换token
* @param redirectUri 待跳转的页面
* @return full url
*/
public static String getTaobaoAccessTokenUrl(String clientId, String clientSecret, String code, String redirectUri) {
return MessageFormat.format(TAOBAO_ACCESS_TOKEN_PATTERN, AuthSource.TAOBAO.accessToken(), clientId, clientSecret, code, redirectUri);
}
/**
* 获取Taobao授权地址
*
* @param clientId Taobao 应用的Client ID
* @param redirectUrl Taobao 应用授权成功后的回调地址
* @param state 随机字符串,用于保持会话状态,防止CSRF攻击
* @return full url
*/
public static String getTaobaoAuthorizeUrl(String clientId, String redirectUrl, String state) {
return MessageFormat.format(TAOBAO_AUTHORIZE_PATTERN, AuthSource.TAOBAO.authorize(), clientId, redirectUrl, getState(state));
}
/**
* 获取Google授权地址
*
......@@ -717,39 +595,4 @@ public class UrlBuilder {
public static String getMiRefreshUrl(String clientId, String clientSecret, String redirectUrl, String refreshToken) {
return MessageFormat.format(MI_REFRESH_TOKEN_PATTERN, AuthSource.MI.refresh(), clientId, clientSecret, redirectUrl, refreshToken);
}
/**
* 获取今日头条授权地址
*
* @param clientId 今日头条 应用的Client ID
* @param redirectUrl 今日头条 应用授权成功后的回调地址
* @param state 随机字符串,用于保持会话状态,防止CSRF攻击
* @return full url
*/
public static String getToutiaoAuthorizeUrl(String clientId, String redirectUrl, String state) {
return MessageFormat.format(TOUTIAO_AUTHORIZE_PATTERN, AuthSource.TOUTIAO.authorize(), clientId, redirectUrl, getState(state));
}
/**
* 获取今日头条 token的接口地址
*
* @param clientId 今日头条 应用的Client ID
* @param clientSecret 今日头条 应用的Client Secret
* @param code 今日头条 授权前的code,用来换token
* @return full url
*/
public static String getToutiaoAccessTokenUrl(String clientId, String clientSecret, String code) {
return MessageFormat.format(TOUTIAO_ACCESS_TOKEN_PATTERN, AuthSource.TOUTIAO.accessToken(), clientId, clientSecret, code);
}
/**
* 获取今日头条用户详情的接口地址
*
* @param clientId 今日头条 应用的client_key
* @param token token
* @return full url
*/
public static String getToutiaoUserInfoUrl(String clientId, String token) {
return MessageFormat.format(TOUTIAO_USER_INFO_PATTERN, AuthSource.TOUTIAO.userInfo(), clientId, token);
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册