提交 7fe8a4d4 编写于 作者: 智布道's avatar 智布道 👁

从UrlBuilder中拆分alipay、baidu、coding、csdn、dingtalk、douyin、facebook和gitee相关的URL

上级 4f272348
......@@ -14,8 +14,9 @@ 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.AlipayUrlBuilder;
import me.zhyd.oauth.url.entity.AuthAuthorizeEntity;
import me.zhyd.oauth.utils.StringUtils;
import me.zhyd.oauth.utils.UrlBuilder;
/**
* 支付宝登录
......@@ -29,7 +30,7 @@ public class AuthAlipayRequest extends BaseAuthRequest {
private AlipayClient alipayClient;
public AuthAlipayRequest(AuthConfig config) {
super(config, AuthSource.ALIPAY);
super(config, AuthSource.ALIPAY, new AlipayUrlBuilder());
this.alipayClient = new DefaultAlipayClient(AuthSource.ALIPAY.accessToken(), config.getClientId(), config.getClientSecret(), "json", "UTF-8", config
.getAlipayPublicKey(), "RSA2");
}
......@@ -93,6 +94,8 @@ public class AuthAlipayRequest extends BaseAuthRequest {
*/
@Override
public String authorize() {
return UrlBuilder.getAlipayAuthorizeUrl(config.getClientId(), config.getRedirectUri(), config.getState());
return this.urlBuilder.getAuthorizeUrl(AuthAuthorizeEntity.builder()
.config(config)
.build());
}
}
......@@ -8,7 +8,11 @@ import me.zhyd.oauth.config.AuthSource;
import me.zhyd.oauth.enums.AuthBaiduErrorCode;
import me.zhyd.oauth.exception.AuthException;
import me.zhyd.oauth.model.*;
import me.zhyd.oauth.utils.UrlBuilder;
import me.zhyd.oauth.url.BaiduUrlBuilder;
import me.zhyd.oauth.url.entity.AuthAccessTokenEntity;
import me.zhyd.oauth.url.entity.AuthAuthorizeEntity;
import me.zhyd.oauth.url.entity.AuthRevokeEntity;
import me.zhyd.oauth.url.entity.AuthUserInfoEntity;
/**
* 百度账号登录
......@@ -20,13 +24,15 @@ import me.zhyd.oauth.utils.UrlBuilder;
public class AuthBaiduRequest extends BaseAuthRequest {
public AuthBaiduRequest(AuthConfig config) {
super(config, AuthSource.BAIDU);
super(config, AuthSource.BAIDU, new BaiduUrlBuilder());
}
@Override
protected AuthToken getAccessToken(AuthCallback authCallback) {
String accessTokenUrl = UrlBuilder.getBaiduAccessTokenUrl(config.getClientId(), config.getClientSecret(), authCallback.getCode(), config
.getRedirectUri());
String accessTokenUrl = this.urlBuilder.getAccessTokenUrl(AuthAccessTokenEntity.builder()
.config(config)
.code(authCallback.getCode())
.build());
HttpResponse response = HttpRequest.post(accessTokenUrl).execute();
JSONObject accessTokenObject = JSONObject.parseObject(response.body());
AuthBaiduErrorCode errorCode = AuthBaiduErrorCode.getErrorCode(accessTokenObject.getString("error"));
......@@ -44,7 +50,9 @@ public class AuthBaiduRequest extends BaseAuthRequest {
@Override
protected AuthUser getUserInfo(AuthToken authToken) {
String accessToken = authToken.getAccessToken();
HttpResponse response = HttpRequest.get(UrlBuilder.getBaiduUserInfoUrl(accessToken)).execute();
HttpResponse response = HttpRequest.get(this.urlBuilder.getUserInfoUrl(AuthUserInfoEntity.builder()
.accessToken(accessToken)
.build())).execute();
String userInfo = response.body();
JSONObject object = JSONObject.parseObject(userInfo);
AuthBaiduErrorCode errorCode = AuthBaiduErrorCode.getErrorCode(object.getString("error"));
......@@ -68,13 +76,17 @@ public class AuthBaiduRequest extends BaseAuthRequest {
*/
@Override
public String authorize() {
return UrlBuilder.getBaiduAuthorizeUrl(config.getClientId(), config.getRedirectUri(), config.getState());
return this.urlBuilder.getAuthorizeUrl(AuthAuthorizeEntity.builder()
.config(config)
.build());
}
@Override
public AuthResponse revoke(AuthToken authToken) {
String accessToken = authToken.getAccessToken();
HttpResponse response = HttpRequest.get(UrlBuilder.getBaiduRevokeUrl(accessToken)).execute();
HttpResponse response = HttpRequest.get(this.urlBuilder.getRevokeUrl(AuthRevokeEntity.builder()
.accessToken(accessToken)
.build())).execute();
String userInfo = response.body();
JSONObject object = JSONObject.parseObject(userInfo);
if (object.containsKey("error_code")) {
......
......@@ -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.CodingUrlBuilder;
import me.zhyd.oauth.url.entity.AuthAccessTokenEntity;
import me.zhyd.oauth.url.entity.AuthAuthorizeEntity;
import me.zhyd.oauth.url.entity.AuthUserInfoEntity;
/**
* Cooding登录
......@@ -22,12 +25,15 @@ import me.zhyd.oauth.utils.UrlBuilder;
public class AuthCodingRequest extends BaseAuthRequest {
public AuthCodingRequest(AuthConfig config) {
super(config, AuthSource.CODING);
super(config, AuthSource.CODING, new CodingUrlBuilder());
}
@Override
protected AuthToken getAccessToken(AuthCallback authCallback) {
String accessTokenUrl = UrlBuilder.getCodingAccessTokenUrl(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 AuthCodingRequest extends BaseAuthRequest {
@Override
protected AuthUser getUserInfo(AuthToken authToken) {
String accessToken = authToken.getAccessToken();
HttpResponse response = HttpRequest.get(UrlBuilder.getCodingUserInfoUrl(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"));
......@@ -73,6 +81,8 @@ public class AuthCodingRequest extends BaseAuthRequest {
*/
@Override
public String authorize() {
return UrlBuilder.getCodingAuthorizeUrl(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.CsdnUrlBuilder;
import me.zhyd.oauth.url.entity.AuthAccessTokenEntity;
import me.zhyd.oauth.url.entity.AuthAuthorizeEntity;
import me.zhyd.oauth.url.entity.AuthUserInfoEntity;
/**
* CSDN登录
......@@ -19,16 +22,19 @@ import me.zhyd.oauth.utils.UrlBuilder;
* @version 1.0
* @since 1.8
*/
@Deprecated
public class AuthCsdnRequest extends BaseAuthRequest {
public AuthCsdnRequest(AuthConfig config) {
super(config, AuthSource.CSDN);
super(config, AuthSource.CSDN, new CsdnUrlBuilder());
}
@Override
protected AuthToken getAccessToken(AuthCallback authCallback) {
String accessTokenUrl = UrlBuilder.getCsdnAccessTokenUrl(config.getClientId(), config.getClientSecret(), authCallback.getCode(), config
.getRedirectUri());
String accessTokenUrl = this.urlBuilder.getAccessTokenUrl(AuthAccessTokenEntity.builder()
.config(config)
.code(authCallback.getCode())
.build());
HttpResponse response = HttpRequest.post(accessTokenUrl).execute();
JSONObject accessTokenObject = JSONObject.parseObject(response.body());
if (accessTokenObject.containsKey("error_code")) {
......@@ -40,7 +46,9 @@ public class AuthCsdnRequest extends BaseAuthRequest {
@Override
protected AuthUser getUserInfo(AuthToken authToken) {
String accessToken = authToken.getAccessToken();
HttpResponse response = HttpRequest.get(UrlBuilder.getCsdnUserInfoUrl(accessToken)).execute();
HttpResponse response = HttpRequest.get(this.urlBuilder.getUserInfoUrl(AuthUserInfoEntity.builder()
.accessToken(accessToken)
.build())).execute();
JSONObject object = JSONObject.parseObject(response.body());
if (object.containsKey("error_code")) {
throw new AuthException(object.getString("error"));
......@@ -63,6 +71,8 @@ public class AuthCsdnRequest extends BaseAuthRequest {
*/
@Override
public String authorize() {
return UrlBuilder.getCsdnAuthorizeUrl(config.getClientId(), config.getRedirectUri(), config.getState());
return this.urlBuilder.getAuthorizeUrl(AuthAuthorizeEntity.builder()
.config(config)
.build());
}
}
......@@ -8,9 +8,14 @@ import me.zhyd.oauth.config.AuthConfig;
import me.zhyd.oauth.config.AuthSource;
import me.zhyd.oauth.enums.AuthDingTalkErrorCode;
import me.zhyd.oauth.exception.AuthException;
import me.zhyd.oauth.model.*;
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.DingtalkUrlBuilder;
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.UrlBuilder;
/**
* 钉钉登录
......@@ -22,7 +27,7 @@ import me.zhyd.oauth.utils.UrlBuilder;
public class AuthDingTalkRequest extends BaseAuthRequest {
public AuthDingTalkRequest(AuthConfig config) {
super(config, AuthSource.DINGTALK);
super(config, AuthSource.DINGTALK, new DingtalkUrlBuilder());
}
@Override
......@@ -38,8 +43,12 @@ public class AuthDingTalkRequest extends BaseAuthRequest {
String urlEncodeSignature = GlobalAuthUtil.generateDingTalkSignature(config.getClientSecret(), timestamp);
JSONObject param = new JSONObject();
param.put("tmp_auth_code", code);
HttpResponse response = HttpRequest.post(UrlBuilder.getDingTalkUserInfoUrl(urlEncodeSignature, timestamp, config
.getClientId())).body(param.toJSONString()).execute();
HttpResponse response = HttpRequest.post(this.urlBuilder.getUserInfoUrl(AuthUserInfoEntity.builder()
.signature(urlEncodeSignature)
.timestamp(timestamp)
.clientId(config.getClientId())
.build()
)).body(param.toJSONString()).execute();
String userInfo = response.body();
JSONObject object = JSON.parseObject(userInfo);
AuthDingTalkErrorCode errorCode = AuthDingTalkErrorCode.getErrorCode(object.getIntValue("errcode"));
......@@ -68,6 +77,8 @@ public class AuthDingTalkRequest extends BaseAuthRequest {
*/
@Override
public String authorize() {
return UrlBuilder.getDingTalkQrConnectUrl(config.getClientId(), config.getRedirectUri(), config.getState());
return this.urlBuilder.getAuthorizeUrl(AuthAuthorizeEntity.builder()
.config(config)
.build());
}
}
......@@ -7,7 +7,11 @@ import me.zhyd.oauth.config.AuthConfig;
import me.zhyd.oauth.config.AuthSource;
import me.zhyd.oauth.exception.AuthException;
import me.zhyd.oauth.model.*;
import me.zhyd.oauth.utils.UrlBuilder;
import me.zhyd.oauth.url.DouyinUrlBuilder;
import me.zhyd.oauth.url.entity.AuthAccessTokenEntity;
import me.zhyd.oauth.url.entity.AuthAuthorizeEntity;
import me.zhyd.oauth.url.entity.AuthRefreshTokenEntity;
import me.zhyd.oauth.url.entity.AuthUserInfoEntity;
/**
......@@ -20,12 +24,15 @@ import me.zhyd.oauth.utils.UrlBuilder;
public class AuthDouyinRequest extends BaseAuthRequest {
public AuthDouyinRequest(AuthConfig config) {
super(config, AuthSource.DOUYIN);
super(config, AuthSource.DOUYIN, new DouyinUrlBuilder());
}
@Override
protected AuthToken getAccessToken(AuthCallback authCallback) {
String accessTokenUrl = UrlBuilder.getDouyinAccessTokenUrl(config.getClientId(), config.getClientSecret(), authCallback.getCode());
String accessTokenUrl = this.urlBuilder.getAccessTokenUrl(AuthAccessTokenEntity.builder()
.config(config)
.code(authCallback.getCode())
.build());
return this.getToken(accessTokenUrl);
}
......@@ -33,7 +40,10 @@ public class AuthDouyinRequest extends BaseAuthRequest {
protected AuthUser getUserInfo(AuthToken authToken) {
String accessToken = authToken.getAccessToken();
String openId = authToken.getOpenId();
String url = UrlBuilder.getDouyinUserInfoUrl(accessToken, openId);
String url = this.urlBuilder.getUserInfoUrl(AuthUserInfoEntity.builder()
.accessToken(accessToken)
.openId(openId)
.build());
HttpResponse response = HttpRequest.get(url).execute();
JSONObject object = JSONObject.parseObject(response.body());
......@@ -58,12 +68,17 @@ public class AuthDouyinRequest extends BaseAuthRequest {
*/
@Override
public String authorize() {
return UrlBuilder.getDouyinAuthorizeUrl(config.getClientId(), config.getRedirectUri(), config.getState());
return this.urlBuilder.getAuthorizeUrl(AuthAuthorizeEntity.builder()
.config(config)
.build());
}
@Override
public AuthResponse refresh(AuthToken oldToken) {
String refreshTokenUrl = UrlBuilder.getDouyinRefreshUrl(config.getClientId(), oldToken.getRefreshToken());
String refreshTokenUrl = this.urlBuilder.getRefreshUrl(AuthRefreshTokenEntity.builder()
.config(config)
.refreshToken(oldToken.getRefreshToken())
.build());
return AuthResponse.builder()
.code(ResponseStatus.SUCCESS.getCode())
.data(this.getToken(refreshTokenUrl))
......
......@@ -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.FacebookUrlBuilder;
import me.zhyd.oauth.url.entity.AuthAccessTokenEntity;
import me.zhyd.oauth.url.entity.AuthAuthorizeEntity;
import me.zhyd.oauth.url.entity.AuthUserInfoEntity;
/**
* Facebook登录
......@@ -22,13 +25,15 @@ import me.zhyd.oauth.utils.UrlBuilder;
public class AuthFacebookRequest extends BaseAuthRequest {
public AuthFacebookRequest(AuthConfig config) {
super(config, AuthSource.FACEBOOK);
super(config, AuthSource.FACEBOOK, new FacebookUrlBuilder());
}
@Override
protected AuthToken getAccessToken(AuthCallback authCallback) {
String accessTokenUrl = UrlBuilder.getFacebookAccessTokenUrl(config.getClientId(), config.getClientSecret(),
authCallback.getCode(), config.getRedirectUri());
String accessTokenUrl = this.urlBuilder.getAccessTokenUrl(AuthAccessTokenEntity.builder()
.config(config)
.code(authCallback.getCode())
.build());
HttpResponse response = HttpRequest.post(accessTokenUrl).execute();
JSONObject accessTokenObject = JSONObject.parseObject(response.body());
......@@ -46,7 +51,9 @@ public class AuthFacebookRequest extends BaseAuthRequest {
@Override
protected AuthUser getUserInfo(AuthToken authToken) {
String accessToken = authToken.getAccessToken();
HttpResponse response = HttpRequest.get(UrlBuilder.getFacebookUserInfoUrl(accessToken)).execute();
HttpResponse response = HttpRequest.get(this.urlBuilder.getUserInfoUrl(AuthUserInfoEntity.builder()
.accessToken(accessToken)
.build())).execute();
String userInfo = response.body();
JSONObject object = JSONObject.parseObject(userInfo);
if (object.containsKey("error")) {
......@@ -80,6 +87,8 @@ public class AuthFacebookRequest extends BaseAuthRequest {
*/
@Override
public String authorize() {
return UrlBuilder.getFacebookAuthorizeUrl(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.GiteeUrlBuilder;
import me.zhyd.oauth.url.entity.AuthAccessTokenEntity;
import me.zhyd.oauth.url.entity.AuthAuthorizeEntity;
import me.zhyd.oauth.url.entity.AuthUserInfoEntity;
/**
* Gitee登录
......@@ -22,13 +25,15 @@ import me.zhyd.oauth.utils.UrlBuilder;
public class AuthGiteeRequest extends BaseAuthRequest {
public AuthGiteeRequest(AuthConfig config) {
super(config, AuthSource.GITEE);
super(config, AuthSource.GITEE, new GiteeUrlBuilder());
}
@Override
protected AuthToken getAccessToken(AuthCallback authCallback) {
String accessTokenUrl = UrlBuilder.getGiteeAccessTokenUrl(config.getClientId(), config.getClientSecret(),
authCallback.getCode(), config.getRedirectUri());
String accessTokenUrl = this.urlBuilder.getAccessTokenUrl(AuthAccessTokenEntity.builder()
.config(config)
.code(authCallback.getCode())
.build());
HttpResponse response = HttpRequest.post(accessTokenUrl).execute();
JSONObject accessTokenObject = JSONObject.parseObject(response.body());
if (accessTokenObject.containsKey("error")) {
......@@ -40,7 +45,9 @@ public class AuthGiteeRequest extends BaseAuthRequest {
@Override
protected AuthUser getUserInfo(AuthToken authToken) {
String accessToken = authToken.getAccessToken();
HttpResponse response = HttpRequest.get(UrlBuilder.getGiteeUserInfoUrl(accessToken)).execute();
HttpResponse response = HttpRequest.get(this.urlBuilder.getUserInfoUrl(AuthUserInfoEntity.builder()
.accessToken(accessToken)
.build())).execute();
String userInfo = response.body();
JSONObject object = JSONObject.parseObject(userInfo);
return AuthUser.builder()
......@@ -66,6 +73,8 @@ public class AuthGiteeRequest extends BaseAuthRequest {
*/
@Override
public String authorize() {
return UrlBuilder.getGiteeAuthorizeUrl(config.getClientId(), config.getRedirectUri(), config.getState());
return this.urlBuilder.getAuthorizeUrl(AuthAuthorizeEntity.builder()
.config(config)
.build());
}
}
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;
/**
* Baidu相关的URL构建类
*
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
* @version 1.0
* @since 1.8
*/
public class AlipayUrlBuilder extends AbstractUrlBuilder {
private static final String ALIPAY_AUTHORIZE_PATTERN = "{0}?app_id={1}&scope=auth_user&redirect_uri={2}&state={3}";
@Override
public String getAccessTokenUrl(AuthAccessTokenEntity accessTokenEntity) {
return null;
}
@Override
public String getUserInfoUrl(AuthUserInfoEntity userInfoEntity) {
return null;
}
@Override
public String getAuthorizeUrl(AuthAuthorizeEntity authorizeEntity) {
AuthConfig config = authorizeEntity.getConfig();
return MessageFormat.format(ALIPAY_AUTHORIZE_PATTERN, AuthSource.ALIPAY.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;
/**
* Baidu相关的URL构建类
*
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
* @version 1.0
* @since 1.8
*/
public class BaiduUrlBuilder extends AbstractUrlBuilder {
private static final String BAIDU_ACCESS_TOKEN_PATTERN = "{0}?client_id={1}&client_secret={2}&grant_type=authorization_code&code={3}&redirect_uri={4}";
private static final String BAIDU_USER_INFO_PATTERN = "{0}?access_token={1}";
private static final String BAIDU_AUTHORIZE_PATTERN = "{0}?client_id={1}&response_type=code&redirect_uri={2}&display=popup&state={3}";
private static final String BAIDU_REVOKE_PATTERN = "{0}?access_token={1}";
@Override
public String getAccessTokenUrl(AuthAccessTokenEntity accessTokenEntity) {
AuthConfig config = accessTokenEntity.getConfig();
return MessageFormat.format(BAIDU_ACCESS_TOKEN_PATTERN, AuthSource.BAIDU.accessToken(), config.getClientId(), config.getClientSecret(), accessTokenEntity.getCode(), config.getRedirectUri());
}
@Override
public String getUserInfoUrl(AuthUserInfoEntity userInfoEntity) {
return MessageFormat.format(BAIDU_USER_INFO_PATTERN, AuthSource.BAIDU.userInfo(), userInfoEntity.getAccessToken());
}
@Override
public String getAuthorizeUrl(AuthAuthorizeEntity authorizeEntity) {
AuthConfig config = authorizeEntity.getConfig();
return MessageFormat.format(BAIDU_AUTHORIZE_PATTERN, AuthSource.BAIDU.authorize(), config.getClientId(), config.getRedirectUri(), this.getRealState(config.getState()));
}
@Override
public String getRefreshUrl(AuthRefreshTokenEntity refreshTokenEntity) {
return null;
}
@Override
public String getRevokeUrl(AuthRevokeEntity revokeEntity) {
return MessageFormat.format(BAIDU_REVOKE_PATTERN, AuthSource.BAIDU.revoke(), revokeEntity.getAccessToken());
}
}
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;
/**
* Coding相关的URL构建类
*
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
* @version 1.0
* @since 1.8
*/
public class CodingUrlBuilder extends AbstractUrlBuilder {
private static final String CODING_ACCESS_TOKEN_PATTERN = "{0}?client_id={1}&client_secret={2}&grant_type=authorization_code&code={3}";
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}";
@Override
public String getAccessTokenUrl(AuthAccessTokenEntity accessTokenEntity) {
AuthConfig config = accessTokenEntity.getConfig();
return MessageFormat.format(CODING_ACCESS_TOKEN_PATTERN, AuthSource.CODING.accessToken(), config.getClientId(),
config.getClientSecret(), accessTokenEntity.getCode());
}
@Override
public String getUserInfoUrl(AuthUserInfoEntity userInfoEntity) {
return MessageFormat.format(CODING_USER_INFO_PATTERN, AuthSource.CODING.userInfo(), userInfoEntity.getAccessToken());
}
@Override
public String getAuthorizeUrl(AuthAuthorizeEntity authorizeEntity) {
AuthConfig config = authorizeEntity.getConfig();
return MessageFormat.format(CODING_AUTHORIZE_PATTERN, AuthSource.CODING.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;
/**
* csdn相关的URL构建类
*
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
* @version 1.0
* @since 1.8
*/
@Deprecated
public class CsdnUrlBuilder extends AbstractUrlBuilder {
private static final String CSDN_ACCESS_TOKEN_PATTERN = "{0}?client_id={1}&client_secret={2}&grant_type=authorization_code&code={3}&redirect_uri={4}";
private static final String CSDN_USER_INFO_PATTERN = "{0}?access_token={1}";
private static final String CSDN_AUTHORIZE_PATTERN = "{0}?client_id={1}&response_type=code&redirect_uri={2}&state={3}";
@Override
public String getAccessTokenUrl(AuthAccessTokenEntity accessTokenEntity) {
AuthConfig config = accessTokenEntity.getConfig();
return MessageFormat.format(CSDN_ACCESS_TOKEN_PATTERN, AuthSource.CSDN.accessToken(), config.getClientId(), config.getClientSecret(), accessTokenEntity.getCode(), config.getRedirectUri());
}
@Override
public String getUserInfoUrl(AuthUserInfoEntity userInfoEntity) {
return MessageFormat.format(CSDN_USER_INFO_PATTERN, AuthSource.CSDN.userInfo(), userInfoEntity.getAccessToken());
}
@Override
public String getAuthorizeUrl(AuthAuthorizeEntity authorizeEntity) {
AuthConfig config = authorizeEntity.getConfig();
return MessageFormat.format(CSDN_AUTHORIZE_PATTERN, AuthSource.CSDN.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 DingtalkUrlBuilder extends AbstractUrlBuilder {
private static final String DING_TALK_QRCONNECT_PATTERN = "{0}?appid={1}&response_type=code&scope=snsapi_login&redirect_uri={2}&state={3}";
private static final String DING_TALK_USER_INFO_PATTERN = "{0}?signature={1}&timestamp={2}&accessKey={3}";
@Override
public String getAccessTokenUrl(AuthAccessTokenEntity accessTokenEntity) {
return null;
}
@Override
public String getUserInfoUrl(AuthUserInfoEntity userInfoEntity) {
return MessageFormat.format(DING_TALK_USER_INFO_PATTERN, AuthSource.DINGTALK.userInfo(), userInfoEntity.getSignature(), userInfoEntity.getTimestamp(), userInfoEntity.getClientId());
}
@Override
public String getAuthorizeUrl(AuthAuthorizeEntity authorizeEntity) {
AuthConfig config = authorizeEntity.getConfig();
return MessageFormat.format(DING_TALK_QRCONNECT_PATTERN, AuthSource.DINGTALK.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 DouyinUrlBuilder extends AbstractUrlBuilder {
private static final String DOUYIN_AUTHORIZE_PATTERN = "{0}?client_key={1}&redirect_uri={2}&state={3}&response_type=code&scope=user_info";
private static final String DOUYIN_ACCESS_TOKEN_PATTERN = "{0}?client_key={1}&client_secret={2}&code={3}&grant_type=authorization_code";
private static final String DOUYIN_USER_INFO_PATTERN = "{0}?access_token={1}&open_id={2}";
private static final String DOUYIN_REFRESH_TOKEN_PATTERN = "{0}?client_key={1}&refresh_token={2}&grant_type=refresh_token";
@Override
public String getAccessTokenUrl(AuthAccessTokenEntity accessTokenEntity) {
AuthConfig config = accessTokenEntity.getConfig();
return MessageFormat.format(DOUYIN_ACCESS_TOKEN_PATTERN, AuthSource.DOUYIN.accessToken(), config.getClientId(), config.getClientSecret(), accessTokenEntity.getCode());
}
@Override
public String getUserInfoUrl(AuthUserInfoEntity userInfoEntity) {
return MessageFormat.format(DOUYIN_USER_INFO_PATTERN, AuthSource.DOUYIN.userInfo(), userInfoEntity.getAccessToken(), userInfoEntity.getOpenId());
}
@Override
public String getAuthorizeUrl(AuthAuthorizeEntity authorizeEntity) {
AuthConfig config = authorizeEntity.getConfig();
return MessageFormat.format(DOUYIN_AUTHORIZE_PATTERN, AuthSource.DOUYIN.authorize(), config.getClientId(), config.getRedirectUri(), this.getRealState(config.getState()));
}
@Override
public String getRefreshUrl(AuthRefreshTokenEntity refreshTokenEntity) {
AuthConfig config = refreshTokenEntity.getConfig();
return MessageFormat.format(DOUYIN_REFRESH_TOKEN_PATTERN, AuthSource.DOUYIN.refresh(), config.getClientId(), refreshTokenEntity.getRefreshToken());
}
@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;
/**
* Facebook相关的URL构建类
*
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
* @version 1.0
* @since 1.8
*/
public class FacebookUrlBuilder extends AbstractUrlBuilder {
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";
private static final String FACEBOOK_USER_INFO_PATTERN = "{0}?access_token={1}&fields=id,name,birthday,gender,hometown,email,devices,picture.width(400)";
@Override
public String getAccessTokenUrl(AuthAccessTokenEntity accessTokenEntity) {
AuthConfig config = accessTokenEntity.getConfig();
return MessageFormat.format(FACEBOOK_ACCESS_TOKEN_PATTERN, AuthSource.FACEBOOK.accessToken(), config.getClientId(), config.getClientSecret(), accessTokenEntity.getCode(), config.getRedirectUri());
}
@Override
public String getUserInfoUrl(AuthUserInfoEntity userInfoEntity) {
return MessageFormat.format(FACEBOOK_USER_INFO_PATTERN, AuthSource.FACEBOOK.userInfo(), userInfoEntity.getAccessToken());
}
@Override
public String getAuthorizeUrl(AuthAuthorizeEntity authorizeEntity) {
AuthConfig config = authorizeEntity.getConfig();
return MessageFormat.format(FACEBOOK_AUTHORIZE_PATTERN, AuthSource.FACEBOOK.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;
/**
* Gitee相关的URL构建类
*
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
* @version 1.0
* @since 1.8
*/
public class GiteeUrlBuilder extends AbstractUrlBuilder {
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
public String getAccessTokenUrl(AuthAccessTokenEntity accessTokenEntity) {
AuthConfig config = accessTokenEntity.getConfig();
return MessageFormat.format(GITEE_ACCESS_TOKEN_PATTERN, AuthSource.GITEE.accessToken(), config.getClientId(), config.getClientSecret(), accessTokenEntity.getCode(), config.getRedirectUri());
}
@Override
public String getUserInfoUrl(AuthUserInfoEntity userInfoEntity) {
return MessageFormat.format(GITEE_USER_INFO_PATTERN, AuthSource.GITEE.userInfo(), userInfoEntity.getAccessToken());
}
@Override
public String getAuthorizeUrl(AuthAuthorizeEntity authorizeEntity) {
AuthConfig config = authorizeEntity.getConfig();
return MessageFormat.format(GITEE_AUTHORIZE_PATTERN, AuthSource.GITEE.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;
}
}
......@@ -10,4 +10,6 @@ import lombok.*;
@Getter
@Builder
public class AuthRevokeEntity {
private String accessToken;
}
......@@ -19,12 +19,20 @@ public class AuthUserInfoEntity {
* 用户openId
*/
private String openId;
/**
* client key
*/
private String clientId;
/**
* 额外的属性
*/
private String extra;
/**
* client key
* 额外的属性
*/
private String clientId;
private String signature;
/**
* 额外的属性
*/
private String timestamp;
}
package me.zhyd.oauth.utils;
import me.zhyd.oauth.config.AuthSource;
import java.text.MessageFormat;
/**
* Url构建工具类
*
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
* @version 1.0
* @since 1.0
*/
public class UrlBuilder {
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}";
private static final String DING_TALK_QRCONNECT_PATTERN = "{0}?appid={1}&response_type=code&scope=snsapi_login&redirect_uri={2}&state={3}";
private static final String DING_TALK_USER_INFO_PATTERN = "{0}?signature={1}&timestamp={2}&accessKey={3}";
private static final String BAIDU_ACCESS_TOKEN_PATTERN = "{0}?client_id={1}&client_secret={2}&grant_type=authorization_code&code={3}&redirect_uri={4}";
private static final String BAIDU_USER_INFO_PATTERN = "{0}?access_token={1}";
private static final String BAIDU_AUTHORIZE_PATTERN = "{0}?client_id={1}&response_type=code&redirect_uri={2}&display=popup&state={3}";
private static final String BAIDU_REVOKE_PATTERN = "{0}?access_token={1}";
private static final String CSDN_ACCESS_TOKEN_PATTERN = "{0}?client_id={1}&client_secret={2}&grant_type=authorization_code&code={3}&redirect_uri={4}";
private static final String CSDN_USER_INFO_PATTERN = "{0}?access_token={1}";
private static final String CSDN_AUTHORIZE_PATTERN = "{0}?client_id={1}&response_type=code&redirect_uri={2}&state={3}";
private static final String CODING_ACCESS_TOKEN_PATTERN = "{0}?client_id={1}&client_secret={2}&grant_type=authorization_code&code={3}";
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 ALIPAY_AUTHORIZE_PATTERN = "{0}?app_id={1}&scope=auth_user&redirect_uri={2}&state={3}";
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";
private static final String FACEBOOK_USER_INFO_PATTERN = "{0}?access_token={1}&fields=id,name,birthday,gender,hometown,email,devices,picture.width(400)";
private static final String DOUYIN_AUTHORIZE_PATTERN = "{0}?client_key={1}&redirect_uri={2}&state={3}&response_type=code&scope=user_info";
private static final String DOUYIN_ACCESS_TOKEN_PATTERN = "{0}?client_key={1}&client_secret={2}&code={3}&grant_type=authorization_code";
private static final String DOUYIN_USER_INFO_PATTERN = "{0}?access_token={1}&open_id={2}";
private static final String DOUYIN_REFRESH_TOKEN_PATTERN = "{0}?client_key={1}&refresh_token={2}&grant_type=refresh_token";
/**
* 获取state,如果为空, 则默认去当前日期的时间戳
*
* @param state state
*/
private static Object getState(String state) {
return StringUtils.isEmpty(state) ? String.valueOf(System.currentTimeMillis()) : state;
}
/**
* 获取gitee token的接口地址
*
* @param clientId gitee 应用的Client ID
* @param clientSecret gitee 应用的Client Secret
* @param code gitee 授权前的code,用来换token
* @param redirectUri 待跳转的页面
* @return full url
*/
public static String getGiteeAccessTokenUrl(String clientId, String clientSecret, String code, String redirectUri) {
return MessageFormat.format(GITEE_ACCESS_TOKEN_PATTERN, AuthSource.GITEE.accessToken(), clientId, clientSecret, code, redirectUri);
}
/**
* 获取gitee用户详情的接口地址
*
* @param token gitee 应用的token
* @return full url
*/
public static String getGiteeUserInfoUrl(String token) {
return MessageFormat.format(GITEE_USER_INFO_PATTERN, AuthSource.GITEE.userInfo(), token);
}
/**
* 获取gitee授权地址
*
* @param clientId gitee 应用的Client ID
* @param redirectUrl gitee 应用授权成功后的回调地址
* @param state 随机字符串,用于保持会话状态,防止CSRF攻击
* @return json
*/
public static String getGiteeAuthorizeUrl(String clientId, String redirectUrl, String state) {
return MessageFormat.format(GITEE_AUTHORIZE_PATTERN, AuthSource.GITEE.authorize(), clientId, redirectUrl, getState(state));
}
/**
* 获取钉钉登录二维码的地址
*
* @param clientId 钉钉 应用的App Id
* @param redirectUrl 钉钉 应用授权成功后的回调地址
* @param state 随机字符串,用于保持会话状态,防止CSRF攻击
* @return full url
*/
public static String getDingTalkQrConnectUrl(String clientId, String redirectUrl, String state) {
return MessageFormat.format(DING_TALK_QRCONNECT_PATTERN, AuthSource.DINGTALK.authorize(), clientId, redirectUrl, getState(state));
}
/**
* 获取钉钉用户信息的地址
*
* @param signature 通过appSecret计算出来的签名值,签名计算方法:https://open-doc.dingtalk.com/microapp/faquestions/hxs5v9
* @param timestamp 当前时间戳,单位是毫秒
* @param accessKey 钉钉 应用的App Id
* @return full url
*/
public static String getDingTalkUserInfoUrl(String signature, String timestamp, String accessKey) {
return MessageFormat.format(DING_TALK_USER_INFO_PATTERN, AuthSource.DINGTALK.userInfo(), signature, timestamp, accessKey);
}
/**
* 获取baidu token的接口地址
*
* @param clientId baidu 应用的API Key
* @param clientSecret baidu 应用的Secret Key
* @param code baidu 授权前的code,用来换token
* @param redirectUri 待跳转的页面
* @return full url
*/
public static String getBaiduAccessTokenUrl(String clientId, String clientSecret, String code, String redirectUri) {
return MessageFormat.format(BAIDU_ACCESS_TOKEN_PATTERN, AuthSource.BAIDU.accessToken(), clientId, clientSecret, code, redirectUri);
}
/**
* 获取baidu用户详情的接口地址
*
* @param token baidu 应用的token
* @return full url
*/
public static String getBaiduUserInfoUrl(String token) {
return MessageFormat.format(BAIDU_USER_INFO_PATTERN, AuthSource.BAIDU.userInfo(), token);
}
/**
* 获取baidu授权地址
*
* @param clientId baidu 应用的API Key
* @param redirectUrl baidu 应用授权成功后的回调地址
* @param state 随机字符串,用于保持会话状态,防止CSRF攻击
* @return json
*/
public static String getBaiduAuthorizeUrl(String clientId, String redirectUrl, String state) {
return MessageFormat.format(BAIDU_AUTHORIZE_PATTERN, AuthSource.BAIDU.authorize(), clientId, redirectUrl, getState(state));
}
/**
* 获取收回baidu授权的地址
*
* @param accessToken baidu 授权登录后的token
* @return json
*/
public static String getBaiduRevokeUrl(String accessToken) {
return MessageFormat.format(BAIDU_REVOKE_PATTERN, AuthSource.BAIDU.revoke(), accessToken);
}
/**
* 获取csdn token的接口地址
*
* @param clientId csdn 应用的App Key
* @param clientSecret csdn 应用的App Secret
* @param code csdn 授权前的code,用来换token
* @param redirectUri 待跳转的页面
* @return full url
*/
public static String getCsdnAccessTokenUrl(String clientId, String clientSecret, String code, String redirectUri) {
return MessageFormat.format(CSDN_ACCESS_TOKEN_PATTERN, AuthSource.CSDN.accessToken(), clientId, clientSecret, code, redirectUri);
}
/**
* 获取csdn用户详情的接口地址
*
* @param token csdn 应用的token
* @return full url
*/
public static String getCsdnUserInfoUrl(String token) {
return MessageFormat.format(CSDN_USER_INFO_PATTERN, AuthSource.CSDN.userInfo(), token);
}
/**
* 获取csdn授权地址
*
* @param clientId csdn 应用的Client ID
* @param redirectUrl csdn 应用授权成功后的回调地址
* @param state 随机字符串,用于保持会话状态,防止CSRF攻击
* @return full url
*/
public static String getCsdnAuthorizeUrl(String clientId, String redirectUrl, String state) {
return MessageFormat.format(CSDN_AUTHORIZE_PATTERN, AuthSource.CSDN.authorize(), clientId, redirectUrl, getState(state));
}
/**
* 获取coding token的接口地址
*
* @param clientId coding 应用的App Key
* @param clientSecret coding 应用的App Secret
* @param code coding 授权前的code,用来换token
* @return full url
*/
public static String getCodingAccessTokenUrl(String clientId, String clientSecret, String code) {
return MessageFormat.format(CODING_ACCESS_TOKEN_PATTERN, AuthSource.CODING.accessToken(), clientId, clientSecret, code);
}
/**
* 获取coding用户详情的接口地址
*
* @param token coding 应用的token
* @return full url
*/
public static String getCodingUserInfoUrl(String token) {
return MessageFormat.format(CODING_USER_INFO_PATTERN, AuthSource.CODING.userInfo(), token);
}
/**
* 获取coding授权地址
*
* @param clientId coding 应用的Client ID
* @param redirectUrl coding 应用授权成功后的回调地址
* @param state 随机字符串,用于保持会话状态,防止CSRF攻击
* @return full url
*/
public static String getCodingAuthorizeUrl(String clientId, String redirectUrl, String state) {
return MessageFormat.format(CODING_AUTHORIZE_PATTERN, AuthSource.CODING.authorize(), clientId, redirectUrl, getState(state));
}
/**
* 获取alipay授权地址
*
* @param clientId alipay 应用的Client ID
* @param redirectUrl alipay 应用授权成功后的回调地址
* @param state 随机字符串,用于保持会话状态,防止CSRF攻击
* @return full url
*/
public static String getAlipayAuthorizeUrl(String clientId, String redirectUrl, String state) {
return MessageFormat.format(ALIPAY_AUTHORIZE_PATTERN, AuthSource.ALIPAY.authorize(), clientId, redirectUrl, getState(state));
}
/**
* 获取Facebook授权地址
*
* @param clientId Facebook 应用的Client ID
* @param redirectUrl Facebook 应用授权成功后的回调地址
* @param state 随机字符串,用于保持会话状态,防止CSRF攻击
* @return full url
*/
public static String getFacebookAuthorizeUrl(String clientId, String redirectUrl, String state) {
return MessageFormat.format(FACEBOOK_AUTHORIZE_PATTERN, AuthSource.FACEBOOK.authorize(), clientId, redirectUrl, getState(state));
}
/**
* 获取Facebook token的接口地址
*
* @param clientId Facebook 应用的Client ID
* @param clientSecret Facebook 应用的Client Secret
* @param code Facebook 授权前的code,用来换token
* @param redirectUri 待跳转的页面
* @return full url
*/
public static String getFacebookAccessTokenUrl(String clientId, String clientSecret, String code, String redirectUri) {
return MessageFormat.format(FACEBOOK_ACCESS_TOKEN_PATTERN, AuthSource.FACEBOOK.accessToken(), clientId, clientSecret, code, redirectUri);
}
/**
* 获取Facebook用户详情的接口地址
*
* @param token Facebook 应用的token
* @return full url
*/
public static String getFacebookUserInfoUrl(String token) {
return MessageFormat.format(FACEBOOK_USER_INFO_PATTERN, AuthSource.FACEBOOK.userInfo(), token);
}
/**
* 获取Douyin授权地址
*
* @param clientId Douyin 应用的Client ID
* @param redirectUrl Douyin 应用授权成功后的回调地址
* @param state 随机字符串,用于保持会话状态,防止CSRF攻击
* @return full url
*/
public static String getDouyinAuthorizeUrl(String clientId, String redirectUrl, String state) {
return MessageFormat.format(DOUYIN_AUTHORIZE_PATTERN, AuthSource.DOUYIN.authorize(), clientId, redirectUrl, getState(state));
}
/**
* 获取Douyin token的接口地址
*
* @param clientId Douyin 应用的Client ID
* @param clientSecret Douyin 应用的Client Secret
* @param code Douyin 授权前的code,用来换token
* @return full url
*/
public static String getDouyinAccessTokenUrl(String clientId, String clientSecret, String code) {
return MessageFormat.format(DOUYIN_ACCESS_TOKEN_PATTERN, AuthSource.DOUYIN.accessToken(), clientId, clientSecret, code);
}
/**
* 获取Douyin用户详情的接口地址
*
* @param token Douyin 应用的token
* @param openId 用户在当前应用的唯一标识 通过token接口获取
* @return full url
*/
public static String getDouyinUserInfoUrl(String token, String openId) {
return MessageFormat.format(DOUYIN_USER_INFO_PATTERN, AuthSource.DOUYIN.userInfo(), token, openId);
}
/**
* 获取Douyin 刷新令牌 地址
*
* @param clientId Douyin 应用的client_key
* @param refreshToken Douyin 应用返回的refresh_token
* @return full url
*/
public static String getDouyinRefreshUrl(String clientId, String refreshToken) {
return MessageFormat.format(DOUYIN_REFRESH_TOKEN_PATTERN, AuthSource.DOUYIN.refresh(), clientId, refreshToken);
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册