mirror of
https://gitee.com/yadong.zhang/JustAuth.git
synced 2025-12-06 16:58:24 +08:00
Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
b9268f296b
@ -14,6 +14,9 @@
|
|||||||
<a target="_blank" href="https://www.oracle.com/technetwork/java/javase/downloads/index.html">
|
<a target="_blank" href="https://www.oracle.com/technetwork/java/javase/downloads/index.html">
|
||||||
<img src="https://img.shields.io/badge/JDK-1.8+-green.svg" ></img>
|
<img src="https://img.shields.io/badge/JDK-1.8+-green.svg" ></img>
|
||||||
</a>
|
</a>
|
||||||
|
<a target="_blank" href="https://apidoc.gitee.com/yadong.zhang/JustAuth/">
|
||||||
|
<img src="https://img.shields.io/badge/Docs-1.7.0-orange.svg" ></img>
|
||||||
|
</a>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<center>
|
<center>
|
||||||
@ -94,7 +97,7 @@ authRequest.login("code");
|
|||||||
|:------:|:-------:|:-------:|
|
|:------:|:-------:|:-------:|
|
||||||
| <img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/gitee.png" width="20"> | [AuthGiteeRequest](https://gitee.com/yadong.zhang/JustAuth/blob/master/src/main/java/me/zhyd/oauth/request/AuthGiteeRequest.java) | <a href="https://gitee.com/api/v5/oauth_doc#list_1" target="_blank">参考文档</a> |
|
| <img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/gitee.png" width="20"> | [AuthGiteeRequest](https://gitee.com/yadong.zhang/JustAuth/blob/master/src/main/java/me/zhyd/oauth/request/AuthGiteeRequest.java) | <a href="https://gitee.com/api/v5/oauth_doc#list_1" target="_blank">参考文档</a> |
|
||||||
| <img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/github.png" width="20"> | [AuthGithubRequest](https://gitee.com/yadong.zhang/JustAuth/blob/master/src/main/java/me/zhyd/oauth/request/AuthGiteeRequest.java) | <a href="https://github.com/settings/developers" target="_blank">参考文档</a> |
|
| <img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/github.png" width="20"> | [AuthGithubRequest](https://gitee.com/yadong.zhang/JustAuth/blob/master/src/main/java/me/zhyd/oauth/request/AuthGiteeRequest.java) | <a href="https://github.com/settings/developers" target="_blank">参考文档</a> |
|
||||||
| <img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/weibo.png" width="20"> | [AuthWeiboRequest](https://gitee.com/yadong.zhang/JustAuth/blob/master/src/main/java/me/zhyd/oauth/request/AuthGiteeRequest.java) | <a href="https://open.weibo.com/wiki/%E5%BE%AE%E5%8D%9AAPI" target="_blank">参考文档</a> |
|
| <img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/weibo.png" width="20"> | [AuthWeiboRequest](https://gitee.com/yadong.zhang/JustAuth/blob/master/src/main/java/me/zhyd/oauth/request/AuthGiteeRequest.java) | <a href="https://open.weibo.com/wiki/%E6%8E%88%E6%9D%83%E6%9C%BA%E5%88%B6%E8%AF%B4%E6%98%8E" target="_blank">参考文档</a> |
|
||||||
| <img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/dingtalk.png" width="20"> | [AuthDingTalkRequest](https://gitee.com/yadong.zhang/JustAuth/blob/master/src/main/java/me/zhyd/oauth/request/AuthDingTalkRequest.java) | <a href="https://open-doc.dingtalk.com/microapp/serverapi2/kymkv6" target="_blank">参考文档</a> |
|
| <img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/dingtalk.png" width="20"> | [AuthDingTalkRequest](https://gitee.com/yadong.zhang/JustAuth/blob/master/src/main/java/me/zhyd/oauth/request/AuthDingTalkRequest.java) | <a href="https://open-doc.dingtalk.com/microapp/serverapi2/kymkv6" target="_blank">参考文档</a> |
|
||||||
| <img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/baidu.png" width="20"> | [AuthBaiduRequest](https://gitee.com/yadong.zhang/JustAuth/blob/master/src/main/java/me/zhyd/oauth/request/AuthBaiduRequest.java) | <a href="https://developer.baidu.com/" target="_blank">参考文档</a> |
|
| <img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/baidu.png" width="20"> | [AuthBaiduRequest](https://gitee.com/yadong.zhang/JustAuth/blob/master/src/main/java/me/zhyd/oauth/request/AuthBaiduRequest.java) | <a href="https://developer.baidu.com/" target="_blank">参考文档</a> |
|
||||||
| <img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/coding.png" width="25"> | [AuthCodingRequest](https://gitee.com/yadong.zhang/JustAuth/blob/master/src/main/java/me/zhyd/oauth/request/AuthCodingRequest.java) | <a href="https://open.coding.net/references/oauth/" target="_blank">参考文档</a> |
|
| <img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/coding.png" width="25"> | [AuthCodingRequest](https://gitee.com/yadong.zhang/JustAuth/blob/master/src/main/java/me/zhyd/oauth/request/AuthCodingRequest.java) | <a href="https://open.coding.net/references/oauth/" target="_blank">参考文档</a> |
|
||||||
|
|||||||
@ -327,7 +327,7 @@ public enum AuthSource {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String refresh() {
|
public String refresh() {
|
||||||
return "https://open.douyin.com/oauth/refresh_token";
|
return "https://open.douyin.com/oauth/refresh_token/";
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -29,7 +29,7 @@ public class AuthBaiduRequest extends BaseAuthRequest {
|
|||||||
HttpResponse response = HttpRequest.post(accessTokenUrl).execute();
|
HttpResponse response = HttpRequest.post(accessTokenUrl).execute();
|
||||||
JSONObject accessTokenObject = JSONObject.parseObject(response.body());
|
JSONObject accessTokenObject = JSONObject.parseObject(response.body());
|
||||||
AuthBaiduErrorCode errorCode = AuthBaiduErrorCode.getErrorCode(accessTokenObject.getString("error"));
|
AuthBaiduErrorCode errorCode = AuthBaiduErrorCode.getErrorCode(accessTokenObject.getString("error"));
|
||||||
if (!AuthBaiduErrorCode.OK.equals(errorCode)) {
|
if (AuthBaiduErrorCode.OK != errorCode) {
|
||||||
throw new AuthException(errorCode.getDesc());
|
throw new AuthException(errorCode.getDesc());
|
||||||
}
|
}
|
||||||
return AuthToken.builder().accessToken(accessTokenObject.getString("access_token")).build();
|
return AuthToken.builder().accessToken(accessTokenObject.getString("access_token")).build();
|
||||||
@ -42,7 +42,7 @@ public class AuthBaiduRequest extends BaseAuthRequest {
|
|||||||
String userInfo = response.body();
|
String userInfo = response.body();
|
||||||
JSONObject object = JSONObject.parseObject(userInfo);
|
JSONObject object = JSONObject.parseObject(userInfo);
|
||||||
AuthBaiduErrorCode errorCode = AuthBaiduErrorCode.getErrorCode(object.getString("error"));
|
AuthBaiduErrorCode errorCode = AuthBaiduErrorCode.getErrorCode(object.getString("error"));
|
||||||
if (!AuthBaiduErrorCode.OK.equals(errorCode)) {
|
if (AuthBaiduErrorCode.OK != errorCode) {
|
||||||
throw new AuthException(errorCode.getDesc());
|
throw new AuthException(errorCode.getDesc());
|
||||||
}
|
}
|
||||||
return AuthUser.builder()
|
return AuthUser.builder()
|
||||||
|
|||||||
@ -40,13 +40,12 @@ public class AuthDingTalkRequest extends BaseAuthRequest {
|
|||||||
String urlEncodeSignature = GlobalAuthUtil.generateDingTalkSignature(config.getClientSecret(), timestamp);
|
String urlEncodeSignature = GlobalAuthUtil.generateDingTalkSignature(config.getClientSecret(), timestamp);
|
||||||
JSONObject param = new JSONObject();
|
JSONObject param = new JSONObject();
|
||||||
param.put("tmp_auth_code", code);
|
param.put("tmp_auth_code", code);
|
||||||
HttpResponse response = HttpRequest.post(UrlBuilder.getDingTalkUserInfoUrl(urlEncodeSignature, timestamp, config.getClientId()))
|
HttpResponse response = HttpRequest.post(UrlBuilder.getDingTalkUserInfoUrl(urlEncodeSignature, timestamp, config
|
||||||
.body(param.toJSONString())
|
.getClientId())).body(param.toJSONString()).execute();
|
||||||
.execute();
|
|
||||||
String userInfo = response.body();
|
String userInfo = response.body();
|
||||||
JSONObject object = JSON.parseObject(userInfo);
|
JSONObject object = JSON.parseObject(userInfo);
|
||||||
AuthDingTalkErrorCode errorCode = AuthDingTalkErrorCode.getErrorCode(object.getIntValue("errcode"));
|
AuthDingTalkErrorCode errorCode = AuthDingTalkErrorCode.getErrorCode(object.getIntValue("errcode"));
|
||||||
if (!AuthDingTalkErrorCode.EC0.equals(errorCode)) {
|
if (AuthDingTalkErrorCode.EC0 != errorCode) {
|
||||||
throw new AuthException(errorCode.getDesc());
|
throw new AuthException(errorCode.getDesc());
|
||||||
}
|
}
|
||||||
object = object.getJSONObject("user_info");
|
object = object.getJSONObject("user_info");
|
||||||
|
|||||||
@ -63,7 +63,7 @@ public class AuthMiRequest extends BaseAuthRequest {
|
|||||||
.execute();
|
.execute();
|
||||||
|
|
||||||
JSONObject userProfile = JSONObject.parseObject(userResponse.body());
|
JSONObject userProfile = JSONObject.parseObject(userResponse.body());
|
||||||
if (StrUtil.equalsIgnoreCase(userProfile.getString("result"), "error")) {
|
if ("error".equalsIgnoreCase(userProfile.getString("result"))) {
|
||||||
throw new AuthException(userProfile.getString("description"));
|
throw new AuthException(userProfile.getString("description"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -86,7 +86,7 @@ public class AuthMiRequest extends BaseAuthRequest {
|
|||||||
|
|
||||||
HttpResponse emailResponse = HttpRequest.get(emailPhoneUrl).execute();
|
HttpResponse emailResponse = HttpRequest.get(emailPhoneUrl).execute();
|
||||||
JSONObject userEmailPhone = JSONObject.parseObject(emailResponse.body());
|
JSONObject userEmailPhone = JSONObject.parseObject(emailResponse.body());
|
||||||
if (!StrUtil.equalsIgnoreCase(userEmailPhone.getString("result"), "error")) {
|
if (!"error".equalsIgnoreCase(userEmailPhone.getString("result"))) {
|
||||||
JSONObject emailPhone = userEmailPhone.getJSONObject("data");
|
JSONObject emailPhone = userEmailPhone.getJSONObject("data");
|
||||||
authUser.setEmail(emailPhone.getString("email"));
|
authUser.setEmail(emailPhone.getString("email"));
|
||||||
}
|
}
|
||||||
|
|||||||
@ -40,7 +40,8 @@ public class AuthWeiboRequest extends BaseAuthRequest {
|
|||||||
return AuthToken.builder()
|
return AuthToken.builder()
|
||||||
.accessToken(accessTokenObject.getString("access_token"))
|
.accessToken(accessTokenObject.getString("access_token"))
|
||||||
.uid(accessTokenObject.getString("uid"))
|
.uid(accessTokenObject.getString("uid"))
|
||||||
.expireIn(accessTokenObject.getIntValue("remind_in"))
|
.openId(accessTokenObject.getString("uid"))
|
||||||
|
.expireIn(accessTokenObject.getIntValue("expires_in"))
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -8,6 +8,8 @@ import javax.crypto.spec.SecretKeySpec;
|
|||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
import java.net.URLDecoder;
|
import java.net.URLDecoder;
|
||||||
import java.net.URLEncoder;
|
import java.net.URLEncoder;
|
||||||
|
import java.nio.charset.Charset;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.security.InvalidKeyException;
|
import java.security.InvalidKeyException;
|
||||||
import java.security.NoSuchAlgorithmException;
|
import java.security.NoSuchAlgorithmException;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
@ -22,16 +24,12 @@ import java.util.Map;
|
|||||||
* @since 1.8
|
* @since 1.8
|
||||||
*/
|
*/
|
||||||
public class GlobalAuthUtil {
|
public class GlobalAuthUtil {
|
||||||
private static final String DEFAULT_ENCODING = "UTF-8";
|
private static final Charset DEFAULT_ENCODING = StandardCharsets.UTF_8;
|
||||||
private static final String ALGORITHM = "HmacSHA256";
|
private static final String ALGORITHM = "HmacSHA256";
|
||||||
|
|
||||||
public static String generateDingTalkSignature(String secretKey, String timestamp) {
|
public static String generateDingTalkSignature(String secretKey, String timestamp) {
|
||||||
try {
|
byte[] signData = sign(secretKey.getBytes(DEFAULT_ENCODING), timestamp.getBytes(DEFAULT_ENCODING));
|
||||||
byte[] signData = sign(secretKey.getBytes(DEFAULT_ENCODING), timestamp.getBytes(DEFAULT_ENCODING));
|
return urlEncode(new String(Base64.encode(signData, false)));
|
||||||
return urlEncode(new String(Base64.encode(signData, false)));
|
|
||||||
} catch (UnsupportedEncodingException ex) {
|
|
||||||
throw new AuthException("Unsupported algorithm: " + DEFAULT_ENCODING, ex);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static byte[] sign(byte[] key, byte[] data) {
|
private static byte[] sign(byte[] key, byte[] data) {
|
||||||
@ -52,9 +50,8 @@ public class GlobalAuthUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
String encoded = URLEncoder.encode(value, GlobalAuthUtil.DEFAULT_ENCODING);
|
String encoded = URLEncoder.encode(value, GlobalAuthUtil.DEFAULT_ENCODING.displayName());
|
||||||
return encoded.replace("+", "%20").replace("*", "%2A")
|
return encoded.replace("+", "%20").replace("*", "%2A").replace("~", "%7E").replace("/", "%2F");
|
||||||
.replace("~", "%7E").replace("/", "%2F");
|
|
||||||
} catch (UnsupportedEncodingException e) {
|
} catch (UnsupportedEncodingException e) {
|
||||||
throw new AuthException("Failed To Encode Uri", e);
|
throw new AuthException("Failed To Encode Uri", e);
|
||||||
}
|
}
|
||||||
@ -65,7 +62,7 @@ public class GlobalAuthUtil {
|
|||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
return URLDecoder.decode(value, GlobalAuthUtil.DEFAULT_ENCODING);
|
return URLDecoder.decode(value, GlobalAuthUtil.DEFAULT_ENCODING.displayName());
|
||||||
} catch (UnsupportedEncodingException e) {
|
} catch (UnsupportedEncodingException e) {
|
||||||
throw new AuthException("Failed To Decode Uri", e);
|
throw new AuthException("Failed To Decode Uri", e);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -87,7 +87,7 @@ public class UrlBuilder {
|
|||||||
private static final String MICROSOFT_USER_INFO_PATTERN = "{0}";
|
private static final String MICROSOFT_USER_INFO_PATTERN = "{0}";
|
||||||
private static final String MICROSOFT_REFRESH_TOKEN_PATTERN = "{0}?client_id={1}&client_secret={2}&scope=user.read%20mail.read&redirect_uri={3}&refresh_token={4}&grant_type=refresh_token";
|
private static final String MICROSOFT_REFRESH_TOKEN_PATTERN = "{0}?client_id={1}&client_secret={2}&scope=user.read%20mail.read&redirect_uri={3}&refresh_token={4}&grant_type=refresh_token";
|
||||||
|
|
||||||
private static final String MI_AUTHORIZE_PATTERN = "{0}?client_id={1}&redirect_uri={2}&response_type=code&scope=user/profile%20user/openIdV2%20user/phoneAndEmail&state={3}&skip_confirm=false";
|
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";
|
private static final String MI_ACCESS_TOKEN_PATTERN = "{0}?client_id={1}&client_secret={2}&redirect_uri={3}&code={4}&grant_type=authorization_code";
|
||||||
private static final String MI_USER_INFO_PATTERN = "{0}?clientId={1}&token={2}";
|
private static final String MI_USER_INFO_PATTERN = "{0}?clientId={1}&token={2}";
|
||||||
private static final String MI_REFRESH_TOKEN_PATTERN = "{0}?client_id={1}&client_secret={2}&redirect_uri={3}&refresh_token={4}&grant_type=refresh_token";
|
private static final String MI_REFRESH_TOKEN_PATTERN = "{0}?client_id={1}&client_secret={2}&redirect_uri={3}&refresh_token={4}&grant_type=refresh_token";
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user