Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
justauth
JustAuth
提交
53df9924
J
JustAuth
项目概览
justauth
/
JustAuth
1 年多 前同步成功
通知
391
Star
15212
Fork
2708
代码
文件
提交
分支
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看板
提交
53df9924
编写于
7月 19, 2019
作者:
智布道
👁
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
⚡
优化代码、修复google获取用户信息失败的问题
上级
e29df531
变更
26
隐藏空白更改
内联
并排
Showing
26 changed file
with
55 addition
and
40 deletion
+55
-40
src/main/java/me/zhyd/oauth/config/AuthSource.java
src/main/java/me/zhyd/oauth/config/AuthSource.java
+1
-1
src/main/java/me/zhyd/oauth/request/AuthAlipayRequest.java
src/main/java/me/zhyd/oauth/request/AuthAlipayRequest.java
+1
-1
src/main/java/me/zhyd/oauth/request/AuthBaiduRequest.java
src/main/java/me/zhyd/oauth/request/AuthBaiduRequest.java
+8
-2
src/main/java/me/zhyd/oauth/request/AuthCodingRequest.java
src/main/java/me/zhyd/oauth/request/AuthCodingRequest.java
+1
-1
src/main/java/me/zhyd/oauth/request/AuthCsdnRequest.java
src/main/java/me/zhyd/oauth/request/AuthCsdnRequest.java
+1
-1
src/main/java/me/zhyd/oauth/request/AuthDefaultRequest.java
src/main/java/me/zhyd/oauth/request/AuthDefaultRequest.java
+0
-1
src/main/java/me/zhyd/oauth/request/AuthDingTalkRequest.java
src/main/java/me/zhyd/oauth/request/AuthDingTalkRequest.java
+1
-1
src/main/java/me/zhyd/oauth/request/AuthDouyinRequest.java
src/main/java/me/zhyd/oauth/request/AuthDouyinRequest.java
+1
-1
src/main/java/me/zhyd/oauth/request/AuthFacebookRequest.java
src/main/java/me/zhyd/oauth/request/AuthFacebookRequest.java
+1
-1
src/main/java/me/zhyd/oauth/request/AuthGiteeRequest.java
src/main/java/me/zhyd/oauth/request/AuthGiteeRequest.java
+1
-1
src/main/java/me/zhyd/oauth/request/AuthGithubRequest.java
src/main/java/me/zhyd/oauth/request/AuthGithubRequest.java
+15
-10
src/main/java/me/zhyd/oauth/request/AuthGoogleRequest.java
src/main/java/me/zhyd/oauth/request/AuthGoogleRequest.java
+9
-5
src/main/java/me/zhyd/oauth/request/AuthMiRequest.java
src/main/java/me/zhyd/oauth/request/AuthMiRequest.java
+1
-1
src/main/java/me/zhyd/oauth/request/AuthMicrosoftRequest.java
...main/java/me/zhyd/oauth/request/AuthMicrosoftRequest.java
+1
-1
src/main/java/me/zhyd/oauth/request/AuthOschinaRequest.java
src/main/java/me/zhyd/oauth/request/AuthOschinaRequest.java
+1
-1
src/main/java/me/zhyd/oauth/request/AuthPinterestRequest.java
...main/java/me/zhyd/oauth/request/AuthPinterestRequest.java
+1
-1
src/main/java/me/zhyd/oauth/request/AuthQqRequest.java
src/main/java/me/zhyd/oauth/request/AuthQqRequest.java
+1
-1
src/main/java/me/zhyd/oauth/request/AuthRenrenRequest.java
src/main/java/me/zhyd/oauth/request/AuthRenrenRequest.java
+1
-1
src/main/java/me/zhyd/oauth/request/AuthStackOverflowRequest.java
.../java/me/zhyd/oauth/request/AuthStackOverflowRequest.java
+1
-1
src/main/java/me/zhyd/oauth/request/AuthTaobaoRequest.java
src/main/java/me/zhyd/oauth/request/AuthTaobaoRequest.java
+1
-1
src/main/java/me/zhyd/oauth/request/AuthTeambitionRequest.java
...ain/java/me/zhyd/oauth/request/AuthTeambitionRequest.java
+1
-1
src/main/java/me/zhyd/oauth/request/AuthTencentCloudRequest.java
...n/java/me/zhyd/oauth/request/AuthTencentCloudRequest.java
+1
-1
src/main/java/me/zhyd/oauth/request/AuthToutiaoRequest.java
src/main/java/me/zhyd/oauth/request/AuthToutiaoRequest.java
+1
-1
src/main/java/me/zhyd/oauth/request/AuthWeChatRequest.java
src/main/java/me/zhyd/oauth/request/AuthWeChatRequest.java
+1
-1
src/main/java/me/zhyd/oauth/request/AuthWeiboRequest.java
src/main/java/me/zhyd/oauth/request/AuthWeiboRequest.java
+1
-1
update.md
update.md
+2
-1
未找到文件。
src/main/java/me/zhyd/oauth/config/AuthSource.java
浏览文件 @
53df9924
...
...
@@ -294,7 +294,7 @@ public enum AuthSource {
@Override
public
String
userInfo
()
{
return
"https://
oauth2.googleapis.com/token
info"
;
return
"https://
www.googleapis.com/oauth2/v3/user
info"
;
}
},
/**
...
...
src/main/java/me/zhyd/oauth/request/AuthAlipayRequest.java
浏览文件 @
53df9924
...
...
@@ -81,7 +81,7 @@ public class AuthAlipayRequest extends AuthDefaultRequest {
.
location
(
location
)
.
gender
(
AuthUserGender
.
getRealGender
(
response
.
getGender
()))
.
token
(
authToken
)
.
source
(
AuthSource
.
ALIPAY
)
.
source
(
source
)
.
build
();
}
...
...
src/main/java/me/zhyd/oauth/request/AuthBaiduRequest.java
浏览文件 @
53df9924
...
...
@@ -8,6 +8,7 @@ import me.zhyd.oauth.config.AuthSource;
import
me.zhyd.oauth.enums.AuthUserGender
;
import
me.zhyd.oauth.exception.AuthException
;
import
me.zhyd.oauth.model.*
;
import
me.zhyd.oauth.utils.StringUtils
;
import
me.zhyd.oauth.utils.UrlBuilder
;
/**
...
...
@@ -39,14 +40,19 @@ public class AuthBaiduRequest extends AuthDefaultRequest {
.
uuid
(
object
.
getString
(
"userid"
))
.
username
(
object
.
getString
(
"username"
))
.
nickname
(
object
.
getString
(
"username"
))
.
avatar
(
object
.
getString
(
"portrait"
))
.
avatar
(
getAvatar
(
object
))
.
remark
(
object
.
getString
(
"userdetail"
))
.
gender
(
AuthUserGender
.
getRealGender
(
object
.
getString
(
"sex"
)))
.
token
(
authToken
)
.
source
(
AuthSource
.
BAIDU
)
.
source
(
source
)
.
build
();
}
private
String
getAvatar
(
JSONObject
object
)
{
String
protrait
=
object
.
getString
(
"portrait"
);
return
StringUtils
.
isEmpty
(
protrait
)
?
null
:
String
.
format
(
"http://himg.bdimg.com/sys/portrait/item/%s.jpg"
,
protrait
);
}
@Override
public
AuthResponse
revoke
(
AuthToken
authToken
)
{
HttpResponse
response
=
doGetRevoke
(
authToken
);
...
...
src/main/java/me/zhyd/oauth/request/AuthCodingRequest.java
浏览文件 @
53df9924
...
...
@@ -55,7 +55,7 @@ public class AuthCodingRequest extends AuthDefaultRequest {
.
email
(
object
.
getString
(
"email"
))
.
remark
(
object
.
getString
(
"slogan"
))
.
token
(
authToken
)
.
source
(
AuthSource
.
CODING
)
.
source
(
source
)
.
build
();
}
...
...
src/main/java/me/zhyd/oauth/request/AuthCsdnRequest.java
浏览文件 @
53df9924
...
...
@@ -44,7 +44,7 @@ public class AuthCsdnRequest extends AuthDefaultRequest {
.
blog
(
object
.
getString
(
"website"
))
.
gender
(
AuthUserGender
.
UNKNOWN
)
.
token
(
authToken
)
.
source
(
AuthSource
.
CSDN
)
.
source
(
source
)
.
build
();
}
...
...
src/main/java/me/zhyd/oauth/request/AuthDefaultRequest.java
浏览文件 @
53df9924
...
...
@@ -20,7 +20,6 @@ import me.zhyd.oauth.utils.UrlBuilder;
* @version 1.0
* @since 1.8
*/
@Data
@Slf4j
public
abstract
class
AuthDefaultRequest
implements
AuthRequest
{
protected
AuthConfig
config
;
...
...
src/main/java/me/zhyd/oauth/request/AuthDingTalkRequest.java
浏览文件 @
53df9924
...
...
@@ -52,7 +52,7 @@ public class AuthDingTalkRequest extends AuthDefaultRequest {
.
nickname
(
object
.
getString
(
"nick"
))
.
username
(
object
.
getString
(
"nick"
))
.
gender
(
AuthUserGender
.
UNKNOWN
)
.
source
(
AuthSource
.
DINGTALK
)
.
source
(
source
)
.
token
(
token
)
.
build
();
}
...
...
src/main/java/me/zhyd/oauth/request/AuthDouyinRequest.java
浏览文件 @
53df9924
...
...
@@ -42,7 +42,7 @@ public class AuthDouyinRequest extends AuthDefaultRequest {
.
remark
(
userInfoObject
.
getString
(
"description"
))
.
gender
(
AuthUserGender
.
UNKNOWN
)
.
token
(
authToken
)
.
source
(
AuthSource
.
DOUYIN
)
.
source
(
source
)
.
build
();
}
...
...
src/main/java/me/zhyd/oauth/request/AuthFacebookRequest.java
浏览文件 @
53df9924
...
...
@@ -51,7 +51,7 @@ public class AuthFacebookRequest extends AuthDefaultRequest {
.
email
(
object
.
getString
(
"email"
))
.
gender
(
AuthUserGender
.
getRealGender
(
object
.
getString
(
"gender"
)))
.
token
(
authToken
)
.
source
(
AuthSource
.
FACEBOOK
)
.
source
(
source
)
.
build
();
}
...
...
src/main/java/me/zhyd/oauth/request/AuthGiteeRequest.java
浏览文件 @
53df9924
...
...
@@ -55,7 +55,7 @@ public class AuthGiteeRequest extends AuthDefaultRequest {
.
remark
(
object
.
getString
(
"bio"
))
.
gender
(
AuthUserGender
.
UNKNOWN
)
.
token
(
authToken
)
.
source
(
AuthSource
.
GITEE
)
.
source
(
source
)
.
build
();
}
...
...
src/main/java/me/zhyd/oauth/request/AuthGithubRequest.java
浏览文件 @
53df9924
...
...
@@ -9,6 +9,9 @@ import me.zhyd.oauth.exception.AuthException;
import
me.zhyd.oauth.model.AuthCallback
;
import
me.zhyd.oauth.model.AuthToken
;
import
me.zhyd.oauth.model.AuthUser
;
import
me.zhyd.oauth.utils.GlobalAuthUtil
;
import
java.util.Map
;
/**
* Github登录
...
...
@@ -26,12 +29,14 @@ public class AuthGithubRequest extends AuthDefaultRequest {
@Override
protected
AuthToken
getAccessToken
(
AuthCallback
authCallback
)
{
HttpResponse
response
=
doPostAuthorizationCode
(
authCallback
.
getCode
());
JSONObject
accessTokenObject
=
JSONObject
.
parseObject
(
response
.
body
());
this
.
checkResponse
(
accessTokenObject
);
Map
<
String
,
String
>
res
=
GlobalAuthUtil
.
parseStringToMap
(
response
.
body
());
if
(
res
.
containsKey
(
"error"
))
{
throw
new
AuthException
(
res
.
get
(
"error"
)
+
":"
+
res
.
get
(
"error_description"
));
}
return
AuthToken
.
builder
()
.
accessToken
(
accessTokenObject
.
getString
(
"access_token"
))
.
scope
(
accessTokenObject
.
getString
(
"scope"
))
.
tokenType
(
accessTokenObject
.
getString
(
"token_type"
))
.
accessToken
(
res
.
get
(
"access_token"
))
.
scope
(
res
.
get
(
"scope"
))
.
tokenType
(
res
.
get
(
"token_type"
))
.
build
();
}
...
...
@@ -39,7 +44,9 @@ public class AuthGithubRequest extends AuthDefaultRequest {
protected
AuthUser
getUserInfo
(
AuthToken
authToken
)
{
HttpResponse
response
=
doGetUserInfo
(
authToken
);
JSONObject
object
=
JSONObject
.
parseObject
(
response
.
body
());
this
.
checkResponse
(
object
);
if
(
object
.
containsKey
(
"error"
))
{
throw
new
AuthException
(
object
.
getString
(
"error_description"
));
}
return
AuthUser
.
builder
()
.
uuid
(
object
.
getString
(
"id"
))
.
username
(
object
.
getString
(
"login"
))
...
...
@@ -52,7 +59,7 @@ public class AuthGithubRequest extends AuthDefaultRequest {
.
remark
(
object
.
getString
(
"bio"
))
.
gender
(
AuthUserGender
.
UNKNOWN
)
.
token
(
authToken
)
.
source
(
AuthSource
.
GITHUB
)
.
source
(
source
)
.
build
();
}
...
...
@@ -62,8 +69,6 @@ public class AuthGithubRequest extends AuthDefaultRequest {
* @param object 请求响应内容
*/
private
void
checkResponse
(
JSONObject
object
)
{
if
(
object
.
containsKey
(
"error"
))
{
throw
new
AuthException
(
object
.
getString
(
"error_description"
));
}
}
}
src/main/java/me/zhyd/oauth/request/AuthGoogleRequest.java
浏览文件 @
53df9924
package
me.zhyd.oauth.request
;
import
cn.hutool.http.HttpRequest
;
import
cn.hutool.http.HttpResponse
;
import
com.alibaba.fastjson.JSONObject
;
import
me.zhyd.oauth.config.AuthConfig
;
...
...
@@ -40,25 +41,28 @@ public class AuthGoogleRequest extends AuthDefaultRequest {
@Override
protected
AuthUser
getUserInfo
(
AuthToken
authToken
)
{
HttpResponse
response
=
doGetUserInfo
(
authToken
);
HttpResponse
response
=
HttpRequest
.
post
(
userInfoUrl
(
authToken
))
.
header
(
"Authorization"
,
"Bearer "
+
authToken
.
getAccessToken
())
.
execute
();
String
userInfo
=
response
.
body
();
JSONObject
object
=
JSONObject
.
parseObject
(
userInfo
);
this
.
checkResponse
(
object
);
return
AuthUser
.
builder
()
.
uuid
(
object
.
getString
(
"sub"
))
.
username
(
object
.
getString
(
"
name
"
))
.
username
(
object
.
getString
(
"
email
"
))
.
avatar
(
object
.
getString
(
"picture"
))
.
nickname
(
object
.
getString
(
"name"
))
.
location
(
object
.
getString
(
"locale"
))
.
email
(
object
.
getString
(
"email"
))
.
gender
(
AuthUserGender
.
UNKNOWN
)
.
token
(
authToken
)
.
source
(
AuthSource
.
GOOGLE
)
.
source
(
source
)
.
build
();
}
/**
* 返回认证url,可自行跳转页面
* https://openidconnect.googleapis.com/v1/userinfo
*
* @return 返回授权地址
*/
...
...
@@ -81,7 +85,7 @@ public class AuthGoogleRequest extends AuthDefaultRequest {
*/
@Override
protected
String
userInfoUrl
(
AuthToken
authToken
)
{
return
UrlBuilder
.
fromBaseUrl
(
source
.
userInfo
()).
queryParam
(
"
id
_token"
,
authToken
.
getAccessToken
()).
build
();
return
UrlBuilder
.
fromBaseUrl
(
source
.
userInfo
()).
queryParam
(
"
access
_token"
,
authToken
.
getAccessToken
()).
build
();
}
/**
...
...
@@ -91,7 +95,7 @@ public class AuthGoogleRequest extends AuthDefaultRequest {
*/
private
void
checkResponse
(
JSONObject
object
)
{
if
(
object
.
containsKey
(
"error"
)
||
object
.
containsKey
(
"error_description"
))
{
throw
new
AuthException
(
object
.
getString
(
"error_description"
));
throw
new
AuthException
(
object
.
containsKey
(
"error"
)
+
":"
+
object
.
getString
(
"error_description"
));
}
}
}
src/main/java/me/zhyd/oauth/request/AuthMiRequest.java
浏览文件 @
53df9924
...
...
@@ -75,7 +75,7 @@ public class AuthMiRequest extends AuthDefaultRequest {
.
email
(
user
.
getString
(
"mail"
))
.
gender
(
AuthUserGender
.
UNKNOWN
)
.
token
(
authToken
)
.
source
(
AuthSource
.
MI
)
.
source
(
source
)
.
build
();
// 获取用户邮箱手机号等信息
...
...
src/main/java/me/zhyd/oauth/request/AuthMicrosoftRequest.java
浏览文件 @
53df9924
...
...
@@ -83,7 +83,7 @@ public class AuthMicrosoftRequest extends AuthDefaultRequest {
.
email
(
object
.
getString
(
"mail"
))
.
gender
(
AuthUserGender
.
UNKNOWN
)
.
token
(
authToken
)
.
source
(
AuthSource
.
MICROSOFT
)
.
source
(
source
)
.
build
();
}
...
...
src/main/java/me/zhyd/oauth/request/AuthOschinaRequest.java
浏览文件 @
53df9924
...
...
@@ -52,7 +52,7 @@ public class AuthOschinaRequest extends AuthDefaultRequest {
.
gender
(
AuthUserGender
.
getRealGender
(
object
.
getString
(
"gender"
)))
.
email
(
object
.
getString
(
"email"
))
.
token
(
authToken
)
.
source
(
AuthSource
.
OSCHINA
)
.
source
(
source
)
.
build
();
}
...
...
src/main/java/me/zhyd/oauth/request/AuthPinterestRequest.java
浏览文件 @
53df9924
...
...
@@ -58,7 +58,7 @@ public class AuthPinterestRequest extends AuthDefaultRequest {
.
gender
(
AuthUserGender
.
UNKNOWN
)
.
remark
(
userObj
.
getString
(
"bio"
))
.
token
(
authToken
)
.
source
(
PINTEREST
)
.
source
(
source
)
.
build
();
}
...
...
src/main/java/me/zhyd/oauth/request/AuthQqRequest.java
浏览文件 @
53df9924
...
...
@@ -65,7 +65,7 @@ public class AuthQqRequest extends AuthDefaultRequest {
.
uuid
(
openId
)
.
gender
(
AuthUserGender
.
getRealGender
(
object
.
getString
(
"gender"
)))
.
token
(
authToken
)
.
source
(
AuthSource
.
QQ
)
.
source
(
source
)
.
build
();
}
...
...
src/main/java/me/zhyd/oauth/request/AuthRenrenRequest.java
浏览文件 @
53df9924
...
...
@@ -45,7 +45,7 @@ public class AuthRenrenRequest extends AuthDefaultRequest {
.
company
(
getCompany
(
userObj
))
.
gender
(
getGender
(
userObj
))
.
token
(
authToken
)
.
source
(
RENREN
)
.
source
(
source
)
.
build
();
}
...
...
src/main/java/me/zhyd/oauth/request/AuthStackOverflowRequest.java
浏览文件 @
53df9924
...
...
@@ -63,7 +63,7 @@ public class AuthStackOverflowRequest extends AuthDefaultRequest {
.
blog
(
userObj
.
getString
(
"website_url"
))
.
gender
(
AuthUserGender
.
UNKNOWN
)
.
token
(
authToken
)
.
source
(
STACK_OVERFLOW
)
.
source
(
source
)
.
build
();
}
...
...
src/main/java/me/zhyd/oauth/request/AuthTaobaoRequest.java
浏览文件 @
53df9924
...
...
@@ -50,7 +50,7 @@ public class AuthTaobaoRequest extends AuthDefaultRequest {
.
nickname
(
nick
)
.
gender
(
AuthUserGender
.
UNKNOWN
)
.
token
(
authToken
)
.
source
(
AuthSource
.
TAOBAO
)
.
source
(
source
)
.
build
();
}
...
...
src/main/java/me/zhyd/oauth/request/AuthTeambitionRequest.java
浏览文件 @
53df9924
...
...
@@ -67,7 +67,7 @@ public class AuthTeambitionRequest extends AuthDefaultRequest {
.
email
(
object
.
getString
(
"email"
))
.
gender
(
AuthUserGender
.
UNKNOWN
)
.
token
(
authToken
)
.
source
(
AuthSource
.
TEAMBITION
)
.
source
(
source
)
.
build
();
}
...
...
src/main/java/me/zhyd/oauth/request/AuthTencentCloudRequest.java
浏览文件 @
53df9924
...
...
@@ -55,7 +55,7 @@ public class AuthTencentCloudRequest extends AuthDefaultRequest {
.
email
(
object
.
getString
(
"email"
))
.
remark
(
object
.
getString
(
"slogan"
))
.
token
(
authToken
)
.
source
(
AuthSource
.
TENCENT_CLOUD
)
.
source
(
source
)
.
build
();
}
...
...
src/main/java/me/zhyd/oauth/request/AuthToutiaoRequest.java
浏览文件 @
53df9924
...
...
@@ -60,7 +60,7 @@ public class AuthToutiaoRequest extends AuthDefaultRequest {
.
remark
(
user
.
getString
(
"description"
))
.
gender
(
AuthUserGender
.
getRealGender
(
user
.
getString
(
"gender"
)))
.
token
(
authToken
)
.
source
(
AuthSource
.
TOUTIAO
)
.
source
(
source
)
.
build
();
}
...
...
src/main/java/me/zhyd/oauth/request/AuthWeChatRequest.java
浏览文件 @
53df9924
...
...
@@ -56,7 +56,7 @@ public class AuthWeChatRequest extends AuthDefaultRequest {
.
uuid
(
openId
)
.
gender
(
AuthUserGender
.
getRealGender
(
object
.
getString
(
"sex"
)))
.
token
(
authToken
)
.
source
(
AuthSource
.
WECHAT
)
.
source
(
source
)
.
build
();
}
...
...
src/main/java/me/zhyd/oauth/request/AuthWeiboRequest.java
浏览文件 @
53df9924
...
...
@@ -69,7 +69,7 @@ public class AuthWeiboRequest extends AuthDefaultRequest {
.
remark
(
object
.
getString
(
"description"
))
.
gender
(
AuthUserGender
.
getRealGender
(
object
.
getString
(
"gender"
)))
.
token
(
authToken
)
.
source
(
AuthSource
.
WEIBO
)
.
source
(
source
)
.
build
();
}
...
...
update.md
浏览文件 @
53df9924
...
...
@@ -7,7 +7,8 @@
5.
优化
`AuthConfig`
、
`AuthResponse`
类,去掉不必要的lombonk注解,减少编译后的代码量
6.
使用lombok注解优化枚举类
7.
`AuthQqRequest`
增加refresh方法
8.
优化代码
8.
修复google登录无法获取用户信息的问题
9.
优化代码
### 2019/07/18
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录