提交 3e8c475d 编写于 作者: 不合群的混子's avatar 不合群的混子

添加 Request 的 AuthStateCache 构造器

上级 c1f9e96a
...@@ -238,13 +238,11 @@ ...@@ -238,13 +238,11 @@
</build> </build>
<distributionManagement> <distributionManagement>
<repository> <repository>
<id>releases</id> <id>xkcoding-nexus</id>
<name>Nexus Release Repository</name>
<url>https://nexus.xkcoding.com/repository/maven-releases/</url> <url>https://nexus.xkcoding.com/repository/maven-releases/</url>
</repository> </repository>
<snapshotRepository> <snapshotRepository>
<id>snapshots</id> <id>xkcoding-nexus</id>
<name>Nexus Snapshot Repository</name>
<url>https://nexus.xkcoding.com/repository/maven-snapshots/</url> <url>https://nexus.xkcoding.com/repository/maven-snapshots/</url>
</snapshotRepository> </snapshotRepository>
</distributionManagement> </distributionManagement>
......
...@@ -7,6 +7,7 @@ import com.alipay.api.request.AlipaySystemOauthTokenRequest; ...@@ -7,6 +7,7 @@ import com.alipay.api.request.AlipaySystemOauthTokenRequest;
import com.alipay.api.request.AlipayUserInfoShareRequest; import com.alipay.api.request.AlipayUserInfoShareRequest;
import com.alipay.api.response.AlipaySystemOauthTokenResponse; import com.alipay.api.response.AlipaySystemOauthTokenResponse;
import com.alipay.api.response.AlipayUserInfoShareResponse; import com.alipay.api.response.AlipayUserInfoShareResponse;
import me.zhyd.oauth.cache.AuthStateCache;
import me.zhyd.oauth.config.AuthConfig; import me.zhyd.oauth.config.AuthConfig;
import me.zhyd.oauth.config.AuthSource; import me.zhyd.oauth.config.AuthSource;
import me.zhyd.oauth.enums.AuthUserGender; import me.zhyd.oauth.enums.AuthUserGender;
...@@ -33,6 +34,12 @@ public class AuthAlipayRequest extends AuthDefaultRequest { ...@@ -33,6 +34,12 @@ public class AuthAlipayRequest extends AuthDefaultRequest {
.getAlipayPublicKey(), "RSA2"); .getAlipayPublicKey(), "RSA2");
} }
public AuthAlipayRequest(AuthConfig config, AuthStateCache authStateCache) {
super(config, AuthSource.ALIPAY, authStateCache);
this.alipayClient = new DefaultAlipayClient(AuthSource.ALIPAY.accessToken(), config.getClientId(), config.getClientSecret(), "json", "UTF-8", config
.getAlipayPublicKey(), "RSA2");
}
@Override @Override
protected AuthToken getAccessToken(AuthCallback authCallback) { protected AuthToken getAccessToken(AuthCallback authCallback) {
AlipaySystemOauthTokenRequest request = new AlipaySystemOauthTokenRequest(); AlipaySystemOauthTokenRequest request = new AlipaySystemOauthTokenRequest();
......
...@@ -3,12 +3,16 @@ package me.zhyd.oauth.request; ...@@ -3,12 +3,16 @@ package me.zhyd.oauth.request;
import cn.hutool.http.HttpRequest; import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse; import cn.hutool.http.HttpResponse;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import me.zhyd.oauth.cache.AuthStateCache;
import me.zhyd.oauth.config.AuthConfig; import me.zhyd.oauth.config.AuthConfig;
import me.zhyd.oauth.config.AuthSource; import me.zhyd.oauth.config.AuthSource;
import me.zhyd.oauth.enums.AuthResponseStatus; import me.zhyd.oauth.enums.AuthResponseStatus;
import me.zhyd.oauth.enums.AuthUserGender; import me.zhyd.oauth.enums.AuthUserGender;
import me.zhyd.oauth.exception.AuthException; import me.zhyd.oauth.exception.AuthException;
import me.zhyd.oauth.model.*; 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.utils.StringUtils; import me.zhyd.oauth.utils.StringUtils;
import me.zhyd.oauth.utils.UrlBuilder; import me.zhyd.oauth.utils.UrlBuilder;
...@@ -24,6 +28,10 @@ public class AuthBaiduRequest extends AuthDefaultRequest { ...@@ -24,6 +28,10 @@ public class AuthBaiduRequest extends AuthDefaultRequest {
super(config, AuthSource.BAIDU); super(config, AuthSource.BAIDU);
} }
public AuthBaiduRequest(AuthConfig config, AuthStateCache authStateCache) {
super(config, AuthSource.BAIDU, authStateCache);
}
@Override @Override
protected AuthToken getAccessToken(AuthCallback authCallback) { protected AuthToken getAccessToken(AuthCallback authCallback) {
HttpResponse response = doPostAuthorizationCode(authCallback.getCode()); HttpResponse response = doPostAuthorizationCode(authCallback.getCode());
......
...@@ -2,6 +2,7 @@ package me.zhyd.oauth.request; ...@@ -2,6 +2,7 @@ package me.zhyd.oauth.request;
import cn.hutool.http.HttpResponse; import cn.hutool.http.HttpResponse;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import me.zhyd.oauth.cache.AuthStateCache;
import me.zhyd.oauth.config.AuthConfig; import me.zhyd.oauth.config.AuthConfig;
import me.zhyd.oauth.config.AuthSource; import me.zhyd.oauth.config.AuthSource;
import me.zhyd.oauth.enums.AuthUserGender; import me.zhyd.oauth.enums.AuthUserGender;
...@@ -23,6 +24,10 @@ public class AuthCodingRequest extends AuthDefaultRequest { ...@@ -23,6 +24,10 @@ public class AuthCodingRequest extends AuthDefaultRequest {
super(config, AuthSource.CODING); super(config, AuthSource.CODING);
} }
public AuthCodingRequest(AuthConfig config, AuthStateCache authStateCache) {
super(config, AuthSource.CODING, authStateCache);
}
@Override @Override
protected AuthToken getAccessToken(AuthCallback authCallback) { protected AuthToken getAccessToken(AuthCallback authCallback) {
HttpResponse response = doGetAuthorizationCode(authCallback.getCode()); HttpResponse response = doGetAuthorizationCode(authCallback.getCode());
......
...@@ -2,6 +2,7 @@ package me.zhyd.oauth.request; ...@@ -2,6 +2,7 @@ package me.zhyd.oauth.request;
import cn.hutool.http.HttpResponse; import cn.hutool.http.HttpResponse;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import me.zhyd.oauth.cache.AuthStateCache;
import me.zhyd.oauth.config.AuthConfig; import me.zhyd.oauth.config.AuthConfig;
import me.zhyd.oauth.config.AuthSource; import me.zhyd.oauth.config.AuthSource;
import me.zhyd.oauth.enums.AuthUserGender; import me.zhyd.oauth.enums.AuthUserGender;
...@@ -23,6 +24,10 @@ public class AuthCsdnRequest extends AuthDefaultRequest { ...@@ -23,6 +24,10 @@ public class AuthCsdnRequest extends AuthDefaultRequest {
super(config, AuthSource.CSDN); super(config, AuthSource.CSDN);
} }
public AuthCsdnRequest(AuthConfig config, AuthStateCache authStateCache) {
super(config, AuthSource.CSDN, authStateCache);
}
@Override @Override
protected AuthToken getAccessToken(AuthCallback authCallback) { protected AuthToken getAccessToken(AuthCallback authCallback) {
HttpResponse response = doPostAuthorizationCode(authCallback.getCode()); HttpResponse response = doPostAuthorizationCode(authCallback.getCode());
......
...@@ -4,6 +4,7 @@ import cn.hutool.http.HttpRequest; ...@@ -4,6 +4,7 @@ import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse; import cn.hutool.http.HttpResponse;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import me.zhyd.oauth.cache.AuthStateCache;
import me.zhyd.oauth.config.AuthConfig; import me.zhyd.oauth.config.AuthConfig;
import me.zhyd.oauth.config.AuthSource; import me.zhyd.oauth.config.AuthSource;
import me.zhyd.oauth.enums.AuthUserGender; import me.zhyd.oauth.enums.AuthUserGender;
...@@ -26,6 +27,10 @@ public class AuthDingTalkRequest extends AuthDefaultRequest { ...@@ -26,6 +27,10 @@ public class AuthDingTalkRequest extends AuthDefaultRequest {
super(config, AuthSource.DINGTALK); super(config, AuthSource.DINGTALK);
} }
public AuthDingTalkRequest(AuthConfig config, AuthStateCache authStateCache) {
super(config, AuthSource.DINGTALK, authStateCache);
}
@Override @Override
protected AuthToken getAccessToken(AuthCallback authCallback) { protected AuthToken getAccessToken(AuthCallback authCallback) {
return AuthToken.builder().accessCode(authCallback.getCode()).build(); return AuthToken.builder().accessCode(authCallback.getCode()).build();
......
...@@ -3,12 +3,16 @@ package me.zhyd.oauth.request; ...@@ -3,12 +3,16 @@ package me.zhyd.oauth.request;
import cn.hutool.http.HttpRequest; import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse; import cn.hutool.http.HttpResponse;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import me.zhyd.oauth.cache.AuthStateCache;
import me.zhyd.oauth.config.AuthConfig; import me.zhyd.oauth.config.AuthConfig;
import me.zhyd.oauth.config.AuthSource; import me.zhyd.oauth.config.AuthSource;
import me.zhyd.oauth.enums.AuthResponseStatus; import me.zhyd.oauth.enums.AuthResponseStatus;
import me.zhyd.oauth.enums.AuthUserGender; import me.zhyd.oauth.enums.AuthUserGender;
import me.zhyd.oauth.exception.AuthException; import me.zhyd.oauth.exception.AuthException;
import me.zhyd.oauth.model.*; 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.utils.UrlBuilder; import me.zhyd.oauth.utils.UrlBuilder;
...@@ -24,6 +28,10 @@ public class AuthDouyinRequest extends AuthDefaultRequest { ...@@ -24,6 +28,10 @@ public class AuthDouyinRequest extends AuthDefaultRequest {
super(config, AuthSource.DOUYIN); super(config, AuthSource.DOUYIN);
} }
public AuthDouyinRequest(AuthConfig config, AuthStateCache authStateCache) {
super(config, AuthSource.DOUYIN, authStateCache);
}
@Override @Override
protected AuthToken getAccessToken(AuthCallback authCallback) { protected AuthToken getAccessToken(AuthCallback authCallback) {
return this.getToken(accessTokenUrl(authCallback.getCode())); return this.getToken(accessTokenUrl(authCallback.getCode()));
......
...@@ -2,6 +2,7 @@ package me.zhyd.oauth.request; ...@@ -2,6 +2,7 @@ package me.zhyd.oauth.request;
import cn.hutool.http.HttpResponse; import cn.hutool.http.HttpResponse;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import me.zhyd.oauth.cache.AuthStateCache;
import me.zhyd.oauth.config.AuthConfig; import me.zhyd.oauth.config.AuthConfig;
import me.zhyd.oauth.config.AuthSource; import me.zhyd.oauth.config.AuthSource;
import me.zhyd.oauth.enums.AuthUserGender; import me.zhyd.oauth.enums.AuthUserGender;
...@@ -23,6 +24,10 @@ public class AuthFacebookRequest extends AuthDefaultRequest { ...@@ -23,6 +24,10 @@ public class AuthFacebookRequest extends AuthDefaultRequest {
super(config, AuthSource.FACEBOOK); super(config, AuthSource.FACEBOOK);
} }
public AuthFacebookRequest(AuthConfig config, AuthStateCache authStateCache) {
super(config, AuthSource.FACEBOOK, authStateCache);
}
@Override @Override
protected AuthToken getAccessToken(AuthCallback authCallback) { protected AuthToken getAccessToken(AuthCallback authCallback) {
HttpResponse response = doPostAuthorizationCode(authCallback.getCode()); HttpResponse response = doPostAuthorizationCode(authCallback.getCode());
......
...@@ -2,6 +2,7 @@ package me.zhyd.oauth.request; ...@@ -2,6 +2,7 @@ package me.zhyd.oauth.request;
import cn.hutool.http.HttpResponse; import cn.hutool.http.HttpResponse;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import me.zhyd.oauth.cache.AuthStateCache;
import me.zhyd.oauth.config.AuthConfig; import me.zhyd.oauth.config.AuthConfig;
import me.zhyd.oauth.config.AuthSource; import me.zhyd.oauth.config.AuthSource;
import me.zhyd.oauth.enums.AuthUserGender; import me.zhyd.oauth.enums.AuthUserGender;
...@@ -22,6 +23,10 @@ public class AuthGiteeRequest extends AuthDefaultRequest { ...@@ -22,6 +23,10 @@ public class AuthGiteeRequest extends AuthDefaultRequest {
super(config, AuthSource.GITEE); super(config, AuthSource.GITEE);
} }
public AuthGiteeRequest(AuthConfig config, AuthStateCache authStateCache) {
super(config, AuthSource.GITEE, authStateCache);
}
@Override @Override
protected AuthToken getAccessToken(AuthCallback authCallback) { protected AuthToken getAccessToken(AuthCallback authCallback) {
HttpResponse response = doPostAuthorizationCode(authCallback.getCode()); HttpResponse response = doPostAuthorizationCode(authCallback.getCode());
......
...@@ -2,6 +2,7 @@ package me.zhyd.oauth.request; ...@@ -2,6 +2,7 @@ package me.zhyd.oauth.request;
import cn.hutool.http.HttpResponse; import cn.hutool.http.HttpResponse;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import me.zhyd.oauth.cache.AuthStateCache;
import me.zhyd.oauth.config.AuthConfig; import me.zhyd.oauth.config.AuthConfig;
import me.zhyd.oauth.config.AuthSource; import me.zhyd.oauth.config.AuthSource;
import me.zhyd.oauth.enums.AuthUserGender; import me.zhyd.oauth.enums.AuthUserGender;
...@@ -25,6 +26,10 @@ public class AuthGithubRequest extends AuthDefaultRequest { ...@@ -25,6 +26,10 @@ public class AuthGithubRequest extends AuthDefaultRequest {
super(config, AuthSource.GITHUB); super(config, AuthSource.GITHUB);
} }
public AuthGithubRequest(AuthConfig config, AuthStateCache authStateCache) {
super(config, AuthSource.GITHUB, authStateCache);
}
@Override @Override
protected AuthToken getAccessToken(AuthCallback authCallback) { protected AuthToken getAccessToken(AuthCallback authCallback) {
HttpResponse response = doPostAuthorizationCode(authCallback.getCode()); HttpResponse response = doPostAuthorizationCode(authCallback.getCode());
......
...@@ -3,6 +3,7 @@ package me.zhyd.oauth.request; ...@@ -3,6 +3,7 @@ package me.zhyd.oauth.request;
import cn.hutool.http.HttpRequest; import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse; import cn.hutool.http.HttpResponse;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import me.zhyd.oauth.cache.AuthStateCache;
import me.zhyd.oauth.config.AuthConfig; import me.zhyd.oauth.config.AuthConfig;
import me.zhyd.oauth.config.AuthSource; import me.zhyd.oauth.config.AuthSource;
import me.zhyd.oauth.enums.AuthUserGender; import me.zhyd.oauth.enums.AuthUserGender;
...@@ -24,6 +25,10 @@ public class AuthGoogleRequest extends AuthDefaultRequest { ...@@ -24,6 +25,10 @@ public class AuthGoogleRequest extends AuthDefaultRequest {
super(config, AuthSource.GOOGLE); super(config, AuthSource.GOOGLE);
} }
public AuthGoogleRequest(AuthConfig config, AuthStateCache authStateCache) {
super(config, AuthSource.GOOGLE, authStateCache);
}
@Override @Override
protected AuthToken getAccessToken(AuthCallback authCallback) { protected AuthToken getAccessToken(AuthCallback authCallback) {
HttpResponse response = doPostAuthorizationCode(authCallback.getCode()); HttpResponse response = doPostAuthorizationCode(authCallback.getCode());
......
...@@ -5,12 +5,16 @@ import cn.hutool.http.HttpResponse; ...@@ -5,12 +5,16 @@ import cn.hutool.http.HttpResponse;
import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.JSONPath; import com.alibaba.fastjson.JSONPath;
import me.zhyd.oauth.cache.AuthStateCache;
import me.zhyd.oauth.config.AuthConfig; import me.zhyd.oauth.config.AuthConfig;
import me.zhyd.oauth.config.AuthSource; import me.zhyd.oauth.config.AuthSource;
import me.zhyd.oauth.enums.AuthResponseStatus; import me.zhyd.oauth.enums.AuthResponseStatus;
import me.zhyd.oauth.enums.AuthUserGender; import me.zhyd.oauth.enums.AuthUserGender;
import me.zhyd.oauth.exception.AuthException; import me.zhyd.oauth.exception.AuthException;
import me.zhyd.oauth.model.*; 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.utils.StringUtils; import me.zhyd.oauth.utils.StringUtils;
import me.zhyd.oauth.utils.UrlBuilder; import me.zhyd.oauth.utils.UrlBuilder;
...@@ -27,6 +31,10 @@ public class AuthLinkedinRequest extends AuthDefaultRequest { ...@@ -27,6 +31,10 @@ public class AuthLinkedinRequest extends AuthDefaultRequest {
super(config, AuthSource.LINKEDIN); super(config, AuthSource.LINKEDIN);
} }
public AuthLinkedinRequest(AuthConfig config, AuthStateCache authStateCache) {
super(config, AuthSource.LINKEDIN, authStateCache);
}
@Override @Override
protected AuthToken getAccessToken(AuthCallback authCallback) { protected AuthToken getAccessToken(AuthCallback authCallback) {
return this.getToken(accessTokenUrl(authCallback.getCode())); return this.getToken(accessTokenUrl(authCallback.getCode()));
......
...@@ -5,12 +5,16 @@ import cn.hutool.http.HttpRequest; ...@@ -5,12 +5,16 @@ import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse; import cn.hutool.http.HttpResponse;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import me.zhyd.oauth.cache.AuthStateCache;
import me.zhyd.oauth.config.AuthConfig; import me.zhyd.oauth.config.AuthConfig;
import me.zhyd.oauth.config.AuthSource; import me.zhyd.oauth.config.AuthSource;
import me.zhyd.oauth.enums.AuthResponseStatus; import me.zhyd.oauth.enums.AuthResponseStatus;
import me.zhyd.oauth.enums.AuthUserGender; import me.zhyd.oauth.enums.AuthUserGender;
import me.zhyd.oauth.exception.AuthException; import me.zhyd.oauth.exception.AuthException;
import me.zhyd.oauth.model.*; 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.utils.UrlBuilder; import me.zhyd.oauth.utils.UrlBuilder;
import java.text.MessageFormat; import java.text.MessageFormat;
...@@ -29,6 +33,10 @@ public class AuthMiRequest extends AuthDefaultRequest { ...@@ -29,6 +33,10 @@ public class AuthMiRequest extends AuthDefaultRequest {
super(config, AuthSource.MI); super(config, AuthSource.MI);
} }
public AuthMiRequest(AuthConfig config, AuthStateCache authStateCache) {
super(config, AuthSource.MI, authStateCache);
}
@Override @Override
protected AuthToken getAccessToken(AuthCallback authCallback) { protected AuthToken getAccessToken(AuthCallback authCallback) {
return getToken(accessTokenUrl(authCallback.getCode())); return getToken(accessTokenUrl(authCallback.getCode()));
......
...@@ -3,12 +3,16 @@ package me.zhyd.oauth.request; ...@@ -3,12 +3,16 @@ package me.zhyd.oauth.request;
import cn.hutool.http.HttpRequest; import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse; import cn.hutool.http.HttpResponse;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import me.zhyd.oauth.cache.AuthStateCache;
import me.zhyd.oauth.config.AuthConfig; import me.zhyd.oauth.config.AuthConfig;
import me.zhyd.oauth.config.AuthSource; import me.zhyd.oauth.config.AuthSource;
import me.zhyd.oauth.enums.AuthResponseStatus; import me.zhyd.oauth.enums.AuthResponseStatus;
import me.zhyd.oauth.enums.AuthUserGender; import me.zhyd.oauth.enums.AuthUserGender;
import me.zhyd.oauth.exception.AuthException; import me.zhyd.oauth.exception.AuthException;
import me.zhyd.oauth.model.*; 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.utils.UrlBuilder; import me.zhyd.oauth.utils.UrlBuilder;
import static me.zhyd.oauth.utils.GlobalAuthUtil.parseQueryToMap; import static me.zhyd.oauth.utils.GlobalAuthUtil.parseQueryToMap;
...@@ -24,6 +28,10 @@ public class AuthMicrosoftRequest extends AuthDefaultRequest { ...@@ -24,6 +28,10 @@ public class AuthMicrosoftRequest extends AuthDefaultRequest {
super(config, AuthSource.MICROSOFT); super(config, AuthSource.MICROSOFT);
} }
public AuthMicrosoftRequest(AuthConfig config, AuthStateCache authStateCache) {
super(config, AuthSource.MICROSOFT, authStateCache);
}
@Override @Override
protected AuthToken getAccessToken(AuthCallback authCallback) { protected AuthToken getAccessToken(AuthCallback authCallback) {
return getToken(accessTokenUrl(authCallback.getCode())); return getToken(accessTokenUrl(authCallback.getCode()));
......
...@@ -2,6 +2,7 @@ package me.zhyd.oauth.request; ...@@ -2,6 +2,7 @@ package me.zhyd.oauth.request;
import cn.hutool.http.HttpResponse; import cn.hutool.http.HttpResponse;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import me.zhyd.oauth.cache.AuthStateCache;
import me.zhyd.oauth.config.AuthConfig; import me.zhyd.oauth.config.AuthConfig;
import me.zhyd.oauth.config.AuthSource; import me.zhyd.oauth.config.AuthSource;
import me.zhyd.oauth.enums.AuthUserGender; import me.zhyd.oauth.enums.AuthUserGender;
...@@ -23,6 +24,10 @@ public class AuthOschinaRequest extends AuthDefaultRequest { ...@@ -23,6 +24,10 @@ public class AuthOschinaRequest extends AuthDefaultRequest {
super(config, AuthSource.OSCHINA); super(config, AuthSource.OSCHINA);
} }
public AuthOschinaRequest(AuthConfig config, AuthStateCache authStateCache) {
super(config, AuthSource.OSCHINA, authStateCache);
}
@Override @Override
protected AuthToken getAccessToken(AuthCallback authCallback) { protected AuthToken getAccessToken(AuthCallback authCallback) {
HttpResponse response = doPostAuthorizationCode(authCallback.getCode()); HttpResponse response = doPostAuthorizationCode(authCallback.getCode());
......
...@@ -3,6 +3,7 @@ package me.zhyd.oauth.request; ...@@ -3,6 +3,7 @@ package me.zhyd.oauth.request;
import cn.hutool.http.HttpRequest; import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse; import cn.hutool.http.HttpResponse;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import me.zhyd.oauth.cache.AuthStateCache;
import me.zhyd.oauth.config.AuthConfig; import me.zhyd.oauth.config.AuthConfig;
import me.zhyd.oauth.enums.AuthUserGender; import me.zhyd.oauth.enums.AuthUserGender;
import me.zhyd.oauth.exception.AuthException; import me.zhyd.oauth.exception.AuthException;
...@@ -29,6 +30,10 @@ public class AuthPinterestRequest extends AuthDefaultRequest { ...@@ -29,6 +30,10 @@ public class AuthPinterestRequest extends AuthDefaultRequest {
super(config, PINTEREST); super(config, PINTEREST);
} }
public AuthPinterestRequest(AuthConfig config, AuthStateCache authStateCache) {
super(config, PINTEREST, authStateCache);
}
@Override @Override
protected AuthToken getAccessToken(AuthCallback authCallback) { protected AuthToken getAccessToken(AuthCallback authCallback) {
HttpResponse response = doPostAuthorizationCode(authCallback.getCode()); HttpResponse response = doPostAuthorizationCode(authCallback.getCode());
......
...@@ -4,12 +4,16 @@ import cn.hutool.core.util.StrUtil; ...@@ -4,12 +4,16 @@ import cn.hutool.core.util.StrUtil;
import cn.hutool.http.HttpRequest; import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse; import cn.hutool.http.HttpResponse;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import me.zhyd.oauth.cache.AuthStateCache;
import me.zhyd.oauth.config.AuthConfig; import me.zhyd.oauth.config.AuthConfig;
import me.zhyd.oauth.config.AuthSource; import me.zhyd.oauth.config.AuthSource;
import me.zhyd.oauth.enums.AuthResponseStatus; import me.zhyd.oauth.enums.AuthResponseStatus;
import me.zhyd.oauth.enums.AuthUserGender; import me.zhyd.oauth.enums.AuthUserGender;
import me.zhyd.oauth.exception.AuthException; import me.zhyd.oauth.exception.AuthException;
import me.zhyd.oauth.model.*; 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.utils.GlobalAuthUtil; import me.zhyd.oauth.utils.GlobalAuthUtil;
import me.zhyd.oauth.utils.StringUtils; import me.zhyd.oauth.utils.StringUtils;
import me.zhyd.oauth.utils.UrlBuilder; import me.zhyd.oauth.utils.UrlBuilder;
...@@ -28,6 +32,10 @@ public class AuthQqRequest extends AuthDefaultRequest { ...@@ -28,6 +32,10 @@ public class AuthQqRequest extends AuthDefaultRequest {
super(config, AuthSource.QQ); super(config, AuthSource.QQ);
} }
public AuthQqRequest(AuthConfig config, AuthStateCache authStateCache) {
super(config, AuthSource.QQ, authStateCache);
}
@Override @Override
protected AuthToken getAccessToken(AuthCallback authCallback) { protected AuthToken getAccessToken(AuthCallback authCallback) {
HttpResponse response = doGetAuthorizationCode(authCallback.getCode()); HttpResponse response = doGetAuthorizationCode(authCallback.getCode());
...@@ -37,10 +45,7 @@ public class AuthQqRequest extends AuthDefaultRequest { ...@@ -37,10 +45,7 @@ public class AuthQqRequest extends AuthDefaultRequest {
@Override @Override
public AuthResponse refresh(AuthToken authToken) { public AuthResponse refresh(AuthToken authToken) {
HttpResponse response = HttpRequest.get(refreshTokenUrl(authToken.getRefreshToken())).execute(); HttpResponse response = HttpRequest.get(refreshTokenUrl(authToken.getRefreshToken())).execute();
return AuthResponse.builder() return AuthResponse.builder().code(AuthResponseStatus.SUCCESS.getCode()).data(getAuthToken(response)).build();
.code(AuthResponseStatus.SUCCESS.getCode())
.data(getAuthToken(response))
.build();
} }
@Override @Override
......
...@@ -4,10 +4,14 @@ import cn.hutool.http.HttpRequest; ...@@ -4,10 +4,14 @@ import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse; import cn.hutool.http.HttpResponse;
import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import me.zhyd.oauth.cache.AuthStateCache;
import me.zhyd.oauth.config.AuthConfig; import me.zhyd.oauth.config.AuthConfig;
import me.zhyd.oauth.enums.AuthUserGender; import me.zhyd.oauth.enums.AuthUserGender;
import me.zhyd.oauth.exception.AuthException; import me.zhyd.oauth.exception.AuthException;
import me.zhyd.oauth.model.*; 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.utils.UrlBuilder; import me.zhyd.oauth.utils.UrlBuilder;
import java.util.Objects; import java.util.Objects;
...@@ -27,6 +31,10 @@ public class AuthRenrenRequest extends AuthDefaultRequest { ...@@ -27,6 +31,10 @@ public class AuthRenrenRequest extends AuthDefaultRequest {
super(config, RENREN); super(config, RENREN);
} }
public AuthRenrenRequest(AuthConfig config, AuthStateCache authStateCache) {
super(config, RENREN, authStateCache);
}
@Override @Override
protected AuthToken getAccessToken(AuthCallback authCallback) { protected AuthToken getAccessToken(AuthCallback authCallback) {
return this.getToken(accessTokenUrl(authCallback.getCode())); return this.getToken(accessTokenUrl(authCallback.getCode()));
......
...@@ -3,6 +3,7 @@ package me.zhyd.oauth.request; ...@@ -3,6 +3,7 @@ package me.zhyd.oauth.request;
import cn.hutool.http.HttpRequest; import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse; import cn.hutool.http.HttpResponse;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import me.zhyd.oauth.cache.AuthStateCache;
import me.zhyd.oauth.config.AuthConfig; import me.zhyd.oauth.config.AuthConfig;
import me.zhyd.oauth.enums.AuthUserGender; import me.zhyd.oauth.enums.AuthUserGender;
import me.zhyd.oauth.exception.AuthException; import me.zhyd.oauth.exception.AuthException;
...@@ -26,6 +27,10 @@ public class AuthStackOverflowRequest extends AuthDefaultRequest { ...@@ -26,6 +27,10 @@ public class AuthStackOverflowRequest extends AuthDefaultRequest {
super(config, STACK_OVERFLOW); super(config, STACK_OVERFLOW);
} }
public AuthStackOverflowRequest(AuthConfig config, AuthStateCache authStateCache) {
super(config, STACK_OVERFLOW, authStateCache);
}
@Override @Override
protected AuthToken getAccessToken(AuthCallback authCallback) { protected AuthToken getAccessToken(AuthCallback authCallback) {
String accessTokenUrl = accessTokenUrl(authCallback.getCode()); String accessTokenUrl = accessTokenUrl(authCallback.getCode());
......
...@@ -2,6 +2,7 @@ package me.zhyd.oauth.request; ...@@ -2,6 +2,7 @@ package me.zhyd.oauth.request;
import cn.hutool.http.HttpResponse; import cn.hutool.http.HttpResponse;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import me.zhyd.oauth.cache.AuthStateCache;
import me.zhyd.oauth.config.AuthConfig; import me.zhyd.oauth.config.AuthConfig;
import me.zhyd.oauth.config.AuthSource; import me.zhyd.oauth.config.AuthSource;
import me.zhyd.oauth.enums.AuthUserGender; import me.zhyd.oauth.enums.AuthUserGender;
...@@ -24,6 +25,10 @@ public class AuthTaobaoRequest extends AuthDefaultRequest { ...@@ -24,6 +25,10 @@ public class AuthTaobaoRequest extends AuthDefaultRequest {
super(config, AuthSource.TAOBAO); super(config, AuthSource.TAOBAO);
} }
public AuthTaobaoRequest(AuthConfig config, AuthStateCache authStateCache) {
super(config, AuthSource.TAOBAO, authStateCache);
}
@Override @Override
protected AuthToken getAccessToken(AuthCallback authCallback) { protected AuthToken getAccessToken(AuthCallback authCallback) {
return AuthToken.builder().accessCode(authCallback.getCode()).build(); return AuthToken.builder().accessCode(authCallback.getCode()).build();
......
...@@ -3,12 +3,16 @@ package me.zhyd.oauth.request; ...@@ -3,12 +3,16 @@ package me.zhyd.oauth.request;
import cn.hutool.http.HttpRequest; import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse; import cn.hutool.http.HttpResponse;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import me.zhyd.oauth.cache.AuthStateCache;
import me.zhyd.oauth.config.AuthConfig; import me.zhyd.oauth.config.AuthConfig;
import me.zhyd.oauth.config.AuthSource; import me.zhyd.oauth.config.AuthSource;
import me.zhyd.oauth.enums.AuthResponseStatus; import me.zhyd.oauth.enums.AuthResponseStatus;
import me.zhyd.oauth.enums.AuthUserGender; import me.zhyd.oauth.enums.AuthUserGender;
import me.zhyd.oauth.exception.AuthException; import me.zhyd.oauth.exception.AuthException;
import me.zhyd.oauth.model.*; import me.zhyd.oauth.model.AuthCallback;
import me.zhyd.oauth.model.AuthResponse;
import me.zhyd.oauth.model.AuthToken;
import me.zhyd.oauth.model.AuthUser;
/** /**
* Teambition授权登录 * Teambition授权登录
...@@ -22,6 +26,10 @@ public class AuthTeambitionRequest extends AuthDefaultRequest { ...@@ -22,6 +26,10 @@ public class AuthTeambitionRequest extends AuthDefaultRequest {
super(config, AuthSource.TEAMBITION); super(config, AuthSource.TEAMBITION);
} }
public AuthTeambitionRequest(AuthConfig config, AuthStateCache authStateCache) {
super(config, AuthSource.TEAMBITION, authStateCache);
}
/** /**
* @param authCallback 回调返回的参数 * @param authCallback 回调返回的参数
* @return 所有信息 * @return 所有信息
......
...@@ -2,6 +2,7 @@ package me.zhyd.oauth.request; ...@@ -2,6 +2,7 @@ package me.zhyd.oauth.request;
import cn.hutool.http.HttpResponse; import cn.hutool.http.HttpResponse;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import me.zhyd.oauth.cache.AuthStateCache;
import me.zhyd.oauth.config.AuthConfig; import me.zhyd.oauth.config.AuthConfig;
import me.zhyd.oauth.config.AuthSource; import me.zhyd.oauth.config.AuthSource;
import me.zhyd.oauth.enums.AuthUserGender; import me.zhyd.oauth.enums.AuthUserGender;
...@@ -23,6 +24,10 @@ public class AuthTencentCloudRequest extends AuthDefaultRequest { ...@@ -23,6 +24,10 @@ public class AuthTencentCloudRequest extends AuthDefaultRequest {
super(config, AuthSource.TENCENT_CLOUD); super(config, AuthSource.TENCENT_CLOUD);
} }
public AuthTencentCloudRequest(AuthConfig config, AuthStateCache authStateCache) {
super(config, AuthSource.TENCENT_CLOUD, authStateCache);
}
@Override @Override
protected AuthToken getAccessToken(AuthCallback authCallback) { protected AuthToken getAccessToken(AuthCallback authCallback) {
HttpResponse response = doGetAuthorizationCode(authCallback.getCode()); HttpResponse response = doGetAuthorizationCode(authCallback.getCode());
......
...@@ -2,6 +2,7 @@ package me.zhyd.oauth.request; ...@@ -2,6 +2,7 @@ package me.zhyd.oauth.request;
import cn.hutool.http.HttpResponse; import cn.hutool.http.HttpResponse;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import me.zhyd.oauth.cache.AuthStateCache;
import me.zhyd.oauth.config.AuthConfig; import me.zhyd.oauth.config.AuthConfig;
import me.zhyd.oauth.config.AuthSource; import me.zhyd.oauth.config.AuthSource;
import me.zhyd.oauth.enums.AuthToutiaoErrorCode; import me.zhyd.oauth.enums.AuthToutiaoErrorCode;
...@@ -24,6 +25,10 @@ public class AuthToutiaoRequest extends AuthDefaultRequest { ...@@ -24,6 +25,10 @@ public class AuthToutiaoRequest extends AuthDefaultRequest {
super(config, AuthSource.TOUTIAO); super(config, AuthSource.TOUTIAO);
} }
public AuthToutiaoRequest(AuthConfig config, AuthStateCache authStateCache) {
super(config, AuthSource.TOUTIAO, authStateCache);
}
@Override @Override
protected AuthToken getAccessToken(AuthCallback authCallback) { protected AuthToken getAccessToken(AuthCallback authCallback) {
HttpResponse response = doGetAuthorizationCode(authCallback.getCode()); HttpResponse response = doGetAuthorizationCode(authCallback.getCode());
...@@ -119,8 +124,7 @@ public class AuthToutiaoRequest extends AuthDefaultRequest { ...@@ -119,8 +124,7 @@ public class AuthToutiaoRequest extends AuthDefaultRequest {
*/ */
private void checkResponse(JSONObject object) { private void checkResponse(JSONObject object) {
if (object.containsKey("error_code")) { if (object.containsKey("error_code")) {
throw new AuthException(AuthToutiaoErrorCode.getErrorCode(object.getIntValue("error_code")) throw new AuthException(AuthToutiaoErrorCode.getErrorCode(object.getIntValue("error_code")).getDesc());
.getDesc());
} }
} }
} }
...@@ -3,12 +3,16 @@ package me.zhyd.oauth.request; ...@@ -3,12 +3,16 @@ package me.zhyd.oauth.request;
import cn.hutool.http.HttpRequest; import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse; import cn.hutool.http.HttpResponse;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import me.zhyd.oauth.cache.AuthStateCache;
import me.zhyd.oauth.config.AuthConfig; import me.zhyd.oauth.config.AuthConfig;
import me.zhyd.oauth.config.AuthSource; import me.zhyd.oauth.config.AuthSource;
import me.zhyd.oauth.enums.AuthResponseStatus; import me.zhyd.oauth.enums.AuthResponseStatus;
import me.zhyd.oauth.enums.AuthUserGender; import me.zhyd.oauth.enums.AuthUserGender;
import me.zhyd.oauth.exception.AuthException; import me.zhyd.oauth.exception.AuthException;
import me.zhyd.oauth.model.*; 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.utils.UrlBuilder; import me.zhyd.oauth.utils.UrlBuilder;
/** /**
...@@ -22,6 +26,10 @@ public class AuthWeChatRequest extends AuthDefaultRequest { ...@@ -22,6 +26,10 @@ public class AuthWeChatRequest extends AuthDefaultRequest {
super(config, AuthSource.WECHAT); super(config, AuthSource.WECHAT);
} }
public AuthWeChatRequest(AuthConfig config, AuthStateCache authStateCache) {
super(config, AuthSource.WECHAT, authStateCache);
}
/** /**
* 微信的特殊性,此时返回的信息同时包含 openid 和 access_token * 微信的特殊性,此时返回的信息同时包含 openid 和 access_token
* *
......
...@@ -3,6 +3,7 @@ package me.zhyd.oauth.request; ...@@ -3,6 +3,7 @@ package me.zhyd.oauth.request;
import cn.hutool.http.HttpRequest; import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse; import cn.hutool.http.HttpResponse;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import me.zhyd.oauth.cache.AuthStateCache;
import me.zhyd.oauth.config.AuthConfig; import me.zhyd.oauth.config.AuthConfig;
import me.zhyd.oauth.config.AuthSource; import me.zhyd.oauth.config.AuthSource;
import me.zhyd.oauth.enums.AuthUserGender; import me.zhyd.oauth.enums.AuthUserGender;
...@@ -27,6 +28,10 @@ public class AuthWeiboRequest extends AuthDefaultRequest { ...@@ -27,6 +28,10 @@ public class AuthWeiboRequest extends AuthDefaultRequest {
super(config, AuthSource.WEIBO); super(config, AuthSource.WEIBO);
} }
public AuthWeiboRequest(AuthConfig config, AuthStateCache authStateCache) {
super(config, AuthSource.WEIBO, authStateCache);
}
@Override @Override
protected AuthToken getAccessToken(AuthCallback authCallback) { protected AuthToken getAccessToken(AuthCallback authCallback) {
HttpResponse response = doPostAuthorizationCode(authCallback.getCode()); HttpResponse response = doPostAuthorizationCode(authCallback.getCode());
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册