提交 8a486107 编写于 作者: 智布道's avatar 智布道 👁

rename

上级 65334d0f
package me.zhyd.oauth.config;
import me.zhyd.oauth.exception.AuthException;
import me.zhyd.oauth.request.ResponseStatus;
import me.zhyd.oauth.model.AuthResponseStatus;
/**
* 各api需要的url, 用枚举类分平台类型管理
......@@ -79,7 +79,7 @@ public enum AuthSource {
@Override
public String accessToken() {
throw new AuthException(ResponseStatus.UNSUPPORTED);
throw new AuthException(AuthResponseStatus.UNSUPPORTED);
}
@Override
......@@ -265,7 +265,7 @@ public enum AuthSource {
@Override
public String userInfo() {
throw new AuthException(ResponseStatus.UNSUPPORTED);
throw new AuthException(AuthResponseStatus.UNSUPPORTED);
}
},
/**
......@@ -473,7 +473,7 @@ public enum AuthSource {
* @return url
*/
public String revoke() {
throw new AuthException(ResponseStatus.UNSUPPORTED);
throw new AuthException(AuthResponseStatus.UNSUPPORTED);
}
/**
......@@ -482,7 +482,7 @@ public enum AuthSource {
* @return url
*/
public String refresh() {
throw new AuthException(ResponseStatus.UNSUPPORTED);
throw new AuthException(AuthResponseStatus.UNSUPPORTED);
}
}
\ No newline at end of file
package me.zhyd.oauth.exception;
import me.zhyd.oauth.request.ResponseStatus;
import me.zhyd.oauth.model.AuthResponseStatus;
/**
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
......@@ -13,7 +13,7 @@ public class AuthException extends RuntimeException {
private String errorMsg;
public AuthException(String errorMsg) {
this(ResponseStatus.FAILURE.getCode(), errorMsg);
this(AuthResponseStatus.FAILURE.getCode(), errorMsg);
}
public AuthException(int errorCode, String errorMsg) {
......@@ -22,7 +22,7 @@ public class AuthException extends RuntimeException {
this.errorMsg = errorMsg;
}
public AuthException(ResponseStatus status) {
public AuthException(AuthResponseStatus status) {
super(status.getMsg());
}
......
......@@ -3,7 +3,6 @@ package me.zhyd.oauth.model;
import lombok.Builder;
import lombok.Getter;
import lombok.Setter;
import me.zhyd.oauth.request.ResponseStatus;
/**
* JustAuth统一授权响应类
......@@ -37,6 +36,6 @@ public class AuthResponse<T> {
* @return true or false
*/
public boolean ok() {
return this.code == ResponseStatus.SUCCESS.getCode();
return this.code == AuthResponseStatus.SUCCESS.getCode();
}
}
package me.zhyd.oauth.request;
package me.zhyd.oauth.model;
/**
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
* @version 1.0
* @since 1.8
*/
public enum ResponseStatus {
public enum AuthResponseStatus {
SUCCESS(2000, "Success"),
FAILURE(5000, "Failure"),
NOT_IMPLEMENTED(5001, "Not Implemented"),
......@@ -21,7 +21,7 @@ public enum ResponseStatus {
private int code;
private String msg;
ResponseStatus(int code, String msg) {
AuthResponseStatus(int code, String msg) {
this.code = code;
this.msg = msg;
}
......
......@@ -14,7 +14,7 @@ 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.AuthAlipayUrlBuilder;
import me.zhyd.oauth.utils.StringUtils;
/**
......@@ -24,12 +24,12 @@ import me.zhyd.oauth.utils.StringUtils;
* @version 1.0
* @since 1.8
*/
public class AuthAlipayRequest extends BaseAuthRequest {
public class AuthAlipayRequest extends AuthDefaultRequest {
private AlipayClient alipayClient;
public AuthAlipayRequest(AuthConfig config) {
super(config, AuthSource.ALIPAY, new AlipayUrlBuilder());
super(config, AuthSource.ALIPAY, new AuthAlipayUrlBuilder());
this.alipayClient = new DefaultAlipayClient(AuthSource.ALIPAY.accessToken(), config.getClientId(), config.getClientSecret(), "json", "UTF-8", config
.getAlipayPublicKey(), "RSA2");
}
......
......@@ -8,7 +8,7 @@ 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.url.BaiduUrlBuilder;
import me.zhyd.oauth.url.AuthBaiduUrlBuilder;
import me.zhyd.oauth.url.entity.AuthUserInfoEntity;
/**
......@@ -18,10 +18,10 @@ import me.zhyd.oauth.url.entity.AuthUserInfoEntity;
* @version 1.0
* @since 1.8
*/
public class AuthBaiduRequest extends BaseAuthRequest {
public class AuthBaiduRequest extends AuthDefaultRequest {
public AuthBaiduRequest(AuthConfig config) {
super(config, AuthSource.BAIDU, new BaiduUrlBuilder());
super(config, AuthSource.BAIDU, new AuthBaiduUrlBuilder());
}
@Override
......@@ -71,11 +71,11 @@ public class AuthBaiduRequest extends BaseAuthRequest {
JSONObject object = JSONObject.parseObject(userInfo);
if (object.containsKey("error_code")) {
return AuthResponse.builder()
.code(ResponseStatus.FAILURE.getCode())
.code(AuthResponseStatus.FAILURE.getCode())
.msg(object.getString("error_msg"))
.build();
}
ResponseStatus status = object.getIntValue("result") == 1 ? ResponseStatus.SUCCESS : ResponseStatus.FAILURE;
AuthResponseStatus status = object.getIntValue("result") == 1 ? AuthResponseStatus.SUCCESS : AuthResponseStatus.FAILURE;
return AuthResponse.builder().code(status.getCode()).msg(status.getMsg()).build();
}
......
......@@ -10,7 +10,7 @@ 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.CodingUrlBuilder;
import me.zhyd.oauth.url.AuthCodingUrlBuilder;
import me.zhyd.oauth.url.entity.AuthUserInfoEntity;
/**
......@@ -20,10 +20,10 @@ import me.zhyd.oauth.url.entity.AuthUserInfoEntity;
* @version 1.0
* @since 1.8
*/
public class AuthCodingRequest extends BaseAuthRequest {
public class AuthCodingRequest extends AuthDefaultRequest {
public AuthCodingRequest(AuthConfig config) {
super(config, AuthSource.CODING, new CodingUrlBuilder());
super(config, AuthSource.CODING, new AuthCodingUrlBuilder());
}
@Override
......
......@@ -10,7 +10,7 @@ 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.CsdnUrlBuilder;
import me.zhyd.oauth.url.AuthCsdnUrlBuilder;
import me.zhyd.oauth.url.entity.AuthUserInfoEntity;
/**
......@@ -21,10 +21,10 @@ import me.zhyd.oauth.url.entity.AuthUserInfoEntity;
* @since 1.8
*/
@Deprecated
public class AuthCsdnRequest extends BaseAuthRequest {
public class AuthCsdnRequest extends AuthDefaultRequest {
public AuthCsdnRequest(AuthConfig config) {
super(config, AuthSource.CSDN, new CsdnUrlBuilder());
super(config, AuthSource.CSDN, new AuthCsdnUrlBuilder());
}
@Override
......
......@@ -4,35 +4,34 @@ import lombok.Data;
import me.zhyd.oauth.config.AuthConfig;
import me.zhyd.oauth.config.AuthSource;
import me.zhyd.oauth.exception.AuthException;
import me.zhyd.oauth.model.AuthCallback;
import me.zhyd.oauth.model.AuthResponse;
import me.zhyd.oauth.model.AuthToken;
import me.zhyd.oauth.model.AuthUser;
import me.zhyd.oauth.url.AbstractUrlBuilder;
import me.zhyd.oauth.model.*;
import me.zhyd.oauth.url.AuthDefaultUrlBuilder;
import me.zhyd.oauth.utils.AuthChecker;
/**
* 默认的request处理类
*
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
* @version 1.0
* @since 1.8
*/
@Data
public abstract class BaseAuthRequest implements AuthRequest {
public abstract class AuthDefaultRequest implements AuthRequest {
protected AuthConfig config;
protected AuthSource source;
protected AbstractUrlBuilder urlBuilder;
protected AuthDefaultUrlBuilder urlBuilder;
public BaseAuthRequest(AuthConfig config, AuthSource source) {
public AuthDefaultRequest(AuthConfig config, AuthSource source) {
this.config = config;
this.source = source;
if (!AuthChecker.isSupportedAuth(config, source)) {
throw new AuthException(ResponseStatus.PARAMETER_INCOMPLETE);
throw new AuthException(AuthResponseStatus.PARAMETER_INCOMPLETE);
}
// 校验配置合法性
AuthChecker.checkConfig(config, source);
}
public BaseAuthRequest(AuthConfig config, AuthSource source, AbstractUrlBuilder urlBuilder) {
public AuthDefaultRequest(AuthConfig config, AuthSource source, AuthDefaultUrlBuilder urlBuilder) {
this(config, source);
this.urlBuilder = urlBuilder;
this.urlBuilder.setAuthConfig(config);
......@@ -50,14 +49,14 @@ public abstract class BaseAuthRequest implements AuthRequest {
AuthToken authToken = this.getAccessToken(authCallback);
AuthUser user = this.getUserInfo(authToken);
return AuthResponse.builder().code(ResponseStatus.SUCCESS.getCode()).data(user).build();
return AuthResponse.builder().code(AuthResponseStatus.SUCCESS.getCode()).data(user).build();
} catch (Exception e) {
return this.responseError(e);
}
}
private AuthResponse responseError(Exception e) {
int errorCode = ResponseStatus.FAILURE.getCode();
int errorCode = AuthResponseStatus.FAILURE.getCode();
if (e instanceof AuthException) {
errorCode = ((AuthException) e).getErrorCode();
}
......
......@@ -12,7 +12,7 @@ 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.AuthDingtalkUrlBuilder;
import me.zhyd.oauth.url.entity.AuthUserInfoEntity;
import me.zhyd.oauth.utils.GlobalAuthUtil;
......@@ -23,10 +23,10 @@ import me.zhyd.oauth.utils.GlobalAuthUtil;
* @version 1.0
* @since 1.8
*/
public class AuthDingTalkRequest extends BaseAuthRequest {
public class AuthDingTalkRequest extends AuthDefaultRequest {
public AuthDingTalkRequest(AuthConfig config) {
super(config, AuthSource.DINGTALK, new DingtalkUrlBuilder());
super(config, AuthSource.DINGTALK, new AuthDingtalkUrlBuilder());
}
@Override
......
......@@ -7,7 +7,7 @@ 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.url.DouyinUrlBuilder;
import me.zhyd.oauth.url.AuthDouyinUrlBuilder;
import me.zhyd.oauth.url.entity.AuthUserInfoEntity;
......@@ -18,10 +18,10 @@ import me.zhyd.oauth.url.entity.AuthUserInfoEntity;
* @version 1.0
* @since 1.8
*/
public class AuthDouyinRequest extends BaseAuthRequest {
public class AuthDouyinRequest extends AuthDefaultRequest {
public AuthDouyinRequest(AuthConfig config) {
super(config, AuthSource.DOUYIN, new DouyinUrlBuilder());
super(config, AuthSource.DOUYIN, new AuthDouyinUrlBuilder());
}
@Override
......@@ -59,7 +59,7 @@ public class AuthDouyinRequest extends BaseAuthRequest {
public AuthResponse refresh(AuthToken oldToken) {
String refreshTokenUrl = this.urlBuilder.getRefreshUrl(oldToken.getRefreshToken());
return AuthResponse.builder()
.code(ResponseStatus.SUCCESS.getCode())
.code(AuthResponseStatus.SUCCESS.getCode())
.data(this.getToken(refreshTokenUrl))
.build();
}
......
......@@ -10,7 +10,7 @@ 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.FacebookUrlBuilder;
import me.zhyd.oauth.url.AuthFacebookUrlBuilder;
import me.zhyd.oauth.url.entity.AuthUserInfoEntity;
/**
......@@ -20,10 +20,10 @@ import me.zhyd.oauth.url.entity.AuthUserInfoEntity;
* @version 1.0
* @since 1.8
*/
public class AuthFacebookRequest extends BaseAuthRequest {
public class AuthFacebookRequest extends AuthDefaultRequest {
public AuthFacebookRequest(AuthConfig config) {
super(config, AuthSource.FACEBOOK, new FacebookUrlBuilder());
super(config, AuthSource.FACEBOOK, new AuthFacebookUrlBuilder());
}
@Override
......
......@@ -10,7 +10,7 @@ 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.GiteeUrlBuilder;
import me.zhyd.oauth.url.AuthGiteeUrlBuilder;
import me.zhyd.oauth.url.entity.AuthUserInfoEntity;
/**
......@@ -20,10 +20,10 @@ import me.zhyd.oauth.url.entity.AuthUserInfoEntity;
* @version 1.0
* @since 1.8
*/
public class AuthGiteeRequest extends BaseAuthRequest {
public class AuthGiteeRequest extends AuthDefaultRequest {
public AuthGiteeRequest(AuthConfig config) {
super(config, AuthSource.GITEE, new GiteeUrlBuilder());
super(config, AuthSource.GITEE, new AuthGiteeUrlBuilder());
}
@Override
......
......@@ -10,7 +10,7 @@ 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.GithubUrlBuilder;
import me.zhyd.oauth.url.AuthGithubUrlBuilder;
import me.zhyd.oauth.url.entity.AuthUserInfoEntity;
import me.zhyd.oauth.utils.GlobalAuthUtil;
......@@ -23,10 +23,10 @@ import java.util.Map;
* @version 1.0
* @since 1.8
*/
public class AuthGithubRequest extends BaseAuthRequest {
public class AuthGithubRequest extends AuthDefaultRequest {
public AuthGithubRequest(AuthConfig config) {
super(config, AuthSource.GITHUB, new GithubUrlBuilder());
super(config, AuthSource.GITHUB, new AuthGithubUrlBuilder());
}
@Override
......
......@@ -10,7 +10,7 @@ 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.GoogleUrlBuilder;
import me.zhyd.oauth.url.AuthGoogleUrlBuilder;
import me.zhyd.oauth.url.entity.AuthUserInfoEntity;
/**
......@@ -20,10 +20,10 @@ import me.zhyd.oauth.url.entity.AuthUserInfoEntity;
* @version 1.3
* @since 1.3
*/
public class AuthGoogleRequest extends BaseAuthRequest {
public class AuthGoogleRequest extends AuthDefaultRequest {
public AuthGoogleRequest(AuthConfig config) {
super(config, AuthSource.GOOGLE, new GoogleUrlBuilder());
super(config, AuthSource.GOOGLE, new AuthGoogleUrlBuilder());
}
@Override
......
......@@ -8,7 +8,7 @@ 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.url.LinkedinUrlBuilder;
import me.zhyd.oauth.url.AuthLinkedinUrlBuilder;
import me.zhyd.oauth.url.entity.AuthUserInfoEntity;
import me.zhyd.oauth.utils.StringUtils;
......@@ -20,10 +20,10 @@ import me.zhyd.oauth.utils.StringUtils;
* @version 1.0
* @since 1.8
*/
public class AuthLinkedinRequest extends BaseAuthRequest {
public class AuthLinkedinRequest extends AuthDefaultRequest {
public AuthLinkedinRequest(AuthConfig config) {
super(config, AuthSource.LINKEDIN, new LinkedinUrlBuilder());
super(config, AuthSource.LINKEDIN, new AuthLinkedinUrlBuilder());
}
@Override
......@@ -116,11 +116,11 @@ public class AuthLinkedinRequest extends BaseAuthRequest {
@Override
public AuthResponse refresh(AuthToken oldToken) {
if (StringUtils.isEmpty(oldToken.getRefreshToken())) {
throw new AuthException(ResponseStatus.UNSUPPORTED);
throw new AuthException(AuthResponseStatus.UNSUPPORTED);
}
String refreshTokenUrl = this.urlBuilder.getRefreshUrl(oldToken.getRefreshToken());
return AuthResponse.builder()
.code(ResponseStatus.SUCCESS.getCode())
.code(AuthResponseStatus.SUCCESS.getCode())
.data(this.getToken(refreshTokenUrl))
.build();
}
......
......@@ -8,7 +8,7 @@ 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.url.MiUrlBuilder;
import me.zhyd.oauth.url.AuthMiUrlBuilder;
import me.zhyd.oauth.url.entity.AuthUserInfoEntity;
import java.text.MessageFormat;
......@@ -20,11 +20,11 @@ import java.text.MessageFormat;
* @version 1.5
* @since 1.5
*/
public class AuthMiRequest extends BaseAuthRequest {
public class AuthMiRequest extends AuthDefaultRequest {
private static final String PREFIX = "&&&START&&&";
public AuthMiRequest(AuthConfig config) {
super(config, AuthSource.MI, new MiUrlBuilder());
super(config, AuthSource.MI, new AuthMiUrlBuilder());
}
@Override
......@@ -105,6 +105,6 @@ public class AuthMiRequest extends BaseAuthRequest {
public AuthResponse refresh(AuthToken authToken) {
String miRefreshUrl = this.urlBuilder.getRefreshUrl(authToken.getRefreshToken());
return AuthResponse.builder().code(ResponseStatus.SUCCESS.getCode()).data(getToken(miRefreshUrl)).build();
return AuthResponse.builder().code(AuthResponseStatus.SUCCESS.getCode()).data(getToken(miRefreshUrl)).build();
}
}
......@@ -8,7 +8,7 @@ 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.url.MicrosoftUrlBuilder;
import me.zhyd.oauth.url.AuthMicrosoftUrlBuilder;
import me.zhyd.oauth.url.entity.AuthUserInfoEntity;
import java.util.HashMap;
......@@ -21,9 +21,9 @@ import java.util.Map;
* @version 1.5
* @since 1.5
*/
public class AuthMicrosoftRequest extends BaseAuthRequest {
public class AuthMicrosoftRequest extends AuthDefaultRequest {
public AuthMicrosoftRequest(AuthConfig config) {
super(config, AuthSource.MICROSOFT, new MicrosoftUrlBuilder());
super(config, AuthSource.MICROSOFT, new AuthMicrosoftUrlBuilder());
}
@Override
......@@ -99,6 +99,6 @@ public class AuthMicrosoftRequest extends BaseAuthRequest {
public AuthResponse refresh(AuthToken authToken) {
String refreshTokenUrl = this.urlBuilder.getRefreshUrl(authToken.getRefreshToken());
return AuthResponse.builder().code(ResponseStatus.SUCCESS.getCode()).data(getToken(refreshTokenUrl)).build();
return AuthResponse.builder().code(AuthResponseStatus.SUCCESS.getCode()).data(getToken(refreshTokenUrl)).build();
}
}
......@@ -10,7 +10,7 @@ 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.OschinaUrlBuilder;
import me.zhyd.oauth.url.AuthOschinaUrlBuilder;
import me.zhyd.oauth.url.entity.AuthUserInfoEntity;
/**
......@@ -20,10 +20,10 @@ import me.zhyd.oauth.url.entity.AuthUserInfoEntity;
* @version 1.0
* @since 1.8
*/
public class AuthOschinaRequest extends BaseAuthRequest {
public class AuthOschinaRequest extends AuthDefaultRequest {
public AuthOschinaRequest(AuthConfig config) {
super(config, AuthSource.OSCHINA, new OschinaUrlBuilder());
super(config, AuthSource.OSCHINA, new AuthOschinaUrlBuilder());
}
@Override
......
......@@ -11,7 +11,7 @@ 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.AuthQqUrlBuilder;
import me.zhyd.oauth.url.entity.AuthUserInfoEntity;
import me.zhyd.oauth.utils.GlobalAuthUtil;
import me.zhyd.oauth.utils.StringUtils;
......@@ -26,9 +26,9 @@ import java.util.Map;
* @version 1.0
* @since 1.8
*/
public class AuthQqRequest extends BaseAuthRequest {
public class AuthQqRequest extends AuthDefaultRequest {
public AuthQqRequest(AuthConfig config) {
super(config, AuthSource.QQ, new QqUrlBuilder());
super(config, AuthSource.QQ, new AuthQqUrlBuilder());
}
@Override
......
......@@ -3,6 +3,7 @@ package me.zhyd.oauth.request;
import me.zhyd.oauth.exception.AuthException;
import me.zhyd.oauth.model.AuthCallback;
import me.zhyd.oauth.model.AuthResponse;
import me.zhyd.oauth.model.AuthResponseStatus;
import me.zhyd.oauth.model.AuthToken;
/**
......@@ -18,7 +19,7 @@ public interface AuthRequest {
* @return 返回授权地址
*/
default String authorize() {
throw new AuthException(ResponseStatus.NOT_IMPLEMENTED);
throw new AuthException(AuthResponseStatus.NOT_IMPLEMENTED);
}
/**
......@@ -28,7 +29,7 @@ public interface AuthRequest {
* @return 返回登录成功后的用户信息
*/
default AuthResponse login(AuthCallback authCallback) {
throw new AuthException(ResponseStatus.NOT_IMPLEMENTED);
throw new AuthException(AuthResponseStatus.NOT_IMPLEMENTED);
}
/**
......@@ -38,7 +39,7 @@ public interface AuthRequest {
* @return AuthResponse
*/
default AuthResponse revoke(AuthToken authToken) {
throw new AuthException(ResponseStatus.NOT_IMPLEMENTED);
throw new AuthException(AuthResponseStatus.NOT_IMPLEMENTED);
}
/**
......@@ -48,6 +49,6 @@ public interface AuthRequest {
* @return AuthResponse
*/
default AuthResponse refresh(AuthToken authToken) {
throw new AuthException(ResponseStatus.NOT_IMPLEMENTED);
throw new AuthException(AuthResponseStatus.NOT_IMPLEMENTED);
}
}
......@@ -6,11 +6,8 @@ import com.alibaba.fastjson.JSONObject;
import me.zhyd.oauth.config.AuthConfig;
import me.zhyd.oauth.config.AuthSource;
import me.zhyd.oauth.exception.AuthException;
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.model.*;
import me.zhyd.oauth.url.AuthTaobaoUrlBuilder;
import me.zhyd.oauth.utils.GlobalAuthUtil;
/**
......@@ -20,10 +17,10 @@ import me.zhyd.oauth.utils.GlobalAuthUtil;
* @version 1.0
* @since 1.8
*/
public class AuthTaobaoRequest extends BaseAuthRequest {
public class AuthTaobaoRequest extends AuthDefaultRequest {
public AuthTaobaoRequest(AuthConfig config) {
super(config, AuthSource.TAOBAO, new TaobaoUrlBuilder());
super(config, AuthSource.TAOBAO, new AuthTaobaoUrlBuilder());
}
@Override
......@@ -37,7 +34,7 @@ public class AuthTaobaoRequest extends BaseAuthRequest {
HttpResponse response = HttpRequest.post(this.urlBuilder.getAccessTokenUrl(accessCode)).execute();
JSONObject accessTokenObject = JSONObject.parseObject(response.body());
if (accessTokenObject.containsKey("error")) {
throw new AuthException(ResponseStatus.FAILURE + ":" + accessTokenObject.getString("error_description"));
throw new AuthException(AuthResponseStatus.FAILURE + ":" + accessTokenObject.getString("error_description"));
}
authToken.setAccessToken(accessTokenObject.getString("access_token"));
authToken.setRefreshToken(accessTokenObject.getString("refresh_token"));
......
......@@ -10,7 +10,7 @@ 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.TencentCloudUrlBuilder;
import me.zhyd.oauth.url.AuthTencentCloudUrlBuilder;
import me.zhyd.oauth.url.entity.AuthUserInfoEntity;
/**
......@@ -20,10 +20,10 @@ import me.zhyd.oauth.url.entity.AuthUserInfoEntity;
* @version 1.0
* @since 1.8
*/
public class AuthTencentCloudRequest extends BaseAuthRequest {
public class AuthTencentCloudRequest extends AuthDefaultRequest {
public AuthTencentCloudRequest(AuthConfig config) {
super(config, AuthSource.TENCENT_CLOUD, new TencentCloudUrlBuilder());
super(config, AuthSource.TENCENT_CLOUD, new AuthTencentCloudUrlBuilder());
}
@Override
......
......@@ -11,7 +11,7 @@ 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.AuthToutiaoUrlBuilder;
import me.zhyd.oauth.url.entity.AuthUserInfoEntity;
/**
......@@ -21,10 +21,10 @@ import me.zhyd.oauth.url.entity.AuthUserInfoEntity;
* @version 1.5
* @since 1.5
*/
public class AuthToutiaoRequest extends BaseAuthRequest {
public class AuthToutiaoRequest extends AuthDefaultRequest {
public AuthToutiaoRequest(AuthConfig config) {
super(config, AuthSource.TOUTIAO, new ToutiaoUrlBuilder());
super(config, AuthSource.TOUTIAO, new AuthToutiaoUrlBuilder());
}
@Override
......
......@@ -7,7 +7,7 @@ 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.url.WechatUrlBuilder;
import me.zhyd.oauth.url.AuthWechatUrlBuilder;
import me.zhyd.oauth.url.entity.AuthUserInfoEntity;
/**
......@@ -17,9 +17,9 @@ import me.zhyd.oauth.url.entity.AuthUserInfoEntity;
* @version 1.0
* @since 1.8
*/
public class AuthWeChatRequest extends BaseAuthRequest {
public class AuthWeChatRequest extends AuthDefaultRequest {
public AuthWeChatRequest(AuthConfig config) {
super(config, AuthSource.WECHAT, new WechatUrlBuilder());
super(config, AuthSource.WECHAT, new AuthWechatUrlBuilder());
}
/**
......@@ -64,7 +64,7 @@ public class AuthWeChatRequest extends BaseAuthRequest {
public AuthResponse refresh(AuthToken oldToken) {
String refreshTokenUrl = this.urlBuilder.getRefreshUrl(oldToken.getRefreshToken());
return AuthResponse.builder()
.code(ResponseStatus.SUCCESS.getCode())
.code(AuthResponseStatus.SUCCESS.getCode())
.data(this.getToken(refreshTokenUrl))
.build();
}
......
......@@ -10,7 +10,7 @@ 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.WeiboUrlBuilder;
import me.zhyd.oauth.url.AuthWeiboUrlBuilder;
import me.zhyd.oauth.url.entity.AuthUserInfoEntity;
import me.zhyd.oauth.utils.IpUtils;
import me.zhyd.oauth.utils.StringUtils;
......@@ -23,10 +23,10 @@ import me.zhyd.oauth.utils.StringUtils;
* @version 1.0
* @since 1.8
*/
public class AuthWeiboRequest extends BaseAuthRequest {
public class AuthWeiboRequest extends AuthDefaultRequest {
public AuthWeiboRequest(AuthConfig config) {
super(config, AuthSource.WEIBO, new WeiboUrlBuilder());
super(config, AuthSource.WEIBO, new AuthWeiboUrlBuilder());
}
@Override
......
package me.zhyd.oauth.url;
import me.zhyd.oauth.config.AuthSource;
import me.zhyd.oauth.exception.AuthException;
import me.zhyd.oauth.model.AuthResponseStatus;
import me.zhyd.oauth.url.entity.AuthUserInfoEntity;
import java.text.MessageFormat;
......@@ -12,18 +14,18 @@ import java.text.MessageFormat;
* @version 1.0
* @since 1.8
*/
public class AlipayUrlBuilder extends AbstractUrlBuilder {
public class AuthAlipayUrlBuilder extends AuthDefaultUrlBuilder {
private static final String ALIPAY_AUTHORIZE_PATTERN = "{0}?app_id={1}&scope=auth_user&redirect_uri={2}&state={3}";
@Override
public String getAccessTokenUrl(String code) {
return null;
throw new AuthException(AuthResponseStatus.NOT_IMPLEMENTED);
}
@Override
public String getUserInfoUrl(AuthUserInfoEntity userInfoEntity) {
return null;
throw new AuthException(AuthResponseStatus.NOT_IMPLEMENTED);
}
@Override
......@@ -33,11 +35,11 @@ public class AlipayUrlBuilder extends AbstractUrlBuilder {
@Override
public String getRefreshUrl(String refreshToken) {
return null;
throw new AuthException(AuthResponseStatus.NOT_IMPLEMENTED);
}
@Override
public String getRevokeUrl(String accessToken) {
return null;
throw new AuthException(AuthResponseStatus.NOT_IMPLEMENTED);
}
}
package me.zhyd.oauth.url;
import me.zhyd.oauth.config.AuthSource;
import me.zhyd.oauth.exception.AuthException;
import me.zhyd.oauth.model.AuthResponseStatus;
import me.zhyd.oauth.url.entity.AuthUserInfoEntity;
import java.text.MessageFormat;
......@@ -12,7 +14,7 @@ import java.text.MessageFormat;
* @version 1.0
* @since 1.8
*/
public class BaiduUrlBuilder extends AbstractUrlBuilder {
public class AuthBaiduUrlBuilder extends AuthDefaultUrlBuilder {
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}";
......@@ -36,7 +38,7 @@ public class BaiduUrlBuilder extends AbstractUrlBuilder {
@Override
public String getRefreshUrl(String refreshToken) {
return null;
throw new AuthException(AuthResponseStatus.NOT_IMPLEMENTED);
}
@Override
......
package me.zhyd.oauth.url;
import me.zhyd.oauth.config.AuthSource;
import me.zhyd.oauth.exception.AuthException;
import me.zhyd.oauth.model.AuthResponseStatus;
import me.zhyd.oauth.url.entity.AuthUserInfoEntity;
import java.text.MessageFormat;
......@@ -12,7 +14,7 @@ import java.text.MessageFormat;
* @version 1.0
* @since 1.8
*/
public class CodingUrlBuilder extends AbstractUrlBuilder {
public class AuthCodingUrlBuilder extends AuthDefaultUrlBuilder {
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}";
......@@ -35,11 +37,11 @@ public class CodingUrlBuilder extends AbstractUrlBuilder {
@Override
public String getRefreshUrl(String refreshToken) {
return null;
throw new AuthException(AuthResponseStatus.NOT_IMPLEMENTED);
}
@Override
public String getRevokeUrl(String accessToken) {
return null;
throw new AuthException(AuthResponseStatus.NOT_IMPLEMENTED);
}
}
package me.zhyd.oauth.url;
import me.zhyd.oauth.config.AuthSource;
import me.zhyd.oauth.exception.AuthException;
import me.zhyd.oauth.model.AuthResponseStatus;
import me.zhyd.oauth.url.entity.AuthUserInfoEntity;
import java.text.MessageFormat;
......@@ -13,7 +15,7 @@ import java.text.MessageFormat;
* @since 1.8
*/
@Deprecated
public class CsdnUrlBuilder extends AbstractUrlBuilder {
public class AuthCsdnUrlBuilder extends AuthDefaultUrlBuilder {
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}";
......@@ -36,11 +38,11 @@ public class CsdnUrlBuilder extends AbstractUrlBuilder {
@Override
public String getRefreshUrl(String refreshToken) {
return null;
throw new AuthException(AuthResponseStatus.NOT_IMPLEMENTED);
}
@Override
public String getRevokeUrl(String accessToken) {
return null;
throw new AuthException(AuthResponseStatus.NOT_IMPLEMENTED);
}
}
......@@ -2,7 +2,7 @@ package me.zhyd.oauth.url;
import me.zhyd.oauth.config.AuthConfig;
import me.zhyd.oauth.exception.AuthException;
import me.zhyd.oauth.request.ResponseStatus;
import me.zhyd.oauth.model.AuthResponseStatus;
import me.zhyd.oauth.url.entity.AuthUserInfoEntity;
import me.zhyd.oauth.utils.StringUtils;
......@@ -11,7 +11,7 @@ import me.zhyd.oauth.utils.StringUtils;
* @version 1.0
* @since 1.8
*/
public abstract class AbstractUrlBuilder {
public abstract class AuthDefaultUrlBuilder {
protected AuthConfig config;
......@@ -64,7 +64,7 @@ public abstract class AbstractUrlBuilder {
* @return openIdUrl
*/
public String getOpenIdUrl(String accessToken, boolean unionid) {
throw new AuthException(ResponseStatus.NOT_IMPLEMENTED);
throw new AuthException(AuthResponseStatus.NOT_IMPLEMENTED);
}
/**
......
package me.zhyd.oauth.url;
import me.zhyd.oauth.config.AuthSource;
import me.zhyd.oauth.exception.AuthException;
import me.zhyd.oauth.model.AuthResponseStatus;
import me.zhyd.oauth.url.entity.AuthUserInfoEntity;
import java.text.MessageFormat;
......@@ -12,14 +14,14 @@ import java.text.MessageFormat;
* @version 1.0
* @since 1.8
*/
public class DingtalkUrlBuilder extends AbstractUrlBuilder {
public class AuthDingtalkUrlBuilder extends AuthDefaultUrlBuilder {
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(String code) {
return null;
throw new AuthException(AuthResponseStatus.NOT_IMPLEMENTED);
}
@Override
......@@ -34,11 +36,11 @@ public class DingtalkUrlBuilder extends AbstractUrlBuilder {
@Override
public String getRefreshUrl(String refreshToken) {
return null;
throw new AuthException(AuthResponseStatus.NOT_IMPLEMENTED);
}
@Override
public String getRevokeUrl(String accessToken) {
return null;
throw new AuthException(AuthResponseStatus.NOT_IMPLEMENTED);
}
}
package me.zhyd.oauth.url;
import me.zhyd.oauth.config.AuthSource;
import me.zhyd.oauth.exception.AuthException;
import me.zhyd.oauth.model.AuthResponseStatus;
import me.zhyd.oauth.url.entity.AuthUserInfoEntity;
import java.text.MessageFormat;
......@@ -12,7 +14,7 @@ import java.text.MessageFormat;
* @version 1.0
* @since 1.8
*/
public class DouyinUrlBuilder extends AbstractUrlBuilder {
public class AuthDouyinUrlBuilder extends AuthDefaultUrlBuilder {
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";
......@@ -41,6 +43,6 @@ public class DouyinUrlBuilder extends AbstractUrlBuilder {
@Override
public String getRevokeUrl(String accessToken) {
return null;
throw new AuthException(AuthResponseStatus.NOT_IMPLEMENTED);
}
}
package me.zhyd.oauth.url;
import me.zhyd.oauth.config.AuthSource;
import me.zhyd.oauth.exception.AuthException;
import me.zhyd.oauth.model.AuthResponseStatus;
import me.zhyd.oauth.url.entity.AuthUserInfoEntity;
import java.text.MessageFormat;
......@@ -12,7 +14,7 @@ import java.text.MessageFormat;
* @version 1.0
* @since 1.8
*/
public class FacebookUrlBuilder extends AbstractUrlBuilder {
public class AuthFacebookUrlBuilder extends AuthDefaultUrlBuilder {
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";
......@@ -35,11 +37,11 @@ public class FacebookUrlBuilder extends AbstractUrlBuilder {
@Override
public String getRefreshUrl(String refreshToken) {
return null;
throw new AuthException(AuthResponseStatus.NOT_IMPLEMENTED);
}
@Override
public String getRevokeUrl(String accessToken) {
return null;
throw new AuthException(AuthResponseStatus.NOT_IMPLEMENTED);
}
}
package me.zhyd.oauth.url;
import me.zhyd.oauth.config.AuthSource;
import me.zhyd.oauth.exception.AuthException;
import me.zhyd.oauth.model.AuthResponseStatus;
import me.zhyd.oauth.url.entity.*;
import java.text.MessageFormat;
......@@ -12,7 +14,7 @@ import java.text.MessageFormat;
* @version 1.0
* @since 1.8
*/
public class GiteeUrlBuilder extends AbstractUrlBuilder {
public class AuthGiteeUrlBuilder extends AuthDefaultUrlBuilder {
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}";
......@@ -35,11 +37,11 @@ public class GiteeUrlBuilder extends AbstractUrlBuilder {
@Override
public String getRefreshUrl(String refreshToken) {
return null;
throw new AuthException(AuthResponseStatus.NOT_IMPLEMENTED);
}
@Override
public String getRevokeUrl(String accessToken) {
return null;
throw new AuthException(AuthResponseStatus.NOT_IMPLEMENTED);
}
}
package me.zhyd.oauth.url;
import me.zhyd.oauth.config.AuthSource;
import me.zhyd.oauth.exception.AuthException;
import me.zhyd.oauth.model.AuthResponseStatus;
import me.zhyd.oauth.url.entity.AuthUserInfoEntity;
import java.text.MessageFormat;
......@@ -12,7 +14,7 @@ import java.text.MessageFormat;
* @version 1.0
* @since 1.8
*/
public class GithubUrlBuilder extends AbstractUrlBuilder {
public class AuthGithubUrlBuilder extends AuthDefaultUrlBuilder {
private static final String GITHUB_ACCESS_TOKEN_PATTERN = "{0}?client_id={1}&client_secret={2}&code={3}&redirect_uri={4}";
private static final String GITHUB_USER_INFO_PATTERN = "{0}?access_token={1}";
......@@ -35,11 +37,11 @@ public class GithubUrlBuilder extends AbstractUrlBuilder {
@Override
public String getRefreshUrl(String refreshToken) {
return null;
throw new AuthException(AuthResponseStatus.NOT_IMPLEMENTED);
}
@Override
public String getRevokeUrl(String accessToken) {
return null;
throw new AuthException(AuthResponseStatus.NOT_IMPLEMENTED);
}
}
package me.zhyd.oauth.url;
import me.zhyd.oauth.config.AuthSource;
import me.zhyd.oauth.exception.AuthException;
import me.zhyd.oauth.model.AuthResponseStatus;
import me.zhyd.oauth.url.entity.AuthUserInfoEntity;
import java.text.MessageFormat;
......@@ -12,7 +14,7 @@ import java.text.MessageFormat;
* @version 1.0
* @since 1.8
*/
public class GoogleUrlBuilder extends AbstractUrlBuilder {
public class AuthGoogleUrlBuilder extends AuthDefaultUrlBuilder {
private static final String GOOGLE_AUTHORIZE_PATTERN = "{0}?client_id={1}&response_type=code&scope=openid%20email%20profile&redirect_uri={2}&state={3}";
private static final String GOOGLE_ACCESS_TOKEN_PATTERN = "{0}?client_id={1}&client_secret={2}&code={3}&redirect_uri={4}&grant_type=authorization_code";
......@@ -35,11 +37,11 @@ public class GoogleUrlBuilder extends AbstractUrlBuilder {
@Override
public String getRefreshUrl(String refreshToken) {
return null;
throw new AuthException(AuthResponseStatus.NOT_IMPLEMENTED);
}
@Override
public String getRevokeUrl(String accessToken) {
return null;
throw new AuthException(AuthResponseStatus.NOT_IMPLEMENTED);
}
}
package me.zhyd.oauth.url;
import me.zhyd.oauth.config.AuthSource;
import me.zhyd.oauth.exception.AuthException;
import me.zhyd.oauth.model.AuthResponseStatus;
import me.zhyd.oauth.url.entity.AuthUserInfoEntity;
import java.text.MessageFormat;
......@@ -12,7 +14,7 @@ import java.text.MessageFormat;
* @version 1.0
* @since 1.8
*/
public class LinkedinUrlBuilder extends AbstractUrlBuilder {
public class AuthLinkedinUrlBuilder extends AuthDefaultUrlBuilder {
private static final String LINKEDIN_AUTHORIZE_PATTERN = "{0}?client_id={1}&redirect_uri={2}&state={3}&response_type=code&scope=r_liteprofile%20r_emailaddress%20w_member_social";
private static final String LINKEDIN_ACCESS_TOKEN_PATTERN = "{0}?client_id={1}&client_secret={2}&code={3}&redirect_uri={4}&grant_type=authorization_code";
......@@ -41,6 +43,6 @@ public class LinkedinUrlBuilder extends AbstractUrlBuilder {
@Override
public String getRevokeUrl(String accessToken) {
return null;
throw new AuthException(AuthResponseStatus.NOT_IMPLEMENTED);
}
}
package me.zhyd.oauth.url;
import me.zhyd.oauth.config.AuthSource;
import me.zhyd.oauth.exception.AuthException;
import me.zhyd.oauth.model.AuthResponseStatus;
import me.zhyd.oauth.url.entity.AuthUserInfoEntity;
import java.text.MessageFormat;
......@@ -12,7 +14,7 @@ import java.text.MessageFormat;
* @version 1.0
* @since 1.8
*/
public class MiUrlBuilder extends AbstractUrlBuilder {
public class AuthMiUrlBuilder extends AuthDefaultUrlBuilder {
private static final String MI_AUTHORIZE_PATTERN = "{0}?client_id={1}&redirect_uri={2}&response_type=code&scope=1%203%204%206&state={3}&skip_confirm=false";
private static final String MI_ACCESS_TOKEN_PATTERN = "{0}?client_id={1}&client_secret={2}&redirect_uri={3}&code={4}&grant_type=authorization_code";
......@@ -41,6 +43,6 @@ public class MiUrlBuilder extends AbstractUrlBuilder {
@Override
public String getRevokeUrl(String accessToken) {
return null;
throw new AuthException(AuthResponseStatus.NOT_IMPLEMENTED);
}
}
package me.zhyd.oauth.url;
import me.zhyd.oauth.config.AuthSource;
import me.zhyd.oauth.exception.AuthException;
import me.zhyd.oauth.model.AuthResponseStatus;
import me.zhyd.oauth.url.entity.AuthUserInfoEntity;
import java.text.MessageFormat;
......@@ -12,7 +14,7 @@ import java.text.MessageFormat;
* @version 1.0
* @since 1.8
*/
public class MicrosoftUrlBuilder extends AbstractUrlBuilder {
public class AuthMicrosoftUrlBuilder extends AuthDefaultUrlBuilder {
private static final String MICROSOFT_AUTHORIZE_PATTERN = "{0}?client_id={1}&response_type=code&redirect_uri={2}&response_mode=query&scope=offline_access%20user.read%20mail.read&state={3}";
private static final String MICROSOFT_ACCESS_TOKEN_PATTERN = "{0}?client_id={1}&client_secret={2}&scope=user.read%20mail.read&redirect_uri={3}&code={4}&grant_type=authorization_code";
......@@ -41,6 +43,6 @@ public class MicrosoftUrlBuilder extends AbstractUrlBuilder {
@Override
public String getRevokeUrl(String accessToken) {
return null;
throw new AuthException(AuthResponseStatus.NOT_IMPLEMENTED);
}
}
package me.zhyd.oauth.url;
import me.zhyd.oauth.config.AuthSource;
import me.zhyd.oauth.exception.AuthException;
import me.zhyd.oauth.model.AuthResponseStatus;
import me.zhyd.oauth.url.entity.AuthUserInfoEntity;
import java.text.MessageFormat;
......@@ -12,7 +14,7 @@ import java.text.MessageFormat;
* @version 1.0
* @since 1.8
*/
public class OschinaUrlBuilder extends AbstractUrlBuilder {
public class AuthOschinaUrlBuilder extends AuthDefaultUrlBuilder {
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";
......@@ -35,11 +37,11 @@ public class OschinaUrlBuilder extends AbstractUrlBuilder {
@Override
public String getRefreshUrl(String refreshToken) {
return null;
throw new AuthException(AuthResponseStatus.NOT_IMPLEMENTED);
}
@Override
public String getRevokeUrl(String accessToken) {
return null;
throw new AuthException(AuthResponseStatus.NOT_IMPLEMENTED);
}
}
package me.zhyd.oauth.url;
import me.zhyd.oauth.config.AuthSource;
import me.zhyd.oauth.exception.AuthException;
import me.zhyd.oauth.model.AuthResponseStatus;
import me.zhyd.oauth.url.entity.AuthUserInfoEntity;
import java.text.MessageFormat;
......@@ -12,7 +14,7 @@ import java.text.MessageFormat;
* @version 1.0
* @since 1.8
*/
public class QqUrlBuilder extends AbstractUrlBuilder {
public class AuthQqUrlBuilder extends AuthDefaultUrlBuilder {
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}";
......@@ -36,12 +38,12 @@ public class QqUrlBuilder extends AbstractUrlBuilder {
@Override
public String getRefreshUrl(String refreshToken) {
return null;
throw new AuthException(AuthResponseStatus.NOT_IMPLEMENTED);
}
@Override
public String getRevokeUrl(String accessToken) {
return null;
throw new AuthException(AuthResponseStatus.NOT_IMPLEMENTED);
}
@Override
......
package me.zhyd.oauth.url;
import me.zhyd.oauth.config.AuthSource;
import me.zhyd.oauth.exception.AuthException;
import me.zhyd.oauth.model.AuthResponseStatus;
import me.zhyd.oauth.url.entity.AuthUserInfoEntity;
import java.text.MessageFormat;
......@@ -12,7 +14,7 @@ import java.text.MessageFormat;
* @version 1.0
* @since 1.8
*/
public class TaobaoUrlBuilder extends AbstractUrlBuilder {
public class AuthTaobaoUrlBuilder extends AuthDefaultUrlBuilder {
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";
......@@ -24,7 +26,7 @@ public class TaobaoUrlBuilder extends AbstractUrlBuilder {
@Override
public String getUserInfoUrl(AuthUserInfoEntity userInfoEntity) {
return null;
throw new AuthException(AuthResponseStatus.NOT_IMPLEMENTED);
}
@Override
......@@ -34,11 +36,11 @@ public class TaobaoUrlBuilder extends AbstractUrlBuilder {
@Override
public String getRefreshUrl(String refreshToken) {
return null;
throw new AuthException(AuthResponseStatus.NOT_IMPLEMENTED);
}
@Override
public String getRevokeUrl(String accessToken) {
return null;
throw new AuthException(AuthResponseStatus.NOT_IMPLEMENTED);
}
}
package me.zhyd.oauth.url;
import me.zhyd.oauth.config.AuthSource;
import me.zhyd.oauth.exception.AuthException;
import me.zhyd.oauth.model.AuthResponseStatus;
import me.zhyd.oauth.url.entity.AuthUserInfoEntity;
import java.text.MessageFormat;
......@@ -12,7 +14,7 @@ import java.text.MessageFormat;
* @version 1.0
* @since 1.8
*/
public class TencentCloudUrlBuilder extends AbstractUrlBuilder {
public class AuthTencentCloudUrlBuilder extends AuthDefaultUrlBuilder {
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}";
......@@ -35,11 +37,11 @@ public class TencentCloudUrlBuilder extends AbstractUrlBuilder {
@Override
public String getRefreshUrl(String refreshToken) {
return null;
throw new AuthException(AuthResponseStatus.NOT_IMPLEMENTED);
}
@Override
public String getRevokeUrl(String accessToken) {
return null;
throw new AuthException(AuthResponseStatus.NOT_IMPLEMENTED);
}
}
package me.zhyd.oauth.url;
import me.zhyd.oauth.config.AuthSource;
import me.zhyd.oauth.exception.AuthException;
import me.zhyd.oauth.model.AuthResponseStatus;
import me.zhyd.oauth.url.entity.AuthUserInfoEntity;
import java.text.MessageFormat;
......@@ -12,7 +14,7 @@ import java.text.MessageFormat;
* @version 1.0
* @since 1.8
*/
public class ToutiaoUrlBuilder extends AbstractUrlBuilder {
public class AuthToutiaoUrlBuilder extends AuthDefaultUrlBuilder {
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}";
......@@ -35,11 +37,11 @@ public class ToutiaoUrlBuilder extends AbstractUrlBuilder {
@Override
public String getRefreshUrl(String refreshToken) {
return null;
throw new AuthException(AuthResponseStatus.NOT_IMPLEMENTED);
}
@Override
public String getRevokeUrl(String accessToken) {
return null;
throw new AuthException(AuthResponseStatus.NOT_IMPLEMENTED);
}
}
package me.zhyd.oauth.url;
import me.zhyd.oauth.config.AuthSource;
import me.zhyd.oauth.exception.AuthException;
import me.zhyd.oauth.model.AuthResponseStatus;
import me.zhyd.oauth.url.entity.AuthUserInfoEntity;
import java.text.MessageFormat;
......@@ -12,7 +14,7 @@ import java.text.MessageFormat;
* @version 1.0
* @since 1.8
*/
public class WechatUrlBuilder extends AbstractUrlBuilder {
public class AuthWechatUrlBuilder extends AuthDefaultUrlBuilder {
private static final String WECHAT_AUTHORIZE_PATTERN = "{0}?appid={1}&redirect_uri={2}&response_type=code&scope=snsapi_login&state={3}#wechat_redirect";
private static final String WECHAT_ACCESS_TOKEN_PATTERN = "{0}?appid={1}&secret={2}&code={3}&grant_type=authorization_code";
......@@ -41,6 +43,6 @@ public class WechatUrlBuilder extends AbstractUrlBuilder {
@Override
public String getRevokeUrl(String accessToken) {
return null;
throw new AuthException(AuthResponseStatus.NOT_IMPLEMENTED);
}
}
package me.zhyd.oauth.url;
import me.zhyd.oauth.config.AuthSource;
import me.zhyd.oauth.exception.AuthException;
import me.zhyd.oauth.model.AuthResponseStatus;
import me.zhyd.oauth.url.entity.AuthUserInfoEntity;
import java.text.MessageFormat;
......@@ -12,7 +14,7 @@ import java.text.MessageFormat;
* @version 1.0
* @since 1.8
*/
public class WeiboUrlBuilder extends AbstractUrlBuilder {
public class AuthWeiboUrlBuilder extends AuthDefaultUrlBuilder {
private static final String WEIBO_ACCESS_TOKEN_PATTERN = "{0}?client_id={1}&client_secret={2}&grant_type=authorization_code&code={3}&redirect_uri={4}";
private static final String WEIBO_USER_INFO_PATTERN = "{0}?{1}";
......@@ -35,11 +37,11 @@ public class WeiboUrlBuilder extends AbstractUrlBuilder {
@Override
public String getRefreshUrl(String refreshToken) {
return null;
throw new AuthException(AuthResponseStatus.NOT_IMPLEMENTED);
}
@Override
public String getRevokeUrl(String accessToken) {
return null;
throw new AuthException(AuthResponseStatus.NOT_IMPLEMENTED);
}
}
......@@ -3,7 +3,7 @@ package me.zhyd.oauth.utils;
import me.zhyd.oauth.config.AuthConfig;
import me.zhyd.oauth.config.AuthSource;
import me.zhyd.oauth.exception.AuthException;
import me.zhyd.oauth.request.ResponseStatus;
import me.zhyd.oauth.model.AuthResponseStatus;
/**
* 授权配置类的校验器
......@@ -38,15 +38,15 @@ public class AuthChecker {
public static void checkConfig(AuthConfig config, AuthSource source) {
String redirectUri = config.getRedirectUri();
if (!GlobalAuthUtil.isHttpProtocol(redirectUri) && !GlobalAuthUtil.isHttpsProtocol(redirectUri)) {
throw new AuthException(ResponseStatus.ILLEGAL_REDIRECT_URI);
throw new AuthException(AuthResponseStatus.ILLEGAL_REDIRECT_URI);
}
// facebook的回调地址必须为https的链接
if (AuthSource.FACEBOOK == source && !GlobalAuthUtil.isHttpsProtocol(redirectUri)) {
throw new AuthException(ResponseStatus.ILLEGAL_REDIRECT_URI);
throw new AuthException(AuthResponseStatus.ILLEGAL_REDIRECT_URI);
}
// 支付宝在创建回调地址时,不允许使用localhost或者127.0.0.1
if (AuthSource.ALIPAY == source && GlobalAuthUtil.isLocalHost(redirectUri)) {
throw new AuthException(ResponseStatus.ILLEGAL_REDIRECT_URI);
throw new AuthException(AuthResponseStatus.ILLEGAL_REDIRECT_URI);
}
}
......@@ -57,7 +57,7 @@ public class AuthChecker {
*/
public static void checkCode(String code) {
if (StringUtils.isEmpty(code)) {
throw new AuthException(ResponseStatus.ILLEGAL_CODE);
throw new AuthException(AuthResponseStatus.ILLEGAL_CODE);
}
}
......@@ -74,11 +74,11 @@ public class AuthChecker {
}
// 如果授权之前使用了state,但是回调时未返回state,则表示当前请求为非法的请求,可能正在被CSRF攻击
if (StringUtils.isEmpty(newState)) {
throw new AuthException(ResponseStatus.ILLEGAL_REQUEST);
throw new AuthException(AuthResponseStatus.ILLEGAL_REQUEST);
}
// 如果授权前后的state不一致,则表示当前请求为非法的请求,新的state可能为伪造
if (!newState.equals(originalState)) {
throw new AuthException(ResponseStatus.ILLEGAL_REQUEST);
throw new AuthException(AuthResponseStatus.ILLEGAL_REQUEST);
}
}
}
......@@ -5,7 +5,7 @@ import cn.hutool.core.util.RandomUtil;
import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import me.zhyd.oauth.exception.AuthException;
import me.zhyd.oauth.request.ResponseStatus;
import me.zhyd.oauth.model.AuthResponseStatus;
import java.nio.charset.Charset;
import java.util.concurrent.ConcurrentHashMap;
......@@ -113,7 +113,7 @@ public class AuthState {
String noneSourceState = decodedState.substring(source.length() + 1);
if (!noneSourceState.startsWith(currentIp)) {
// ip不相同,可能为非法的请求
throw new AuthException(ResponseStatus.ILLEGAL_REQUEST);
throw new AuthException(AuthResponseStatus.ILLEGAL_REQUEST);
}
String body = noneSourceState.substring(currentIp.length() + 1);
log.debug("body is [{}]", body);
......
### 2019/07/16
1. 重构UrlBuilder类
2. 将CSDN相关的类置为`Deprecated`,后续可能会删除,也可能一直保留。毕竟CSDN的openAPI已经不对外开放了。
3. `BaseAuthRequest` 改名为 `AuthDefaultRequest`
3. `ResponseStatus` 改名为 `AuthResponseStatus` 并且移动到 `me.zhyd.oauth.model`
### 2019/07/15
1. 新增 `AuthState` 类,内置默认的state生成规则和校验规则
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册