Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
晓序
JustAuth
提交
739fa786
J
JustAuth
项目概览
晓序
/
JustAuth
与 Fork 源项目一致
Fork自
justauth / JustAuth
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
J
JustAuth
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
739fa786
编写于
6月 22, 2019
作者:
智布道
👁
提交者:
GitHub
6月 22, 2019
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #15 from xkcoding/patch-4
调整部分代码
上级
12ec6226
6f1cead8
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
16 addition
and
20 deletion
+16
-20
src/main/java/me/zhyd/oauth/request/AuthBaiduRequest.java
src/main/java/me/zhyd/oauth/request/AuthBaiduRequest.java
+2
-2
src/main/java/me/zhyd/oauth/request/AuthDingTalkRequest.java
src/main/java/me/zhyd/oauth/request/AuthDingTalkRequest.java
+3
-4
src/main/java/me/zhyd/oauth/request/AuthMiRequest.java
src/main/java/me/zhyd/oauth/request/AuthMiRequest.java
+2
-2
src/main/java/me/zhyd/oauth/utils/GlobalAuthUtil.java
src/main/java/me/zhyd/oauth/utils/GlobalAuthUtil.java
+8
-11
src/main/java/me/zhyd/oauth/utils/UrlBuilder.java
src/main/java/me/zhyd/oauth/utils/UrlBuilder.java
+1
-1
未找到文件。
src/main/java/me/zhyd/oauth/request/AuthBaiduRequest.java
浏览文件 @
739fa786
...
...
@@ -29,7 +29,7 @@ public class AuthBaiduRequest extends BaseAuthRequest {
HttpResponse
response
=
HttpRequest
.
post
(
accessTokenUrl
).
execute
();
JSONObject
accessTokenObject
=
JSONObject
.
parseObject
(
response
.
body
());
AuthBaiduErrorCode
errorCode
=
AuthBaiduErrorCode
.
getErrorCode
(
accessTokenObject
.
getString
(
"error"
));
if
(
!
AuthBaiduErrorCode
.
OK
.
equals
(
errorCode
)
)
{
if
(
AuthBaiduErrorCode
.
OK
!=
errorCode
)
{
throw
new
AuthException
(
errorCode
.
getDesc
());
}
return
AuthToken
.
builder
().
accessToken
(
accessTokenObject
.
getString
(
"access_token"
)).
build
();
...
...
@@ -42,7 +42,7 @@ public class AuthBaiduRequest extends BaseAuthRequest {
String
userInfo
=
response
.
body
();
JSONObject
object
=
JSONObject
.
parseObject
(
userInfo
);
AuthBaiduErrorCode
errorCode
=
AuthBaiduErrorCode
.
getErrorCode
(
object
.
getString
(
"error"
));
if
(
!
AuthBaiduErrorCode
.
OK
.
equals
(
errorCode
)
)
{
if
(
AuthBaiduErrorCode
.
OK
!=
errorCode
)
{
throw
new
AuthException
(
errorCode
.
getDesc
());
}
return
AuthUser
.
builder
()
...
...
src/main/java/me/zhyd/oauth/request/AuthDingTalkRequest.java
浏览文件 @
739fa786
...
...
@@ -40,13 +40,12 @@ public class AuthDingTalkRequest extends BaseAuthRequest {
String
urlEncodeSignature
=
GlobalAuthUtil
.
generateDingTalkSignature
(
config
.
getClientSecret
(),
timestamp
);
JSONObject
param
=
new
JSONObject
();
param
.
put
(
"tmp_auth_code"
,
code
);
HttpResponse
response
=
HttpRequest
.
post
(
UrlBuilder
.
getDingTalkUserInfoUrl
(
urlEncodeSignature
,
timestamp
,
config
.
getClientId
()))
.
body
(
param
.
toJSONString
())
.
execute
();
HttpResponse
response
=
HttpRequest
.
post
(
UrlBuilder
.
getDingTalkUserInfoUrl
(
urlEncodeSignature
,
timestamp
,
config
.
getClientId
())).
body
(
param
.
toJSONString
()).
execute
();
String
userInfo
=
response
.
body
();
JSONObject
object
=
JSON
.
parseObject
(
userInfo
);
AuthDingTalkErrorCode
errorCode
=
AuthDingTalkErrorCode
.
getErrorCode
(
object
.
getIntValue
(
"errcode"
));
if
(
!
AuthDingTalkErrorCode
.
EC0
.
equals
(
errorCode
)
)
{
if
(
AuthDingTalkErrorCode
.
EC0
!=
errorCode
)
{
throw
new
AuthException
(
errorCode
.
getDesc
());
}
object
=
object
.
getJSONObject
(
"user_info"
);
...
...
src/main/java/me/zhyd/oauth/request/AuthMiRequest.java
浏览文件 @
739fa786
...
...
@@ -63,7 +63,7 @@ public class AuthMiRequest extends BaseAuthRequest {
.
execute
();
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"
));
}
...
...
@@ -86,7 +86,7 @@ public class AuthMiRequest extends BaseAuthRequest {
HttpResponse
emailResponse
=
HttpRequest
.
get
(
emailPhoneUrl
).
execute
();
JSONObject
userEmailPhone
=
JSONObject
.
parseObject
(
emailResponse
.
body
());
if
(!
StrUtil
.
equalsIgnoreCase
(
userEmailPhone
.
getString
(
"result"
),
"error"
))
{
if
(!
"error"
.
equalsIgnoreCase
(
userEmailPhone
.
getString
(
"result"
)
))
{
JSONObject
emailPhone
=
userEmailPhone
.
getJSONObject
(
"data"
);
authUser
.
setEmail
(
emailPhone
.
getString
(
"email"
));
}
...
...
src/main/java/me/zhyd/oauth/utils/GlobalAuthUtil.java
浏览文件 @
739fa786
...
...
@@ -8,6 +8,8 @@ import javax.crypto.spec.SecretKeySpec;
import
java.io.UnsupportedEncodingException
;
import
java.net.URLDecoder
;
import
java.net.URLEncoder
;
import
java.nio.charset.Charset
;
import
java.nio.charset.StandardCharsets
;
import
java.security.InvalidKeyException
;
import
java.security.NoSuchAlgorithmException
;
import
java.util.Arrays
;
...
...
@@ -22,16 +24,12 @@ import java.util.Map;
* @since 1.8
*/
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"
;
public
static
String
generateDingTalkSignature
(
String
secretKey
,
String
timestamp
)
{
try
{
byte
[]
signData
=
sign
(
secretKey
.
getBytes
(
DEFAULT_ENCODING
),
timestamp
.
getBytes
(
DEFAULT_ENCODING
));
return
urlEncode
(
new
String
(
Base64
.
encode
(
signData
,
false
)));
}
catch
(
UnsupportedEncodingException
ex
)
{
throw
new
AuthException
(
"Unsupported algorithm: "
+
DEFAULT_ENCODING
,
ex
);
}
byte
[]
signData
=
sign
(
secretKey
.
getBytes
(
DEFAULT_ENCODING
),
timestamp
.
getBytes
(
DEFAULT_ENCODING
));
return
urlEncode
(
new
String
(
Base64
.
encode
(
signData
,
false
)));
}
private
static
byte
[]
sign
(
byte
[]
key
,
byte
[]
data
)
{
...
...
@@ -52,9 +50,8 @@ public class GlobalAuthUtil {
}
try
{
String
encoded
=
URLEncoder
.
encode
(
value
,
GlobalAuthUtil
.
DEFAULT_ENCODING
);
return
encoded
.
replace
(
"+"
,
"%20"
).
replace
(
"*"
,
"%2A"
)
.
replace
(
"~"
,
"%7E"
).
replace
(
"/"
,
"%2F"
);
String
encoded
=
URLEncoder
.
encode
(
value
,
GlobalAuthUtil
.
DEFAULT_ENCODING
.
displayName
());
return
encoded
.
replace
(
"+"
,
"%20"
).
replace
(
"*"
,
"%2A"
).
replace
(
"~"
,
"%7E"
).
replace
(
"/"
,
"%2F"
);
}
catch
(
UnsupportedEncodingException
e
)
{
throw
new
AuthException
(
"Failed To Encode Uri"
,
e
);
}
...
...
@@ -65,7 +62,7 @@ public class GlobalAuthUtil {
return
""
;
}
try
{
return
URLDecoder
.
decode
(
value
,
GlobalAuthUtil
.
DEFAULT_ENCODING
);
return
URLDecoder
.
decode
(
value
,
GlobalAuthUtil
.
DEFAULT_ENCODING
.
displayName
()
);
}
catch
(
UnsupportedEncodingException
e
)
{
throw
new
AuthException
(
"Failed To Decode Uri"
,
e
);
}
...
...
src/main/java/me/zhyd/oauth/utils/UrlBuilder.java
浏览文件 @
739fa786
...
...
@@ -87,7 +87,7 @@ public class UrlBuilder {
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
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_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"
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录