提交 7cdc7191 编写于 作者: cly_0's avatar cly_0

继续进行优化,去掉多余的改动

上级 5073f828
...@@ -17,7 +17,7 @@ public enum AuthDefaultSource implements AuthSource { ...@@ -17,7 +17,7 @@ public enum AuthDefaultSource implements AuthSource {
/** /**
* Github * Github
*/ */
GITHUB { GITHUB(AuthGithubRequest.class) {
@Override @Override
public String authorize() { public String authorize() {
return "https://github.com/login/oauth/authorize"; return "https://github.com/login/oauth/authorize";
...@@ -32,21 +32,11 @@ public enum AuthDefaultSource implements AuthSource { ...@@ -32,21 +32,11 @@ public enum AuthDefaultSource implements AuthSource {
public String userInfo() { public String userInfo() {
return "https://api.github.com/user"; return "https://api.github.com/user";
} }
@Override
public AuthRequest getAuthRequestInstance(AuthConfig authConfig) {
return getAuthRequestInstance(authConfig,null);
}
@Override
public AuthRequest getAuthRequestInstance(AuthConfig authConfig, AuthStateCache authStateCache) {
return getInstance(AuthGithubRequest.class,authConfig,authStateCache);
}
}, },
/** /**
* 新浪微博 * 新浪微博
*/ */
WEIBO { WEIBO(AuthWeiboRequest.class) {
@Override @Override
public String authorize() { public String authorize() {
return "https://api.weibo.com/oauth2/authorize"; return "https://api.weibo.com/oauth2/authorize";
...@@ -62,16 +52,6 @@ public enum AuthDefaultSource implements AuthSource { ...@@ -62,16 +52,6 @@ public enum AuthDefaultSource implements AuthSource {
return "https://api.weibo.com/2/users/show.json"; return "https://api.weibo.com/2/users/show.json";
} }
@Override
public AuthRequest getAuthRequestInstance(AuthConfig authConfig) {
return getAuthRequestInstance(authConfig,null);
}
@Override
public AuthRequest getAuthRequestInstance(AuthConfig authConfig, AuthStateCache authStateCache) {
return getInstance(AuthWeiboRequest.class,authConfig,authStateCache);
}
@Override @Override
public String revoke() { public String revoke() {
return "https://api.weibo.com/oauth2/revokeoauth2"; return "https://api.weibo.com/oauth2/revokeoauth2";
...@@ -80,7 +60,7 @@ public enum AuthDefaultSource implements AuthSource { ...@@ -80,7 +60,7 @@ public enum AuthDefaultSource implements AuthSource {
/** /**
* gitee * gitee
*/ */
GITEE { GITEE(AuthGiteeRequest.class) {
@Override @Override
public String authorize() { public String authorize() {
return "https://gitee.com/oauth/authorize"; return "https://gitee.com/oauth/authorize";
...@@ -95,21 +75,11 @@ public enum AuthDefaultSource implements AuthSource { ...@@ -95,21 +75,11 @@ public enum AuthDefaultSource implements AuthSource {
public String userInfo() { public String userInfo() {
return "https://gitee.com/api/v5/user"; return "https://gitee.com/api/v5/user";
} }
@Override
public AuthRequest getAuthRequestInstance(AuthConfig authConfig) {
return getAuthRequestInstance(authConfig,null);
}
@Override
public AuthRequest getAuthRequestInstance(AuthConfig authConfig, AuthStateCache authStateCache) {
return getInstance(AuthGiteeRequest.class,authConfig,authStateCache);
}
}, },
/** /**
* 钉钉扫码登录 * 钉钉扫码登录
*/ */
DINGTALK { DINGTALK(AuthDingTalkRequest.class) {
@Override @Override
public String authorize() { public String authorize() {
return "https://oapi.dingtalk.com/connect/qrconnect"; return "https://oapi.dingtalk.com/connect/qrconnect";
...@@ -124,21 +94,11 @@ public enum AuthDefaultSource implements AuthSource { ...@@ -124,21 +94,11 @@ public enum AuthDefaultSource implements AuthSource {
public String userInfo() { public String userInfo() {
return "https://oapi.dingtalk.com/sns/getuserinfo_bycode"; return "https://oapi.dingtalk.com/sns/getuserinfo_bycode";
} }
@Override
public AuthRequest getAuthRequestInstance(AuthConfig authConfig) {
return getAuthRequestInstance(authConfig,null);
}
@Override
public AuthRequest getAuthRequestInstance(AuthConfig authConfig, AuthStateCache authStateCache) {
return getInstance(AuthDingTalkRequest.class,authConfig,authStateCache);
}
}, },
/** /**
* 钉钉账号登录 * 钉钉账号登录
*/ */
DINGTALK_ACCOUNT { DINGTALK_ACCOUNT(AuthDingTalkAccountRequest.class) {
@Override @Override
public String authorize() { public String authorize() {
return "https://oapi.dingtalk.com/connect/oauth2/sns_authorize"; return "https://oapi.dingtalk.com/connect/oauth2/sns_authorize";
...@@ -153,21 +113,11 @@ public enum AuthDefaultSource implements AuthSource { ...@@ -153,21 +113,11 @@ public enum AuthDefaultSource implements AuthSource {
public String userInfo() { public String userInfo() {
return DINGTALK.userInfo(); return DINGTALK.userInfo();
} }
@Override
public AuthRequest getAuthRequestInstance(AuthConfig authConfig) {
return getAuthRequestInstance(authConfig,null);
}
@Override
public AuthRequest getAuthRequestInstance(AuthConfig authConfig, AuthStateCache authStateCache) {
return getInstance(AuthDingTalkAccountRequest.class,authConfig,authStateCache);
}
}, },
/** /**
* 百度 * 百度
*/ */
BAIDU { BAIDU(AuthBaiduRequest.class) {
@Override @Override
public String authorize() { public String authorize() {
return "https://openapi.baidu.com/oauth/2.0/authorize"; return "https://openapi.baidu.com/oauth/2.0/authorize";
...@@ -192,21 +142,11 @@ public enum AuthDefaultSource implements AuthSource { ...@@ -192,21 +142,11 @@ public enum AuthDefaultSource implements AuthSource {
public String refresh() { public String refresh() {
return "https://openapi.baidu.com/oauth/2.0/token"; return "https://openapi.baidu.com/oauth/2.0/token";
} }
@Override
public AuthRequest getAuthRequestInstance(AuthConfig authConfig) {
return getAuthRequestInstance(authConfig,null);
}
@Override
public AuthRequest getAuthRequestInstance(AuthConfig authConfig, AuthStateCache authStateCache) {
return getInstance(AuthBaiduRequest.class,authConfig,authStateCache);
}
}, },
/** /**
* csdn * csdn
*/ */
CSDN { CSDN(AuthCsdnRequest.class) {
@Override @Override
public String authorize() { public String authorize() {
return "https://api.csdn.net/oauth2/authorize"; return "https://api.csdn.net/oauth2/authorize";
...@@ -221,16 +161,6 @@ public enum AuthDefaultSource implements AuthSource { ...@@ -221,16 +161,6 @@ public enum AuthDefaultSource implements AuthSource {
public String userInfo() { public String userInfo() {
return "https://api.csdn.net/user/getinfo"; return "https://api.csdn.net/user/getinfo";
} }
@Override
public AuthRequest getAuthRequestInstance(AuthConfig authConfig) {
return getAuthRequestInstance(authConfig,null);
}
@Override
public AuthRequest getAuthRequestInstance(AuthConfig authConfig, AuthStateCache authStateCache) {
return getInstance(AuthCsdnRequest.class,authConfig,authStateCache);
}
}, },
/** /**
* Coding, * Coding,
...@@ -238,7 +168,7 @@ public enum AuthDefaultSource implements AuthSource { ...@@ -238,7 +168,7 @@ public enum AuthDefaultSource implements AuthSource {
* 参考 https://help.coding.net/docs/project/open/oauth.html#%E7%94%A8%E6%88%B7%E6%8E%88%E6%9D%83 中的说明, * 参考 https://help.coding.net/docs/project/open/oauth.html#%E7%94%A8%E6%88%B7%E6%8E%88%E6%9D%83 中的说明,
* 新版的 coding API 地址需要传入用户团队名,这儿使用动态参数,方便在 request 中使用 * 新版的 coding API 地址需要传入用户团队名,这儿使用动态参数,方便在 request 中使用
*/ */
CODING { CODING(AuthCodingRequest.class) {
@Override @Override
public String authorize() { public String authorize() {
return "https://%s.coding.net/oauth_authorize.html"; return "https://%s.coding.net/oauth_authorize.html";
...@@ -253,21 +183,11 @@ public enum AuthDefaultSource implements AuthSource { ...@@ -253,21 +183,11 @@ public enum AuthDefaultSource implements AuthSource {
public String userInfo() { public String userInfo() {
return "https://%s.coding.net/api/account/current_user"; return "https://%s.coding.net/api/account/current_user";
} }
@Override
public AuthRequest getAuthRequestInstance(AuthConfig authConfig) {
return getAuthRequestInstance(authConfig,null);
}
@Override
public AuthRequest getAuthRequestInstance(AuthConfig authConfig, AuthStateCache authStateCache) {
return getInstance(AuthCodingRequest.class,authConfig,authStateCache);
}
}, },
/** /**
* oschina 开源中国 * oschina 开源中国
*/ */
OSCHINA { OSCHINA(AuthOschinaRequest.class) {
@Override @Override
public String authorize() { public String authorize() {
return "https://www.oschina.net/action/oauth2/authorize"; return "https://www.oschina.net/action/oauth2/authorize";
...@@ -282,21 +202,11 @@ public enum AuthDefaultSource implements AuthSource { ...@@ -282,21 +202,11 @@ public enum AuthDefaultSource implements AuthSource {
public String userInfo() { public String userInfo() {
return "https://www.oschina.net/action/openapi/user"; return "https://www.oschina.net/action/openapi/user";
} }
@Override
public AuthRequest getAuthRequestInstance(AuthConfig authConfig) {
return getAuthRequestInstance(authConfig,null);
}
@Override
public AuthRequest getAuthRequestInstance(AuthConfig authConfig, AuthStateCache authStateCache) {
return getInstance(AuthOschinaRequest.class,authConfig,authStateCache);
}
}, },
/** /**
* 支付宝 * 支付宝
*/ */
ALIPAY { ALIPAY(AuthAlipayRequest.class) {
@Override @Override
public String authorize() { public String authorize() {
return "https://openauth.alipay.com/oauth2/publicAppAuthorize.htm"; return "https://openauth.alipay.com/oauth2/publicAppAuthorize.htm";
...@@ -311,21 +221,11 @@ public enum AuthDefaultSource implements AuthSource { ...@@ -311,21 +221,11 @@ public enum AuthDefaultSource implements AuthSource {
public String userInfo() { public String userInfo() {
return "https://openapi.alipay.com/gateway.do"; return "https://openapi.alipay.com/gateway.do";
} }
@Override
public AuthRequest getAuthRequestInstance(AuthConfig authConfig) {
return getAuthRequestInstance(authConfig,null);
}
@Override
public AuthRequest getAuthRequestInstance(AuthConfig authConfig, AuthStateCache authStateCache) {
return getInstance(AuthAlipayRequest.class,authConfig,authStateCache);
}
}, },
/** /**
* QQ * QQ
*/ */
QQ { QQ(AuthQqRequest.class) {
@Override @Override
public String authorize() { public String authorize() {
return "https://graph.qq.com/oauth2.0/authorize"; return "https://graph.qq.com/oauth2.0/authorize";
...@@ -345,21 +245,11 @@ public enum AuthDefaultSource implements AuthSource { ...@@ -345,21 +245,11 @@ public enum AuthDefaultSource implements AuthSource {
public String refresh() { public String refresh() {
return "https://graph.qq.com/oauth2.0/token"; return "https://graph.qq.com/oauth2.0/token";
} }
@Override
public AuthRequest getAuthRequestInstance(AuthConfig authConfig) {
return getAuthRequestInstance(authConfig,null);
}
@Override
public AuthRequest getAuthRequestInstance(AuthConfig authConfig, AuthStateCache authStateCache) {
return getInstance(AuthQqRequest.class,authConfig,authStateCache);
}
}, },
/** /**
* 微信开放平台 * 微信开放平台
*/ */
WECHAT_OPEN { WECHAT_OPEN(AuthWeChatOpenRequest.class) {
@Override @Override
public String authorize() { public String authorize() {
return "https://open.weixin.qq.com/connect/qrconnect"; return "https://open.weixin.qq.com/connect/qrconnect";
...@@ -379,21 +269,11 @@ public enum AuthDefaultSource implements AuthSource { ...@@ -379,21 +269,11 @@ public enum AuthDefaultSource implements AuthSource {
public String refresh() { public String refresh() {
return "https://api.weixin.qq.com/sns/oauth2/refresh_token"; return "https://api.weixin.qq.com/sns/oauth2/refresh_token";
} }
@Override
public AuthRequest getAuthRequestInstance(AuthConfig authConfig) {
return getAuthRequestInstance(authConfig,null);
}
@Override
public AuthRequest getAuthRequestInstance(AuthConfig authConfig, AuthStateCache authStateCache) {
return getInstance(AuthWeChatOpenRequest.class,authConfig,authStateCache);
}
}, },
/** /**
* 微信公众平台 * 微信公众平台
*/ */
WECHAT_MP { WECHAT_MP(AuthWeChatMpRequest.class) {
@Override @Override
public String authorize() { public String authorize() {
return "https://open.weixin.qq.com/connect/oauth2/authorize"; return "https://open.weixin.qq.com/connect/oauth2/authorize";
...@@ -413,21 +293,11 @@ public enum AuthDefaultSource implements AuthSource { ...@@ -413,21 +293,11 @@ public enum AuthDefaultSource implements AuthSource {
public String refresh() { public String refresh() {
return "https://api.weixin.qq.com/sns/oauth2/refresh_token"; return "https://api.weixin.qq.com/sns/oauth2/refresh_token";
} }
@Override
public AuthRequest getAuthRequestInstance(AuthConfig authConfig) {
return getAuthRequestInstance(authConfig,null);
}
@Override
public AuthRequest getAuthRequestInstance(AuthConfig authConfig, AuthStateCache authStateCache) {
return getInstance(AuthWeChatMpRequest.class,authConfig,authStateCache);
}
}, },
/** /**
* 淘宝 * 淘宝
*/ */
TAOBAO { TAOBAO(AuthTaobaoRequest.class) {
@Override @Override
public String authorize() { public String authorize() {
return "https://oauth.taobao.com/authorize"; return "https://oauth.taobao.com/authorize";
...@@ -442,21 +312,11 @@ public enum AuthDefaultSource implements AuthSource { ...@@ -442,21 +312,11 @@ public enum AuthDefaultSource implements AuthSource {
public String userInfo() { public String userInfo() {
throw new AuthException(AuthResponseStatus.UNSUPPORTED); throw new AuthException(AuthResponseStatus.UNSUPPORTED);
} }
@Override
public AuthRequest getAuthRequestInstance(AuthConfig authConfig) {
return getAuthRequestInstance(authConfig,null);
}
@Override
public AuthRequest getAuthRequestInstance(AuthConfig authConfig, AuthStateCache authStateCache) {
return getInstance(AuthTaobaoRequest.class,authConfig,authStateCache);
}
}, },
/** /**
* Google * Google
*/ */
GOOGLE { GOOGLE(AuthGoogleRequest.class) {
@Override @Override
public String authorize() { public String authorize() {
return "https://accounts.google.com/o/oauth2/v2/auth"; return "https://accounts.google.com/o/oauth2/v2/auth";
...@@ -471,21 +331,11 @@ public enum AuthDefaultSource implements AuthSource { ...@@ -471,21 +331,11 @@ public enum AuthDefaultSource implements AuthSource {
public String userInfo() { public String userInfo() {
return "https://www.googleapis.com/oauth2/v3/userinfo"; return "https://www.googleapis.com/oauth2/v3/userinfo";
} }
@Override
public AuthRequest getAuthRequestInstance(AuthConfig authConfig) {
return getAuthRequestInstance(authConfig,null);
}
@Override
public AuthRequest getAuthRequestInstance(AuthConfig authConfig, AuthStateCache authStateCache) {
return getInstance(AuthGoogleRequest.class,authConfig,authStateCache);
}
}, },
/** /**
* Facebook * Facebook
*/ */
FACEBOOK { FACEBOOK(AuthFacebookRequest.class) {
@Override @Override
public String authorize() { public String authorize() {
return "https://www.facebook.com/v10.0/dialog/oauth"; return "https://www.facebook.com/v10.0/dialog/oauth";
...@@ -500,21 +350,11 @@ public enum AuthDefaultSource implements AuthSource { ...@@ -500,21 +350,11 @@ public enum AuthDefaultSource implements AuthSource {
public String userInfo() { public String userInfo() {
return "https://graph.facebook.com/v10.0/me"; return "https://graph.facebook.com/v10.0/me";
} }
@Override
public AuthRequest getAuthRequestInstance(AuthConfig authConfig) {
return getAuthRequestInstance(authConfig,null);
}
@Override
public AuthRequest getAuthRequestInstance(AuthConfig authConfig, AuthStateCache authStateCache) {
return getInstance(AuthFacebookRequest.class,authConfig,authStateCache);
}
}, },
/** /**
* 抖音 * 抖音
*/ */
DOUYIN { DOUYIN(AuthDouyinRequest.class) {
@Override @Override
public String authorize() { public String authorize() {
return "https://open.douyin.com/platform/oauth/connect"; return "https://open.douyin.com/platform/oauth/connect";
...@@ -534,21 +374,11 @@ public enum AuthDefaultSource implements AuthSource { ...@@ -534,21 +374,11 @@ public enum AuthDefaultSource implements AuthSource {
public String refresh() { public String refresh() {
return "https://open.douyin.com/oauth/refresh_token/"; return "https://open.douyin.com/oauth/refresh_token/";
} }
@Override
public AuthRequest getAuthRequestInstance(AuthConfig authConfig) {
return getAuthRequestInstance(authConfig,null);
}
@Override
public AuthRequest getAuthRequestInstance(AuthConfig authConfig, AuthStateCache authStateCache) {
return getInstance(AuthDouyinRequest.class,authConfig,authStateCache);
}
}, },
/** /**
* 领英 * 领英
*/ */
LINKEDIN { LINKEDIN(AuthLinkedinRequest.class) {
@Override @Override
public String authorize() { public String authorize() {
return "https://www.linkedin.com/oauth/v2/authorization"; return "https://www.linkedin.com/oauth/v2/authorization";
...@@ -568,21 +398,11 @@ public enum AuthDefaultSource implements AuthSource { ...@@ -568,21 +398,11 @@ public enum AuthDefaultSource implements AuthSource {
public String refresh() { public String refresh() {
return "https://www.linkedin.com/oauth/v2/accessToken"; return "https://www.linkedin.com/oauth/v2/accessToken";
} }
@Override
public AuthRequest getAuthRequestInstance(AuthConfig authConfig) {
return getAuthRequestInstance(authConfig,null);
}
@Override
public AuthRequest getAuthRequestInstance(AuthConfig authConfig, AuthStateCache authStateCache) {
return getInstance(AuthLinkedinRequest.class,authConfig,authStateCache);
}
}, },
/** /**
* 微软 * 微软
*/ */
MICROSOFT { MICROSOFT(AuthMicrosoftRequest.class) {
@Override @Override
public String authorize() { public String authorize() {
return "https://login.microsoftonline.com/common/oauth2/v2.0/authorize"; return "https://login.microsoftonline.com/common/oauth2/v2.0/authorize";
...@@ -602,21 +422,11 @@ public enum AuthDefaultSource implements AuthSource { ...@@ -602,21 +422,11 @@ public enum AuthDefaultSource implements AuthSource {
public String refresh() { public String refresh() {
return "https://login.microsoftonline.com/common/oauth2/v2.0/token"; return "https://login.microsoftonline.com/common/oauth2/v2.0/token";
} }
@Override
public AuthRequest getAuthRequestInstance(AuthConfig authConfig) {
return getAuthRequestInstance(authConfig,null);
}
@Override
public AuthRequest getAuthRequestInstance(AuthConfig authConfig, AuthStateCache authStateCache) {
return getInstance(AuthMicrosoftRequest.class,authConfig,authStateCache);
}
}, },
/** /**
* 小米 * 小米
*/ */
MI { MI(AuthMiRequest.class) {
@Override @Override
public String authorize() { public String authorize() {
return "https://account.xiaomi.com/oauth2/authorize"; return "https://account.xiaomi.com/oauth2/authorize";
...@@ -636,21 +446,11 @@ public enum AuthDefaultSource implements AuthSource { ...@@ -636,21 +446,11 @@ public enum AuthDefaultSource implements AuthSource {
public String refresh() { public String refresh() {
return "https://account.xiaomi.com/oauth2/token"; return "https://account.xiaomi.com/oauth2/token";
} }
@Override
public AuthRequest getAuthRequestInstance(AuthConfig authConfig) {
return getAuthRequestInstance(authConfig,null);
}
@Override
public AuthRequest getAuthRequestInstance(AuthConfig authConfig, AuthStateCache authStateCache) {
return getInstance(AuthMiRequest.class,authConfig,authStateCache);
}
}, },
/** /**
* 今日头条 * 今日头条
*/ */
TOUTIAO { TOUTIAO(AuthToutiaoRequest.class) {
@Override @Override
public String authorize() { public String authorize() {
return "https://open.snssdk.com/auth/authorize"; return "https://open.snssdk.com/auth/authorize";
...@@ -665,21 +465,11 @@ public enum AuthDefaultSource implements AuthSource { ...@@ -665,21 +465,11 @@ public enum AuthDefaultSource implements AuthSource {
public String userInfo() { public String userInfo() {
return "https://open.snssdk.com/data/user_profile"; return "https://open.snssdk.com/data/user_profile";
} }
@Override
public AuthRequest getAuthRequestInstance(AuthConfig authConfig) {
return getAuthRequestInstance(authConfig,null);
}
@Override
public AuthRequest getAuthRequestInstance(AuthConfig authConfig, AuthStateCache authStateCache) {
return getInstance(AuthToutiaoRequest.class,authConfig,authStateCache);
}
}, },
/** /**
* Teambition * Teambition
*/ */
TEAMBITION { TEAMBITION(AuthTeambitionRequest.class) {
@Override @Override
public String authorize() { public String authorize() {
return "https://account.teambition.com/oauth2/authorize"; return "https://account.teambition.com/oauth2/authorize";
...@@ -699,22 +489,12 @@ public enum AuthDefaultSource implements AuthSource { ...@@ -699,22 +489,12 @@ public enum AuthDefaultSource implements AuthSource {
public String userInfo() { public String userInfo() {
return "https://api.teambition.com/users/me"; return "https://api.teambition.com/users/me";
} }
@Override
public AuthRequest getAuthRequestInstance(AuthConfig authConfig) {
return getAuthRequestInstance(authConfig,null);
}
@Override
public AuthRequest getAuthRequestInstance(AuthConfig authConfig, AuthStateCache authStateCache) {
return getInstance(AuthTeambitionRequest.class,authConfig,authStateCache);
}
}, },
/** /**
* 人人网 * 人人网
*/ */
RENREN { RENREN(AuthRenrenRequest.class) {
@Override @Override
public String authorize() { public String authorize() {
return "https://graph.renren.com/oauth/authorize"; return "https://graph.renren.com/oauth/authorize";
...@@ -734,22 +514,12 @@ public enum AuthDefaultSource implements AuthSource { ...@@ -734,22 +514,12 @@ public enum AuthDefaultSource implements AuthSource {
public String userInfo() { public String userInfo() {
return "https://api.renren.com/v2/user/get"; return "https://api.renren.com/v2/user/get";
} }
@Override
public AuthRequest getAuthRequestInstance(AuthConfig authConfig) {
return getAuthRequestInstance(authConfig,null);
}
@Override
public AuthRequest getAuthRequestInstance(AuthConfig authConfig, AuthStateCache authStateCache) {
return getInstance(AuthRenrenRequest.class,authConfig,authStateCache);
}
}, },
/** /**
* Pinterest * Pinterest
*/ */
PINTEREST { PINTEREST(AuthPinterestRequest.class) {
@Override @Override
public String authorize() { public String authorize() {
return "https://api.pinterest.com/oauth"; return "https://api.pinterest.com/oauth";
...@@ -764,22 +534,12 @@ public enum AuthDefaultSource implements AuthSource { ...@@ -764,22 +534,12 @@ public enum AuthDefaultSource implements AuthSource {
public String userInfo() { public String userInfo() {
return "https://api.pinterest.com/v1/me"; return "https://api.pinterest.com/v1/me";
} }
@Override
public AuthRequest getAuthRequestInstance(AuthConfig authConfig) {
return getAuthRequestInstance(authConfig,null);
}
@Override
public AuthRequest getAuthRequestInstance(AuthConfig authConfig, AuthStateCache authStateCache) {
return getInstance(AuthPinterestRequest.class,authConfig,authStateCache);
}
}, },
/** /**
* Stack Overflow * Stack Overflow
*/ */
STACK_OVERFLOW { STACK_OVERFLOW(AuthStackOverflowRequest.class) {
@Override @Override
public String authorize() { public String authorize() {
return "https://stackoverflow.com/oauth"; return "https://stackoverflow.com/oauth";
...@@ -794,16 +554,6 @@ public enum AuthDefaultSource implements AuthSource { ...@@ -794,16 +554,6 @@ public enum AuthDefaultSource implements AuthSource {
public String userInfo() { public String userInfo() {
return "https://api.stackexchange.com/2.2/me"; return "https://api.stackexchange.com/2.2/me";
} }
@Override
public AuthRequest getAuthRequestInstance(AuthConfig authConfig) {
return getAuthRequestInstance(authConfig,null);
}
@Override
public AuthRequest getAuthRequestInstance(AuthConfig authConfig, AuthStateCache authStateCache) {
return getInstance(AuthStackOverflowRequest.class,authConfig,authStateCache);
}
}, },
/** /**
...@@ -811,7 +561,7 @@ public enum AuthDefaultSource implements AuthSource { ...@@ -811,7 +561,7 @@ public enum AuthDefaultSource implements AuthSource {
* *
* @since 1.10.0 * @since 1.10.0
*/ */
HUAWEI { HUAWEI(AuthHuaweiRequest.class) {
@Override @Override
public String authorize() { public String authorize() {
return "https://oauth-login.cloud.huawei.com/oauth2/v2/authorize"; return "https://oauth-login.cloud.huawei.com/oauth2/v2/authorize";
...@@ -831,16 +581,6 @@ public enum AuthDefaultSource implements AuthSource { ...@@ -831,16 +581,6 @@ public enum AuthDefaultSource implements AuthSource {
public String refresh() { public String refresh() {
return "https://oauth-login.cloud.huawei.com/oauth2/v2/token"; return "https://oauth-login.cloud.huawei.com/oauth2/v2/token";
} }
@Override
public AuthRequest getAuthRequestInstance(AuthConfig authConfig) {
return getAuthRequestInstance(authConfig,null);
}
@Override
public AuthRequest getAuthRequestInstance(AuthConfig authConfig, AuthStateCache authStateCache) {
return getInstance(AuthHuaweiRequest.class,authConfig,authStateCache);
}
}, },
/** /**
...@@ -848,7 +588,7 @@ public enum AuthDefaultSource implements AuthSource { ...@@ -848,7 +588,7 @@ public enum AuthDefaultSource implements AuthSource {
* *
* @since 1.10.0 * @since 1.10.0
*/ */
WECHAT_ENTERPRISE { WECHAT_ENTERPRISE(AuthWeChatEnterpriseQrcodeRequest.class) {
@Override @Override
public String authorize() { public String authorize() {
return "https://open.work.weixin.qq.com/wwopen/sso/qrConnect"; return "https://open.work.weixin.qq.com/wwopen/sso/qrConnect";
...@@ -863,22 +603,12 @@ public enum AuthDefaultSource implements AuthSource { ...@@ -863,22 +603,12 @@ public enum AuthDefaultSource implements AuthSource {
public String userInfo() { public String userInfo() {
return "https://qyapi.weixin.qq.com/cgi-bin/user/getuserinfo"; return "https://qyapi.weixin.qq.com/cgi-bin/user/getuserinfo";
} }
@Override
public AuthRequest getAuthRequestInstance(AuthConfig authConfig) {
return getAuthRequestInstance(authConfig,null);
}
@Override
public AuthRequest getAuthRequestInstance(AuthConfig authConfig, AuthStateCache authStateCache) {
return getInstance(AbstractAuthWeChatEnterpriseRequest.class,authConfig,authStateCache);
}
}, },
/** /**
* 企业微信网页登录 * 企业微信网页登录
*/ */
WECHAT_ENTERPRISE_WEB { WECHAT_ENTERPRISE_WEB(AuthWeChatEnterpriseWebRequest.class) {
@Override @Override
public String authorize() { public String authorize() {
return "https://open.weixin.qq.com/connect/oauth2/authorize"; return "https://open.weixin.qq.com/connect/oauth2/authorize";
...@@ -893,16 +623,6 @@ public enum AuthDefaultSource implements AuthSource { ...@@ -893,16 +623,6 @@ public enum AuthDefaultSource implements AuthSource {
public String userInfo() { public String userInfo() {
return "https://qyapi.weixin.qq.com/cgi-bin/user/getuserinfo"; return "https://qyapi.weixin.qq.com/cgi-bin/user/getuserinfo";
} }
@Override
public AuthRequest getAuthRequestInstance(AuthConfig authConfig) {
return getAuthRequestInstance(authConfig,null);
}
@Override
public AuthRequest getAuthRequestInstance(AuthConfig authConfig, AuthStateCache authStateCache) {
return getInstance(AuthWeChatEnterpriseWebRequest.class,authConfig,authStateCache);
}
}, },
/** /**
...@@ -910,7 +630,7 @@ public enum AuthDefaultSource implements AuthSource { ...@@ -910,7 +630,7 @@ public enum AuthDefaultSource implements AuthSource {
* *
* @since 1.11.0 * @since 1.11.0
*/ */
KUJIALE { KUJIALE(AuthKujialeRequest.class) {
@Override @Override
public String authorize() { public String authorize() {
return "https://oauth.kujiale.com/oauth2/show"; return "https://oauth.kujiale.com/oauth2/show";
...@@ -930,16 +650,6 @@ public enum AuthDefaultSource implements AuthSource { ...@@ -930,16 +650,6 @@ public enum AuthDefaultSource implements AuthSource {
public String refresh() { public String refresh() {
return "https://oauth.kujiale.com/oauth2/auth/token/refresh"; return "https://oauth.kujiale.com/oauth2/auth/token/refresh";
} }
@Override
public AuthRequest getAuthRequestInstance(AuthConfig authConfig) {
return getAuthRequestInstance(authConfig,null);
}
@Override
public AuthRequest getAuthRequestInstance(AuthConfig authConfig, AuthStateCache authStateCache) {
return getInstance(AuthKujialeRequest.class,authConfig,authStateCache);
}
}, },
/** /**
...@@ -947,7 +657,7 @@ public enum AuthDefaultSource implements AuthSource { ...@@ -947,7 +657,7 @@ public enum AuthDefaultSource implements AuthSource {
* *
* @since 1.11.0 * @since 1.11.0
*/ */
GITLAB { GITLAB(AuthGitlabRequest.class) {
@Override @Override
public String authorize() { public String authorize() {
return "https://gitlab.com/oauth/authorize"; return "https://gitlab.com/oauth/authorize";
...@@ -962,16 +672,6 @@ public enum AuthDefaultSource implements AuthSource { ...@@ -962,16 +672,6 @@ public enum AuthDefaultSource implements AuthSource {
public String userInfo() { public String userInfo() {
return "https://gitlab.com/api/v4/user"; return "https://gitlab.com/api/v4/user";
} }
@Override
public AuthRequest getAuthRequestInstance(AuthConfig authConfig) {
return getAuthRequestInstance(authConfig,null);
}
@Override
public AuthRequest getAuthRequestInstance(AuthConfig authConfig, AuthStateCache authStateCache) {
return getInstance(AuthGitlabRequest.class,authConfig,authStateCache);
}
}, },
/** /**
...@@ -979,7 +679,7 @@ public enum AuthDefaultSource implements AuthSource { ...@@ -979,7 +679,7 @@ public enum AuthDefaultSource implements AuthSource {
* *
* @since 1.12.0 * @since 1.12.0
*/ */
MEITUAN { MEITUAN(AuthMeituanRequest.class) {
@Override @Override
public String authorize() { public String authorize() {
return "https://openapi.waimai.meituan.com/oauth/authorize"; return "https://openapi.waimai.meituan.com/oauth/authorize";
...@@ -999,16 +699,6 @@ public enum AuthDefaultSource implements AuthSource { ...@@ -999,16 +699,6 @@ public enum AuthDefaultSource implements AuthSource {
public String refresh() { public String refresh() {
return "https://openapi.waimai.meituan.com/oauth/refresh_token"; return "https://openapi.waimai.meituan.com/oauth/refresh_token";
} }
@Override
public AuthRequest getAuthRequestInstance(AuthConfig authConfig) {
return getAuthRequestInstance(authConfig,null);
}
@Override
public AuthRequest getAuthRequestInstance(AuthConfig authConfig, AuthStateCache authStateCache) {
return getInstance(AuthMeituanRequest.class,authConfig,authStateCache);
}
}, },
/** /**
...@@ -1018,7 +708,7 @@ public enum AuthDefaultSource implements AuthSource { ...@@ -1018,7 +708,7 @@ public enum AuthDefaultSource implements AuthSource {
* *
* @since 1.12.0 * @since 1.12.0
*/ */
ELEME { ELEME(AuthElemeRequest.class) {
@Override @Override
public String authorize() { public String authorize() {
return "https://open-api.shop.ele.me/authorize"; return "https://open-api.shop.ele.me/authorize";
...@@ -1038,16 +728,6 @@ public enum AuthDefaultSource implements AuthSource { ...@@ -1038,16 +728,6 @@ public enum AuthDefaultSource implements AuthSource {
public String refresh() { public String refresh() {
return "https://open-api.shop.ele.me/token"; return "https://open-api.shop.ele.me/token";
} }
@Override
public AuthRequest getAuthRequestInstance(AuthConfig authConfig) {
return getAuthRequestInstance(authConfig,null);
}
@Override
public AuthRequest getAuthRequestInstance(AuthConfig authConfig, AuthStateCache authStateCache) {
return getInstance(AuthElemeRequest.class,authConfig,authStateCache);
}
}, },
/** /**
...@@ -1055,7 +735,7 @@ public enum AuthDefaultSource implements AuthSource { ...@@ -1055,7 +735,7 @@ public enum AuthDefaultSource implements AuthSource {
* *
* @since 1.13.0 * @since 1.13.0
*/ */
TWITTER { TWITTER(AuthTwitterRequest.class) {
@Override @Override
public String authorize() { public String authorize() {
return "https://api.twitter.com/oauth/authenticate"; return "https://api.twitter.com/oauth/authenticate";
...@@ -1070,16 +750,6 @@ public enum AuthDefaultSource implements AuthSource { ...@@ -1070,16 +750,6 @@ public enum AuthDefaultSource implements AuthSource {
public String userInfo() { public String userInfo() {
return "https://api.twitter.com/1.1/account/verify_credentials.json"; return "https://api.twitter.com/1.1/account/verify_credentials.json";
} }
@Override
public AuthRequest getAuthRequestInstance(AuthConfig authConfig) {
return getAuthRequestInstance(authConfig,null);
}
@Override
public AuthRequest getAuthRequestInstance(AuthConfig authConfig, AuthStateCache authStateCache) {
return getInstance(AuthTwitterRequest.class,authConfig,authStateCache);
}
}, },
/** /**
...@@ -1089,7 +759,7 @@ public enum AuthDefaultSource implements AuthSource { ...@@ -1089,7 +759,7 @@ public enum AuthDefaultSource implements AuthSource {
* *
* @since 1.15.9 * @since 1.15.9
*/ */
FEISHU { FEISHU(AuthFeishuRequest.class) {
@Override @Override
public String authorize() { public String authorize() {
return "https://open.feishu.cn/open-apis/authen/v1/index"; return "https://open.feishu.cn/open-apis/authen/v1/index";
...@@ -1109,23 +779,13 @@ public enum AuthDefaultSource implements AuthSource { ...@@ -1109,23 +779,13 @@ public enum AuthDefaultSource implements AuthSource {
public String refresh() { public String refresh() {
return "https://open.feishu.cn/open-apis/authen/v1/refresh_access_token"; return "https://open.feishu.cn/open-apis/authen/v1/refresh_access_token";
} }
@Override
public AuthRequest getAuthRequestInstance(AuthConfig authConfig) {
return getAuthRequestInstance(authConfig,null);
}
@Override
public AuthRequest getAuthRequestInstance(AuthConfig authConfig, AuthStateCache authStateCache) {
return getInstance(AuthFeishuRequest.class,authConfig,authStateCache);
}
}, },
/** /**
* 京东 * 京东
* *
* @since 1.15.0 * @since 1.15.0
*/ */
JD { JD(AuthJdRequest.class) {
@Override @Override
public String authorize() { public String authorize() {
return "https://open-oauth.jd.com/oauth2/to_login"; return "https://open-oauth.jd.com/oauth2/to_login";
...@@ -1145,22 +805,12 @@ public enum AuthDefaultSource implements AuthSource { ...@@ -1145,22 +805,12 @@ public enum AuthDefaultSource implements AuthSource {
public String refresh() { public String refresh() {
return "https://open-oauth.jd.com/oauth2/refresh_token"; return "https://open-oauth.jd.com/oauth2/refresh_token";
} }
@Override
public AuthRequest getAuthRequestInstance(AuthConfig authConfig) {
return getAuthRequestInstance(authConfig,null);
}
@Override
public AuthRequest getAuthRequestInstance(AuthConfig authConfig, AuthStateCache authStateCache) {
return getInstance(AuthJdRequest.class,authConfig,authStateCache);
}
}, },
/** /**
* 阿里云 * 阿里云
*/ */
ALIYUN { ALIYUN(AuthAliyunRequest.class) {
@Override @Override
public String authorize() { public String authorize() {
return "https://signin.aliyun.com/oauth2/v1/auth"; return "https://signin.aliyun.com/oauth2/v1/auth";
...@@ -1180,22 +830,12 @@ public enum AuthDefaultSource implements AuthSource { ...@@ -1180,22 +830,12 @@ public enum AuthDefaultSource implements AuthSource {
public String refresh() { public String refresh() {
return "https://oauth.aliyun.com/v1/token"; return "https://oauth.aliyun.com/v1/token";
} }
@Override
public AuthRequest getAuthRequestInstance(AuthConfig authConfig) {
return getAuthRequestInstance(authConfig,null);
}
@Override
public AuthRequest getAuthRequestInstance(AuthConfig authConfig, AuthStateCache authStateCache) {
return getInstance(AuthAliyunRequest.class,authConfig,authStateCache);
}
}, },
/** /**
* 喜马拉雅 * 喜马拉雅
*/ */
XMLY { XMLY(AuthXmlyRequest.class) {
@Override @Override
public String authorize() { public String authorize() {
return "https://api.ximalaya.com/oauth2/js/authorize"; return "https://api.ximalaya.com/oauth2/js/authorize";
...@@ -1215,16 +855,6 @@ public enum AuthDefaultSource implements AuthSource { ...@@ -1215,16 +855,6 @@ public enum AuthDefaultSource implements AuthSource {
public String refresh() { public String refresh() {
return "https://oauth.aliyun.com/v1/token"; return "https://oauth.aliyun.com/v1/token";
} }
@Override
public AuthRequest getAuthRequestInstance(AuthConfig authConfig) {
return getAuthRequestInstance(authConfig,null);
}
@Override
public AuthRequest getAuthRequestInstance(AuthConfig authConfig, AuthStateCache authStateCache) {
return getInstance(AuthXmlyRequest.class,authConfig,authStateCache);
}
}, },
/** /**
...@@ -1232,7 +862,7 @@ public enum AuthDefaultSource implements AuthSource { ...@@ -1232,7 +862,7 @@ public enum AuthDefaultSource implements AuthSource {
* *
* @since 1.16.0 * @since 1.16.0
*/ */
AMAZON { AMAZON(AuthAmazonRequest.class) {
@Override @Override
public String authorize() { public String authorize() {
return "https://www.amazon.com/ap/oa"; return "https://www.amazon.com/ap/oa";
...@@ -1252,23 +882,13 @@ public enum AuthDefaultSource implements AuthSource { ...@@ -1252,23 +882,13 @@ public enum AuthDefaultSource implements AuthSource {
public String refresh() { public String refresh() {
return "https://api.amazon.com/auth/o2/token"; return "https://api.amazon.com/auth/o2/token";
} }
@Override
public AuthRequest getAuthRequestInstance(AuthConfig authConfig) {
return getAuthRequestInstance(authConfig,null);
}
@Override
public AuthRequest getAuthRequestInstance(AuthConfig authConfig, AuthStateCache authStateCache) {
return getInstance(AuthAmazonRequest.class,authConfig,authStateCache);
}
}, },
/** /**
* Slack * Slack
* *
* @since 1.16.0 * @since 1.16.0
*/ */
SLACK { SLACK(AuthSlackRequest.class) {
@Override @Override
public String authorize() { public String authorize() {
return "https://slack.com/oauth/v2/authorize"; return "https://slack.com/oauth/v2/authorize";
...@@ -1295,23 +915,13 @@ public enum AuthDefaultSource implements AuthSource { ...@@ -1295,23 +915,13 @@ public enum AuthDefaultSource implements AuthSource {
public String revoke() { public String revoke() {
return "https://slack.com/api/auth.revoke"; return "https://slack.com/api/auth.revoke";
} }
@Override
public AuthRequest getAuthRequestInstance(AuthConfig authConfig) {
return getAuthRequestInstance(authConfig,null);
}
@Override
public AuthRequest getAuthRequestInstance(AuthConfig authConfig, AuthStateCache authStateCache) {
return getInstance(AuthSlackRequest.class,authConfig,authStateCache);
}
}, },
/** /**
* line * line
* *
* @since 1.16.0 * @since 1.16.0
*/ */
LINE { LINE(AuthLineRequest.class) {
@Override @Override
public String authorize() { public String authorize() {
return "https://access.line.me/oauth2/v2.1/authorize"; return "https://access.line.me/oauth2/v2.1/authorize";
...@@ -1327,16 +937,6 @@ public enum AuthDefaultSource implements AuthSource { ...@@ -1327,16 +937,6 @@ public enum AuthDefaultSource implements AuthSource {
return "https://api.line.me/v2/profile"; return "https://api.line.me/v2/profile";
} }
@Override
public AuthRequest getAuthRequestInstance(AuthConfig authConfig) {
return getAuthRequestInstance(authConfig,null);
}
@Override
public AuthRequest getAuthRequestInstance(AuthConfig authConfig, AuthStateCache authStateCache) {
return getInstance(AuthLineRequest.class,authConfig,authStateCache);
}
@Override @Override
public String refresh() { public String refresh() {
return "https://api.line.me/oauth2/v2.1/token"; return "https://api.line.me/oauth2/v2.1/token";
...@@ -1346,7 +946,6 @@ public enum AuthDefaultSource implements AuthSource { ...@@ -1346,7 +946,6 @@ public enum AuthDefaultSource implements AuthSource {
public String revoke() { public String revoke() {
return "https://api.line.me/oauth2/v2.1/revoke"; return "https://api.line.me/oauth2/v2.1/revoke";
} }
}, },
/** /**
* Okta, * Okta,
...@@ -1355,7 +954,7 @@ public enum AuthDefaultSource implements AuthSource { ...@@ -1355,7 +954,7 @@ public enum AuthDefaultSource implements AuthSource {
* *
* @since 1.16.0 * @since 1.16.0
*/ */
OKTA { OKTA(AuthOktaRequest.class) {
@Override @Override
public String authorize() { public String authorize() {
return "https://%s.okta.com/oauth2/%s/v1/authorize"; return "https://%s.okta.com/oauth2/%s/v1/authorize";
...@@ -1380,23 +979,13 @@ public enum AuthDefaultSource implements AuthSource { ...@@ -1380,23 +979,13 @@ public enum AuthDefaultSource implements AuthSource {
public String revoke() { public String revoke() {
return "https://%s.okta.com/oauth2/%s/v1/revoke"; return "https://%s.okta.com/oauth2/%s/v1/revoke";
} }
@Override
public AuthRequest getAuthRequestInstance(AuthConfig authConfig) {
return getAuthRequestInstance(authConfig,null);
}
@Override
public AuthRequest getAuthRequestInstance(AuthConfig authConfig, AuthStateCache authStateCache) {
return getInstance(AuthOktaRequest.class,authConfig,authStateCache);
}
}, },
/** /**
* 程序员客栈 * 程序员客栈
* *
* @since 1.16.2 * @since 1.16.2
*/ */
PROGINN { PROGINN(AuthProginnRequest.class) {
@Override @Override
public String authorize() { public String authorize() {
return "https://www.proginn.com/oauth2/authorize"; return "https://www.proginn.com/oauth2/authorize";
...@@ -1411,44 +1000,49 @@ public enum AuthDefaultSource implements AuthSource { ...@@ -1411,44 +1000,49 @@ public enum AuthDefaultSource implements AuthSource {
public String userInfo() { public String userInfo() {
return "https://www.proginn.com/openapi/user/basic_info"; return "https://www.proginn.com/openapi/user/basic_info";
} }
};
@Override /** 对应的实现类 */
public AuthRequest getAuthRequestInstance(AuthConfig authConfig) { private Class<? extends AuthDefaultRequest> targetClass;
return getAuthRequestInstance(authConfig,null);
}
@Override AuthDefaultSource(Class<? extends AuthDefaultRequest> targetClass) {
public AuthRequest getAuthRequestInstance(AuthConfig authConfig, AuthStateCache authStateCache) { this.targetClass = targetClass;
return getInstance(AuthProginnRequest.class,authConfig,authStateCache); }
}
}; /**
* 根据source获取对应的AuthSource枚举
* @param source 枚举名
* @return AuthDefaultSource
*/
public static AuthDefaultSource getAuthSource(String source){
return Arrays.stream(AuthDefaultSource.values()).filter(authSource -> authSource.name().equalsIgnoreCase(source)).findAny().orElseThrow(()->new AuthException("未获取到有效的AuthSource配置"));
}
/**
* 根据配置获取 AuthRequest 实例
* @param authConfig 配置
* @return AuthRequest
*/
public AuthRequest getAuthRequestInstance(AuthConfig authConfig) {
return getAuthRequestInstance(authConfig,null);
}
/** /**
* 利用反射 生成 AuthRequest 实例 * 利用反射 生成 AuthRequest 实例
* @param cl 目标 class
* @param authConfig 配置 * @param authConfig 配置
* @param authStateCache 缓存配置 * @param authStateCache 缓存配置
* @return AuthRequest * @return AuthRequest
*/ */
AuthRequest getInstance(Class<? extends AuthDefaultRequest> cl, AuthConfig authConfig, AuthStateCache authStateCache) { public AuthRequest getAuthRequestInstance(AuthConfig authConfig, AuthStateCache authStateCache) {
try { try {
Class<?> clazz = Class.forName(cl.getName());
if(authStateCache==null){ if(authStateCache==null){
return (AuthRequest) clazz.getDeclaredConstructor(AuthConfig.class).newInstance(authConfig); return this.targetClass.getDeclaredConstructor(AuthConfig.class).newInstance(authConfig);
}else{ }else{
return (AuthRequest) clazz.getDeclaredConstructor(AuthConfig.class, AuthStateCache.class).newInstance(authConfig, authStateCache); return this.targetClass.getDeclaredConstructor(AuthConfig.class, AuthStateCache.class).newInstance(authConfig, authStateCache);
} }
} catch (Exception e) { } catch (Exception e) {
throw new AuthException("未获取到有效的Auth配置"); throw new AuthException("未获取到有效的Auth配置");
} }
} }
/**
* 根据source获取对应的AuthSource枚举实例
* @param source 枚举名
* @return AuthDefaultSource
*/
public static AuthDefaultSource getAuthSource(String source){
return Arrays.stream(AuthDefaultSource.values()).filter(authSource -> source.equalsIgnoreCase(authSource.name())).findAny().orElseThrow(()->new AuthException("未获取到有效的AuthSource配置"));
}
} }
package me.zhyd.oauth.config; package me.zhyd.oauth.config;
import me.zhyd.oauth.cache.AuthStateCache;
import me.zhyd.oauth.enums.AuthResponseStatus; import me.zhyd.oauth.enums.AuthResponseStatus;
import me.zhyd.oauth.exception.AuthException; import me.zhyd.oauth.exception.AuthException;
import me.zhyd.oauth.model.AuthCallback; import me.zhyd.oauth.model.AuthCallback;
import me.zhyd.oauth.request.AuthRequest;
/** /**
* OAuth平台的API地址的统一接口,提供以下方法: * OAuth平台的API地址的统一接口,提供以下方法:
...@@ -46,21 +44,6 @@ public interface AuthSource { ...@@ -46,21 +44,6 @@ public interface AuthSource {
*/ */
String userInfo(); String userInfo();
/**
* 根据配置获取对应的实例
* @param authConfig 配置
* @return AuthRequest
*/
AuthRequest getAuthRequestInstance(AuthConfig authConfig);
/**
* 根据配置和缓存获取对应的实例
* @param authConfig 配置
* @param authStateCache 缓存
* @return AuthRequest
*/
AuthRequest getAuthRequestInstance(AuthConfig authConfig, AuthStateCache authStateCache);
/** /**
* 取消授权的api * 取消授权的api
* *
......
...@@ -2,11 +2,10 @@ package me.zhyd.oauth.config; ...@@ -2,11 +2,10 @@ package me.zhyd.oauth.config;
import me.zhyd.oauth.cache.AuthStateCache; import me.zhyd.oauth.cache.AuthStateCache;
import me.zhyd.oauth.exception.AuthException; import me.zhyd.oauth.exception.AuthException;
import me.zhyd.oauth.request.AuthDefaultRequest;
import me.zhyd.oauth.request.AuthExtendRequest; import me.zhyd.oauth.request.AuthExtendRequest;
import me.zhyd.oauth.request.AuthRequest; import me.zhyd.oauth.request.AuthRequest;
import java.lang.reflect.Constructor;
/** /**
* 测试自定义实现{@link AuthSource}接口后的枚举类 * 测试自定义实现{@link AuthSource}接口后的枚举类
* *
...@@ -16,7 +15,7 @@ import java.lang.reflect.Constructor; ...@@ -16,7 +15,7 @@ import java.lang.reflect.Constructor;
*/ */
public enum AuthExtendSource implements AuthSource { public enum AuthExtendSource implements AuthSource {
OTHER { OTHER (AuthExtendRequest.class){
/** /**
* 授权的api * 授权的api
* *
...@@ -47,32 +46,6 @@ public enum AuthExtendSource implements AuthSource { ...@@ -47,32 +46,6 @@ public enum AuthExtendSource implements AuthSource {
return null; return null;
} }
@Override
public AuthRequest getAuthRequestInstance(AuthConfig authConfig) {
return getAuthRequestInstance(authConfig,null);
}
@Override
public AuthRequest getAuthRequestInstance(AuthConfig authConfig, AuthStateCache authStateCache) {
try {
AuthRequest request;
Class<?> clazz = Class.forName(AuthExtendRequest.class.getName());
Constructor constructor;
if(authStateCache==null){
constructor = clazz.getDeclaredConstructor(AuthConfig.class);
constructor.setAccessible(true);
request = (AuthRequest) constructor.newInstance(authConfig);
}else{
constructor = clazz.getDeclaredConstructor(AuthConfig.class, AuthStateCache.class);
constructor.setAccessible(true);
request = (AuthRequest) constructor.newInstance(authConfig, authStateCache);
}
return request;
} catch (Exception e) {
throw new AuthException("未获取到有效的Auth配置");
}
}
/** /**
* 取消授权的api * 取消授权的api
* *
...@@ -92,5 +65,28 @@ public enum AuthExtendSource implements AuthSource { ...@@ -92,5 +65,28 @@ public enum AuthExtendSource implements AuthSource {
public String refresh() { public String refresh() {
return null; return null;
} }
};
private Class<? extends AuthDefaultRequest> targetClass;
AuthExtendSource(Class<? extends AuthDefaultRequest> targetClass) {
this.targetClass = targetClass;
}
public AuthRequest getAuthRequestInstance(AuthConfig authConfig) {
return this.getAuthRequestInstance(authConfig,null);
}
public AuthRequest getAuthRequestInstance(AuthConfig authConfig, AuthStateCache authStateCache) {
try {
if(authStateCache==null){
return this.targetClass.getDeclaredConstructor(AuthConfig.class).newInstance(authConfig);
}else{
return this.targetClass.getDeclaredConstructor(AuthConfig.class, AuthStateCache.class).newInstance(authConfig, authStateCache);
}
} catch (Exception e) {
throw new AuthException("未获取到有效的Auth配置");
}
} }
} }
...@@ -3,6 +3,7 @@ package me.zhyd.oauth.request; ...@@ -3,6 +3,7 @@ package me.zhyd.oauth.request;
import me.zhyd.oauth.config.AuthConfig; import me.zhyd.oauth.config.AuthConfig;
import me.zhyd.oauth.config.AuthDefaultSource; import me.zhyd.oauth.config.AuthDefaultSource;
import me.zhyd.oauth.utils.AuthStateUtils; import me.zhyd.oauth.utils.AuthStateUtils;
import org.junit.Assert;
import org.junit.Test; import org.junit.Test;
public class AuthWeChatMpRequestTest { public class AuthWeChatMpRequestTest {
...@@ -25,6 +26,7 @@ public class AuthWeChatMpRequestTest { ...@@ -25,6 +26,7 @@ public class AuthWeChatMpRequestTest {
.clientSecret("a") .clientSecret("a")
.redirectUri("https://www.justauth.cn") .redirectUri("https://www.justauth.cn")
.build()); .build());
Assert.assertTrue(request instanceof AuthWeChatMpRequest);
System.out.println(request.authorize(AuthStateUtils.createState())); System.out.println(request.authorize(AuthStateUtils.createState()));
} }
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册