Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
justauth
JustAuth
提交
350f9d70
J
JustAuth
项目概览
justauth
/
JustAuth
大约 1 年 前同步成功
通知
379
Star
15211
Fork
2709
代码
文件
提交
分支
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,发现更多精彩内容 >>
未验证
提交
350f9d70
编写于
7月 18, 2019
作者:
智布道
👁
提交者:
GitHub
7月 18, 2019
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #19 from pengisgood/dev
Integrate Renren
上级
267200c4
0ed3092d
变更
15
显示空白变更内容
内联
并排
Showing
15 changed file
with
184 addition
and
18 deletion
+184
-18
src/main/java/me/zhyd/oauth/config/AuthSource.java
src/main/java/me/zhyd/oauth/config/AuthSource.java
+26
-1
src/main/java/me/zhyd/oauth/model/AuthUserGender.java
src/main/java/me/zhyd/oauth/model/AuthUserGender.java
+6
-6
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/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/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
+1
-1
src/main/java/me/zhyd/oauth/request/AuthGoogleRequest.java
src/main/java/me/zhyd/oauth/request/AuthGoogleRequest.java
+1
-1
src/main/java/me/zhyd/oauth/request/AuthLinkedinRequest.java
src/main/java/me/zhyd/oauth/request/AuthLinkedinRequest.java
+1
-1
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/AuthRenrenRequest.java
src/main/java/me/zhyd/oauth/request/AuthRenrenRequest.java
+92
-0
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/url/AuthRenrenUrlBuilder.java
src/main/java/me/zhyd/oauth/url/AuthRenrenUrlBuilder.java
+49
-0
未找到文件。
src/main/java/me/zhyd/oauth/config/AuthSource.java
浏览文件 @
350f9d70
...
...
@@ -444,6 +444,31 @@ public enum AuthSource {
public
String
userInfo
()
{
return
"https://api.teambition.com/users/me"
;
}
},
/**
* 人人网
*/
RENREN
{
@Override
public
String
authorize
()
{
return
"https://graph.renren.com/oauth/authorize"
;
}
@Override
public
String
accessToken
()
{
return
"https://graph.renren.com/oauth/token"
;
}
@Override
public
String
refresh
()
{
return
"https://graph.renren.com/oauth/token"
;
}
@Override
public
String
userInfo
()
{
return
"https://api.renren.com/v2/user/get"
;
}
};
/**
...
...
src/main/java/me/zhyd/oauth/model/AuthUserGender.java
浏览文件 @
350f9d70
...
...
@@ -10,7 +10,7 @@ import java.util.Arrays;
* @since 1.8
*/
public
enum
AuthUserGender
{
MALE
(
1
,
"男"
),
FEMALE
(
0
,
"女"
),
UNKNOW
(-
1
,
"未知"
);
MALE
(
1
,
"男"
),
FEMALE
(
0
,
"女"
),
UNKNOW
N
(-
1
,
"未知"
);
private
int
code
;
private
String
desc
;
...
...
@@ -21,17 +21,17 @@ public enum AuthUserGender {
public
static
AuthUserGender
getRealGender
(
String
code
)
{
if
(
code
==
null
)
{
return
UNKNOW
;
return
UNKNOW
N
;
}
String
[]
males
=
{
"m"
,
"男"
,
"1"
,
"male"
,
"F"
};
if
(
Arrays
.
asList
(
males
).
contains
(
code
))
{
String
[]
males
=
{
"m"
,
"男"
,
"1"
,
"male"
};
if
(
Arrays
.
asList
(
males
).
contains
(
code
.
toLowerCase
()
))
{
return
MALE
;
}
String
[]
females
=
{
"f"
,
"女"
,
"0"
,
"female"
};
if
(
Arrays
.
asList
(
females
).
contains
(
code
))
{
if
(
Arrays
.
asList
(
females
).
contains
(
code
.
toLowerCase
()
))
{
return
FEMALE
;
}
return
UNKNOW
;
return
UNKNOW
N
;
}
public
int
getCode
()
{
...
...
src/main/java/me/zhyd/oauth/request/AuthCsdnRequest.java
浏览文件 @
350f9d70
...
...
@@ -53,7 +53,7 @@ public class AuthCsdnRequest extends AuthDefaultRequest {
.
username
(
object
.
getString
(
"username"
))
.
remark
(
object
.
getString
(
"description"
))
.
blog
(
object
.
getString
(
"website"
))
.
gender
(
AuthUserGender
.
UNKNOW
)
.
gender
(
AuthUserGender
.
UNKNOW
N
)
.
token
(
authToken
)
.
source
(
AuthSource
.
CSDN
)
.
build
();
...
...
src/main/java/me/zhyd/oauth/request/AuthDingTalkRequest.java
浏览文件 @
350f9d70
...
...
@@ -63,7 +63,7 @@ public class AuthDingTalkRequest extends AuthDefaultRequest {
.
uuid
(
object
.
getString
(
"unionid"
))
.
nickname
(
object
.
getString
(
"nick"
))
.
username
(
object
.
getString
(
"nick"
))
.
gender
(
AuthUserGender
.
UNKNOW
)
.
gender
(
AuthUserGender
.
UNKNOW
N
)
.
source
(
AuthSource
.
DINGTALK
)
.
token
(
token
)
.
build
();
...
...
src/main/java/me/zhyd/oauth/request/AuthDouyinRequest.java
浏览文件 @
350f9d70
...
...
@@ -49,7 +49,7 @@ public class AuthDouyinRequest extends AuthDefaultRequest {
.
nickname
(
userInfoObject
.
getString
(
"nickname"
))
.
avatar
(
userInfoObject
.
getString
(
"avatar"
))
.
remark
(
userInfoObject
.
getString
(
"description"
))
.
gender
(
AuthUserGender
.
UNKNOW
)
.
gender
(
AuthUserGender
.
UNKNOW
N
)
.
token
(
authToken
)
.
source
(
AuthSource
.
DOUYIN
)
.
build
();
...
...
src/main/java/me/zhyd/oauth/request/AuthGiteeRequest.java
浏览文件 @
350f9d70
...
...
@@ -55,7 +55,7 @@ public class AuthGiteeRequest extends AuthDefaultRequest {
.
location
(
object
.
getString
(
"address"
))
.
email
(
object
.
getString
(
"email"
))
.
remark
(
object
.
getString
(
"bio"
))
.
gender
(
AuthUserGender
.
UNKNOW
)
.
gender
(
AuthUserGender
.
UNKNOW
N
)
.
token
(
authToken
)
.
source
(
AuthSource
.
GITEE
)
.
build
();
...
...
src/main/java/me/zhyd/oauth/request/AuthGithubRequest.java
浏览文件 @
350f9d70
...
...
@@ -58,7 +58,7 @@ public class AuthGithubRequest extends AuthDefaultRequest {
.
location
(
object
.
getString
(
"location"
))
.
email
(
object
.
getString
(
"email"
))
.
remark
(
object
.
getString
(
"bio"
))
.
gender
(
AuthUserGender
.
UNKNOW
)
.
gender
(
AuthUserGender
.
UNKNOW
N
)
.
token
(
authToken
)
.
source
(
AuthSource
.
GITHUB
)
.
build
();
...
...
src/main/java/me/zhyd/oauth/request/AuthGoogleRequest.java
浏览文件 @
350f9d70
...
...
@@ -61,7 +61,7 @@ public class AuthGoogleRequest extends AuthDefaultRequest {
.
nickname
(
object
.
getString
(
"name"
))
.
location
(
object
.
getString
(
"locale"
))
.
email
(
object
.
getString
(
"email"
))
.
gender
(
AuthUserGender
.
UNKNOW
)
.
gender
(
AuthUserGender
.
UNKNOW
N
)
.
token
(
authToken
)
.
source
(
AuthSource
.
GOOGLE
)
.
build
();
...
...
src/main/java/me/zhyd/oauth/request/AuthLinkedinRequest.java
浏览文件 @
350f9d70
...
...
@@ -81,7 +81,7 @@ public class AuthLinkedinRequest extends AuthDefaultRequest {
.
avatar
(
avatar
)
.
email
(
email
)
.
token
(
authToken
)
.
gender
(
AuthUserGender
.
UNKNOW
)
.
gender
(
AuthUserGender
.
UNKNOW
N
)
.
source
(
AuthSource
.
LINKEDIN
)
.
build
();
}
...
...
src/main/java/me/zhyd/oauth/request/AuthMiRequest.java
浏览文件 @
350f9d70
...
...
@@ -78,7 +78,7 @@ public class AuthMiRequest extends AuthDefaultRequest {
.
nickname
(
user
.
getString
(
"miliaoNick"
))
.
avatar
(
user
.
getString
(
"miliaoIcon"
))
.
email
(
user
.
getString
(
"mail"
))
.
gender
(
AuthUserGender
.
UNKNOW
)
.
gender
(
AuthUserGender
.
UNKNOW
N
)
.
token
(
authToken
)
.
source
(
AuthSource
.
MI
)
.
build
();
...
...
src/main/java/me/zhyd/oauth/request/AuthMicrosoftRequest.java
浏览文件 @
350f9d70
...
...
@@ -83,7 +83,7 @@ public class AuthMicrosoftRequest extends AuthDefaultRequest {
.
nickname
(
object
.
getString
(
"displayName"
))
.
location
(
object
.
getString
(
"officeLocation"
))
.
email
(
object
.
getString
(
"mail"
))
.
gender
(
AuthUserGender
.
UNKNOW
)
.
gender
(
AuthUserGender
.
UNKNOW
N
)
.
token
(
authToken
)
.
source
(
AuthSource
.
MICROSOFT
)
.
build
();
...
...
src/main/java/me/zhyd/oauth/request/AuthRenrenRequest.java
0 → 100644
浏览文件 @
350f9d70
package
me.zhyd.oauth.request
;
import
cn.hutool.http.HttpRequest
;
import
cn.hutool.http.HttpResponse
;
import
com.alibaba.fastjson.JSONArray
;
import
com.alibaba.fastjson.JSONObject
;
import
me.zhyd.oauth.config.AuthConfig
;
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.model.AuthUserGender
;
import
me.zhyd.oauth.url.AuthRenrenUrlBuilder
;
import
me.zhyd.oauth.url.entity.AuthUserInfoEntity
;
import
java.util.Objects
;
import
static
me
.
zhyd
.
oauth
.
config
.
AuthSource
.
RENREN
;
/**
* 人人登录
*
* @author hongwei.peng (pengisgood(at)gmail(dot)com)
* @version 1.8.1
* @since 1.8.1
*/
public
class
AuthRenrenRequest
extends
AuthDefaultRequest
{
public
AuthRenrenRequest
(
AuthConfig
config
)
{
super
(
config
,
RENREN
,
new
AuthRenrenUrlBuilder
());
}
@Override
protected
AuthToken
getAccessToken
(
AuthCallback
authCallback
)
{
String
accessTokenUrl
=
this
.
urlBuilder
.
getAccessTokenUrl
(
authCallback
.
getCode
());
HttpResponse
response
=
HttpRequest
.
post
(
accessTokenUrl
).
execute
();
JSONObject
accessTokenObject
=
JSONObject
.
parseObject
(
response
.
body
());
if
(!
response
.
isOk
())
{
throw
new
AuthException
(
"Unable to get token from renren using code ["
+
authCallback
.
getCode
()
+
"]: "
+
accessTokenObject
);
}
return
AuthToken
.
builder
()
.
accessToken
(
accessTokenObject
.
getString
(
"access_token"
))
.
refreshToken
(
accessTokenObject
.
getString
(
"refresh_token"
))
.
openId
(
accessTokenObject
.
getJSONObject
(
"user"
).
getString
(
"id"
))
.
build
();
}
@Override
protected
AuthUser
getUserInfo
(
AuthToken
authToken
)
{
String
accessToken
=
authToken
.
getAccessToken
();
HttpResponse
response
=
HttpRequest
.
get
(
this
.
urlBuilder
.
getUserInfoUrl
(
AuthUserInfoEntity
.
builder
()
.
openId
(
authToken
.
getOpenId
())
.
accessToken
(
accessToken
)
.
build
())).
execute
();
JSONObject
userObj
=
JSONObject
.
parseObject
(
response
.
body
()).
getJSONObject
(
"response"
);
return
AuthUser
.
builder
()
.
uuid
(
userObj
.
getString
(
"id"
))
.
avatar
(
getAvatarUrl
(
userObj
))
.
nickname
(
userObj
.
getString
(
"name"
))
.
company
(
getCompany
(
userObj
))
.
gender
(
getGender
(
userObj
))
.
token
(
authToken
)
.
source
(
RENREN
)
.
build
();
}
private
String
getAvatarUrl
(
JSONObject
userObj
)
{
JSONArray
jsonArray
=
userObj
.
getJSONArray
(
"avatar"
);
if
(
Objects
.
isNull
(
jsonArray
)
||
jsonArray
.
isEmpty
())
{
return
null
;
}
return
jsonArray
.
getJSONObject
(
0
).
getString
(
"url"
);
}
private
AuthUserGender
getGender
(
JSONObject
userObj
)
{
JSONObject
basicInformation
=
userObj
.
getJSONObject
(
"basicInformation"
);
if
(
Objects
.
isNull
(
basicInformation
))
{
return
AuthUserGender
.
UNKNOWN
;
}
return
AuthUserGender
.
getRealGender
(
basicInformation
.
getString
(
"sex"
));
}
private
String
getCompany
(
JSONObject
userObj
)
{
JSONArray
jsonArray
=
userObj
.
getJSONArray
(
"work"
);
if
(
Objects
.
isNull
(
jsonArray
)
||
jsonArray
.
isEmpty
())
{
return
null
;
}
return
jsonArray
.
getJSONObject
(
0
).
getString
(
"name"
);
}
}
src/main/java/me/zhyd/oauth/request/AuthTaobaoRequest.java
浏览文件 @
350f9d70
...
...
@@ -47,7 +47,7 @@ public class AuthTaobaoRequest extends AuthDefaultRequest {
.
uuid
(
accessTokenObject
.
getString
(
"taobao_user_id"
))
.
username
(
nick
)
.
nickname
(
nick
)
.
gender
(
AuthUserGender
.
UNKNOW
)
.
gender
(
AuthUserGender
.
UNKNOW
N
)
.
token
(
authToken
)
.
source
(
AuthSource
.
TAOBAO
)
.
build
();
...
...
src/main/java/me/zhyd/oauth/request/AuthTeambitionRequest.java
浏览文件 @
350f9d70
...
...
@@ -66,7 +66,7 @@ public class AuthTeambitionRequest extends AuthDefaultRequest {
.
blog
(
object
.
getString
(
"website"
))
.
location
(
object
.
getString
(
"location"
))
.
email
(
object
.
getString
(
"email"
))
.
gender
(
AuthUserGender
.
UNKNOW
)
.
gender
(
AuthUserGender
.
UNKNOW
N
)
.
token
(
authToken
)
.
source
(
AuthSource
.
TEAMBITION
)
.
build
();
...
...
src/main/java/me/zhyd/oauth/url/AuthRenrenUrlBuilder.java
0 → 100644
浏览文件 @
350f9d70
package
me.zhyd.oauth.url
;
import
me.zhyd.oauth.exception.AuthException
;
import
me.zhyd.oauth.model.AuthResponseStatus
;
import
me.zhyd.oauth.url.entity.AuthUserInfoEntity
;
import
java.text.MessageFormat
;
import
static
me
.
zhyd
.
oauth
.
config
.
AuthSource
.
RENREN
;
/**
* 人人网相关的URL构建类
*
* @author hongwei.peng (pengisgood(at)gmail(dot)com)
* @version 1.8.1
* @since 1.8.1
*/
public
class
AuthRenrenUrlBuilder
extends
AuthDefaultUrlBuilder
{
private
static
final
String
RENREN_ACCESS_TOKEN_PATTERN
=
"{0}?client_id={1}&client_secret={2}&grant_type=authorization_code&code={3}&redirect_uri={4}"
;
private
static
final
String
RENREN_USER_INFO_PATTERN
=
"{0}?access_token={1}&userId={2}"
;
private
static
final
String
RENREN_AUTHORIZE_PATTERN
=
"{0}?client_id={1}&response_type=code&redirect_uri={2}&state={3}"
;
private
static
final
String
RENREN_REFRESH_PATTERN
=
"{0}?refresh_token={1}&client_id={2}&client_secret={3}&grant_type=refresh_token"
;
@Override
public
String
getAccessTokenUrl
(
String
code
)
{
return
MessageFormat
.
format
(
RENREN_ACCESS_TOKEN_PATTERN
,
RENREN
.
accessToken
(),
config
.
getClientId
(),
config
.
getClientSecret
(),
code
,
config
.
getRedirectUri
());
}
@Override
public
String
getUserInfoUrl
(
AuthUserInfoEntity
userInfoEntity
)
{
return
MessageFormat
.
format
(
RENREN_USER_INFO_PATTERN
,
RENREN
.
userInfo
(),
userInfoEntity
.
getAccessToken
(),
userInfoEntity
.
getOpenId
());
}
@Override
public
String
getAuthorizeUrl
()
{
return
MessageFormat
.
format
(
RENREN_AUTHORIZE_PATTERN
,
RENREN
.
authorize
(),
config
.
getClientId
(),
config
.
getRedirectUri
(),
this
.
getRealState
(
config
.
getState
()));
}
@Override
public
String
getRefreshUrl
(
String
refreshToken
)
{
return
MessageFormat
.
format
(
RENREN_REFRESH_PATTERN
,
RENREN
.
refresh
(),
refreshToken
,
config
.
getClientId
(),
config
.
getClientSecret
());
}
@Override
public
String
getRevokeUrl
(
String
accessToken
)
{
throw
new
AuthException
(
AuthResponseStatus
.
UNSUPPORTED
);
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录