Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
justauth
JustAuth
提交
d5189aa3
J
JustAuth
项目概览
justauth
/
JustAuth
12 个月 前同步成功
通知
361
Star
15209
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,发现更多精彩内容 >>
未验证
提交
d5189aa3
编写于
7月 18, 2019
作者:
智布道
👁
提交者:
GitHub
7月 18, 2019
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'dev' into remove-urlbuilder
上级
0d4e52d6
32c540cf
变更
15
隐藏空白更改
内联
并排
Showing
15 changed file
with
375 addition
and
19 deletion
+375
-19
README.md
README.md
+13
-1
developer.md
developer.md
+1
-0
example.md
example.md
+17
-1
pom.xml
pom.xml
+6
-1
src/main/java/me/zhyd/oauth/config/AuthConfig.java
src/main/java/me/zhyd/oauth/config/AuthConfig.java
+7
-0
src/main/java/me/zhyd/oauth/config/AuthSource.java
src/main/java/me/zhyd/oauth/config/AuthSource.java
+40
-0
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/AuthMicrosoftRequest.java
...main/java/me/zhyd/oauth/request/AuthMicrosoftRequest.java
+4
-4
src/main/java/me/zhyd/oauth/request/AuthPinterestRequest.java
...main/java/me/zhyd/oauth/request/AuthPinterestRequest.java
+76
-0
src/main/java/me/zhyd/oauth/request/AuthRenrenRequest.java
src/main/java/me/zhyd/oauth/request/AuthRenrenRequest.java
+29
-11
src/main/java/me/zhyd/oauth/request/AuthStackOverflowRequest.java
.../java/me/zhyd/oauth/request/AuthStackOverflowRequest.java
+68
-0
src/main/java/me/zhyd/oauth/url/AuthPinterestUrlBuilder.java
src/main/java/me/zhyd/oauth/url/AuthPinterestUrlBuilder.java
+48
-0
src/main/java/me/zhyd/oauth/url/AuthStackOverflowUrlBuilder.java
...n/java/me/zhyd/oauth/url/AuthStackOverflowUrlBuilder.java
+48
-0
src/main/java/me/zhyd/oauth/utils/GlobalAuthUtil.java
src/main/java/me/zhyd/oauth/utils/GlobalAuthUtil.java
+8
-0
update.md
update.md
+9
-0
未找到文件。
README.md
浏览文件 @
d5189aa3
...
...
@@ -37,10 +37,18 @@
<td
align=
"center"
width=
"200"
><a
href=
"#授权google"
><img
src=
"https://gitee.com/yadong.zhang/static/raw/master/JustAuth/google.png"
width=
"20"
></a></td>
<td
align=
"center"
width=
"200"
><a
href=
"#授权facebook"
><img
src=
"https://gitee.com/yadong.zhang/static/raw/master/JustAuth/facebook.png"
width=
"20"
></a></td>
<td
align=
"center"
width=
"200"
><a
href=
"#授权抖音"
><img
src=
"https://gitee.com/yadong.zhang/static/raw/master/JustAuth/douyin.png"
width=
"20"
></a></td>
</tr>
</table>
<table>
<tr>
<td
align=
"center"
width=
"200"
><a
href=
"#授权领英"
><img
src=
"https://gitee.com/yadong.zhang/static/raw/master/JustAuth/linkedin.png"
width=
"20"
></a></td>
<td
align=
"center"
width=
"200"
><a
href=
"#授权微软"
><img
src=
"https://gitee.com/yadong.zhang/static/raw/master/JustAuth/microsoft.png"
width=
"20"
></a></td>
<td
align=
"center"
width=
"200"
><a
href=
"#授权小米"
><img
src=
"https://gitee.com/yadong.zhang/static/raw/master/JustAuth/mi.png"
width=
"20"
></a></td>
<td
align=
"center"
width=
"200"
><a
href=
"#授权今日头条"
><img
src=
"https://gitee.com/yadong.zhang/static/raw/master/JustAuth/toutiao.png"
width=
"20"
></a></td>
<td
align=
"center"
width=
"200"
><a
href=
"#授权Teambition"
><img
src=
"https://gitee.com/yadong.zhang/static/raw/master/JustAuth/teambition.png"
width=
"20"
></a></td>
<td
align=
"center"
width=
"200"
><a
href=
"#授权人人"
><img
src=
"https://gitee.com/yadong.zhang/static/raw/master/JustAuth/renren.png"
width=
"20"
></a></td>
<td
align=
"center"
width=
"200"
><a
href=
"#授权Pinterest"
><img
src=
"https://gitee.com/yadong.zhang/static/raw/master/JustAuth/pinterest.png"
width=
"20"
></a></td>
<td
align=
"center"
width=
"200"
><a
href=
"#授权Stack Overflow"
><img
src=
"https://gitee.com/yadong.zhang/static/raw/master/JustAuth/stackoverflow.png"
width=
"20"
></a></td>
<td
align=
"center"
width=
"200"
><a
href=
"#授权csdn"
><img
src=
"https://gitee.com/yadong.zhang/static/raw/master/JustAuth/csdn.png"
width=
"20"
></a></td>
</tr>
</table>
...
...
@@ -120,6 +128,10 @@ authRequest.login(callback);
|
<img
src=
"https://gitee.com/yadong.zhang/static/raw/master/JustAuth/microsoft.png"
width=
"20"
>
|
[
AuthMicrosoftRequest
](
https://gitee.com/yadong.zhang/JustAuth/blob/master/src/main/java/me/zhyd/oauth/request/AuthMicrosoftRequest.java
)
|
<a
href=
"https://docs.microsoft.com/zh-cn/graph/auth/"
target=
"_blank"
>
参考文档
</a>
|
|
<img
src=
"https://gitee.com/yadong.zhang/static/raw/master/JustAuth/mi.png"
width=
"20"
>
|
[
AuthMiRequest
](
https://gitee.com/yadong.zhang/JustAuth/blob/master/src/main/java/me/zhyd/oauth/request/AuthMiRequest.java
)
|
<a
href=
"https://dev.mi.com/console/doc/detail?pId=711"
target=
"_blank"
>
参考文档
</a>
|
|
<img
src=
"https://gitee.com/yadong.zhang/static/raw/master/JustAuth/toutiao.png"
width=
"20"
>
|
[
AuthToutiaoRequest
](
https://gitee.com/yadong.zhang/JustAuth/blob/master/src/main/java/me/zhyd/oauth/request/AuthToutiaoRequest.java
)
|
<a
href=
"https://open.mp.toutiao.com/#/resource?_k=y7mfgk"
target=
"_blank"
>
参考文档
</a>
|
|
<img
src=
"https://gitee.com/yadong.zhang/static/raw/master/JustAuth/teambition.png"
width=
"20"
>
|
[
AuthTeambitionRequest
](
https://gitee.com/yadong.zhang/JustAuth/blob/master/src/main/java/me/zhyd/oauth/request/AuthTeambitionRequest.java
)
|
<a
href=
"https://docs.teambition.com/"
target=
"_blank"
>
参考文档
</a>
|
|
<img
src=
"https://gitee.com/yadong.zhang/static/raw/master/JustAuth/renren.png"
width=
"20"
>
|
[
AuthRenrenRequest
](
https://gitee.com/yadong.zhang/JustAuth/blob/master/src/main/java/me/zhyd/oauth/request/AuthRenrenRequest.java
)
|
<a
href=
"http://open.renren.com/wiki/OAuth2.0"
target=
"_blank"
>
参考文档
</a>
|
|
<img
src=
"https://gitee.com/yadong.zhang/static/raw/master/JustAuth/pinterest.png"
width=
"20"
>
|
[
AuthPinterestRequest
](
https://gitee.com/yadong.zhang/JustAuth/blob/master/src/main/java/me/zhyd/oauth/request/AuthPinterestRequest.java
)
|
<a
href=
"https://developers.pinterest.com/docs/api/overview/?"
target=
"_blank"
>
参考文档
</a>
|
|
<img
src=
"https://gitee.com/yadong.zhang/static/raw/master/JustAuth/stackoverflow.png"
width=
"20"
>
|
[
AuthStackOverflowRequest
](
https://gitee.com/yadong.zhang/JustAuth/blob/master/src/main/java/me/zhyd/oauth/request/AuthStackOverflowRequest.java
)
|
<a
href=
"https://api.stackexchange.com/docs"
target=
"_blank"
>
参考文档
</a>
|
|
<img
src=
"https://gitee.com/yadong.zhang/static/raw/master/JustAuth/csdn.png"
width=
"20"
>
|
[
AuthCsdnRequest
](
https://gitee.com/yadong.zhang/JustAuth/blob/master/src/main/java/me/zhyd/oauth/request/AuthCsdnRequest.java
)
| 无 |
_请知悉:经咨询CSDN官方客服得知,CSDN的授权开放平台已经下线。如果以前申请过的应用,可以继续使用,但是不再支持申请新的应用。so, 本项目中的CSDN登录只能针对少部分用户使用了_
...
...
@@ -168,4 +180,4 @@ _请知悉:经咨询CSDN官方客服得知,CSDN的授权开放平台已经
| 支付宝 | 微信 |
| :------------: | :------------: |
|
<img
src=
"https://gitee.com/yadong.zhang/static/raw/master/qrcode/zfb_code.png"
width=
"200"
/>
|
<img
src=
"https://gitee.com/yadong.zhang/static/raw/master/qrcode/wx_code.png"
width=
"200"
/>
|
\ No newline at end of file
|
<img
src=
"https://gitee.com/yadong.zhang/static/raw/master/qrcode/zfb_code.png"
width=
"200"
/>
|
<img
src=
"https://gitee.com/yadong.zhang/static/raw/master/qrcode/wx_code.png"
width=
"200"
/>
|
developer.md
浏览文件 @
d5189aa3
...
...
@@ -3,4 +3,5 @@
-
<img
src=
"https://avatar.gitee.com/uploads/99/784199_yadong.zhang.png!avatar100?1462325358"
width=
"20"
>
· yadong.zhang :
<a
href=
"https://github.com/zhangyd-c"
target=
"_blank"
>
[Github]
</a>
|
<a
href=
"https://gitee.com/yadong.zhang"
target=
"_blank"
>
[Gitee]
</a>
|
<a
href=
"https://www.zhyd.me"
target=
"_blank"
>
[个人网站]
</a>
-
<img
src=
"https://avatars0.githubusercontent.com/u/10429917?s=460&v=4"
width=
"20"
>
· yangkai.shen :
<a
href=
"https://github.com/xkcoding"
target=
"_blank"
>
[Github]
</a>
|
<a
href=
"https://xkcoding.com"
target=
"_blank"
>
[个人网站]
</a>
-
<img
src=
"https://avatar.gitee.com/uploads/51/1651_dolphinboy.png!avatar100?1479346570"
width=
"20"
>
· skqing :
<a
href=
"https://gitee.com/skqing"
target=
"_blank"
>
[Gitee]
</a>
|
<a
href=
"https://my.oschina.net/dolphinboy"
target=
"_blank"
>
[个人网站]
</a>
-
<img
src=
"https://avatars2.githubusercontent.com/u/2988765?s=115&v=4"
width=
"20"
>
· pengisgood :
<a
href=
"https://github.com/pengisgood"
target=
"_blank"
>
[Github]
</a>
|
<a
href=
"https://pengisgood.github.io"
target=
"_blank"
>
[个人网站]
</a>
-
千年等一回,我只为等你...
example.md
浏览文件 @
d5189aa3
...
...
@@ -80,8 +80,24 @@ _注:非全部平台,部分平台可能不存在图例_
暂无
#### 授权Pinterest
![
授权Pinterest
](
https://images.gitee.com/uploads/images/2019/0718/155012_6290f500_784199.jpeg
"授权Pinterest"
)
#### 授权Renren
![
授权Renre
](
https://images.gitee.com/uploads/images/2019/0718/155035_8e26c10a_784199.jpeg
"授权Renren"
)
#### 授权Stack Overflow
![
授权Stack Overflow
](
https://images.gitee.com/uploads/images/2019/0718/192639_cc301ba7_784199.png
"授权Stack Overflow"
)
#### 授权Twitter
暂无
#### 授权csdn
暂无
_请知悉:经咨询CSDN官方客服得知,CSDN的授权开放平台已经下线。如果以前申请过的应用,可以继续使用,但是不再支持申请新的应用。so, 本项目中的CSDN登录只能针对少部分用户使用了_
\ No newline at end of file
_请知悉:经咨询CSDN官方客服得知,CSDN的授权开放平台已经下线。如果以前申请过的应用,可以继续使用,但是不再支持申请新的应用。so, 本项目中的CSDN登录只能针对少部分用户使用了_
pom.xml
浏览文件 @
d5189aa3
...
...
@@ -30,7 +30,7 @@
<developers>
<developer>
<name>
yadong.z
hang
</name>
<name>
Yadong.Z
hang
</name>
<email>
yadong.zhang0415@gmail.com
</email>
<url>
https://www.zhyd.me
</url>
</developer>
...
...
@@ -39,6 +39,11 @@
<email>
shenyangkai1994@gmail.com
</email>
<url>
https://xkcoding.com
</url>
</developer>
<developer>
<name>
Hongwei.Peng
</name>
<email>
pengisgood@gmail.com
</email>
<url>
https://github.com/pengisgood
</url>
</developer>
</developers>
<properties>
...
...
src/main/java/me/zhyd/oauth/config/AuthConfig.java
浏览文件 @
d5189aa3
...
...
@@ -51,4 +51,11 @@ public class AuthConfig {
* 1.8.0版本新增参数
*/
private
String
state
;
/**
* Stack Overflow Key
* <p>
* 1.9.0版本新增参数
*/
private
String
stackOverflowKey
;
}
src/main/java/me/zhyd/oauth/config/AuthSource.java
浏览文件 @
d5189aa3
...
...
@@ -469,6 +469,46 @@ public enum AuthSource {
public
String
userInfo
()
{
return
"https://api.renren.com/v2/user/get"
;
}
},
/**
* Pinterest
*/
PINTEREST
{
@Override
public
String
authorize
()
{
return
"https://api.pinterest.com/oauth"
;
}
@Override
public
String
accessToken
()
{
return
"https://api.pinterest.com/v1/oauth/token"
;
}
@Override
public
String
userInfo
()
{
return
"https://api.pinterest.com/v1/me"
;
}
},
/**
* Stack Overflow
*/
STACK_OVERFLOW
{
@Override
public
String
authorize
()
{
return
"https://stackoverflow.com/oauth"
;
}
@Override
public
String
accessToken
()
{
return
"https://stackoverflow.com/oauth/access_token/json"
;
}
@Override
public
String
userInfo
()
{
return
"https://api.stackexchange.com/2.2/me"
;
}
};
/**
...
...
src/main/java/me/zhyd/oauth/request/AuthLinkedinRequest.java
浏览文件 @
d5189aa3
...
...
@@ -139,7 +139,7 @@ public class AuthLinkedinRequest extends AuthDefaultRequest {
private
AuthToken
getToken
(
String
accessTokenUrl
)
{
HttpResponse
response
=
HttpRequest
.
post
(
accessTokenUrl
)
.
header
(
"Host"
,
"www.linkedin.com"
)
.
header
(
"Content-Type"
,
"application/x-www-form-urlencoded"
)
.
contentType
(
"application/x-www-form-urlencoded"
)
.
execute
();
String
accessTokenStr
=
response
.
body
();
JSONObject
accessTokenObject
=
JSONObject
.
parseObject
(
accessTokenStr
);
...
...
src/main/java/me/zhyd/oauth/request/AuthMicrosoftRequest.java
浏览文件 @
d5189aa3
...
...
@@ -13,6 +13,8 @@ import me.zhyd.oauth.utils.UrlBuilder;
import
java.util.HashMap
;
import
java.util.Map
;
import
static
me
.
zhyd
.
oauth
.
utils
.
GlobalAuthUtil
.
parseQueryToMap
;
/**
* 微软登录
*
...
...
@@ -37,12 +39,10 @@ public class AuthMicrosoftRequest extends AuthDefaultRequest {
* @return token对象
*/
private
AuthToken
getToken
(
String
accessTokenUrl
)
{
Map
<
String
,
Object
>
paramMap
=
new
HashMap
<>(
6
);
HttpUtil
.
decodeParamMap
(
accessTokenUrl
,
"UTF-8"
).
forEach
(
paramMap:
:
put
);
HttpResponse
response
=
HttpRequest
.
post
(
accessTokenUrl
)
.
header
(
"Host"
,
"https://login.microsoftonline.com"
)
.
header
(
"Content-Type"
,
"application/x-www-form-urlencoded"
)
.
form
(
par
amMap
)
.
contentType
(
"application/x-www-form-urlencoded"
)
.
form
(
par
seQueryToMap
(
accessTokenUrl
)
)
.
execute
();
String
accessTokenStr
=
response
.
body
();
JSONObject
accessTokenObject
=
JSONObject
.
parseObject
(
accessTokenStr
);
...
...
src/main/java/me/zhyd/oauth/request/AuthPinterestRequest.java
0 → 100644
浏览文件 @
d5189aa3
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
;
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.AuthPinterestUrlBuilder
;
import
me.zhyd.oauth.url.entity.AuthUserInfoEntity
;
import
java.util.Objects
;
import
static
me
.
zhyd
.
oauth
.
config
.
AuthSource
.
PINTEREST
;
/**
* Pinterest登录
*
* @author hongwei.peng (pengisgood(at)gmail(dot)com)
* @version 1.9.0
* @since 1.9.0
*/
public
class
AuthPinterestRequest
extends
AuthDefaultRequest
{
public
AuthPinterestRequest
(
AuthConfig
config
)
{
super
(
config
,
PINTEREST
,
new
AuthPinterestUrlBuilder
());
}
@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 Pinterest using code ["
+
authCallback
.
getCode
()
+
"]: "
+
accessTokenObject
);
}
return
AuthToken
.
builder
()
.
accessToken
(
accessTokenObject
.
getString
(
"access_token"
))
.
tokenType
(
accessTokenObject
.
getString
(
"token_type"
))
.
build
();
}
@Override
protected
AuthUser
getUserInfo
(
AuthToken
authToken
)
{
String
accessToken
=
authToken
.
getAccessToken
();
HttpResponse
response
=
HttpRequest
.
get
(
this
.
urlBuilder
.
getUserInfoUrl
(
AuthUserInfoEntity
.
builder
()
.
accessToken
(
accessToken
)
.
build
())).
execute
();
JSONObject
userObj
=
JSONObject
.
parseObject
(
response
.
body
()).
getJSONObject
(
"data"
);
return
AuthUser
.
builder
()
.
uuid
(
userObj
.
getString
(
"id"
))
.
avatar
(
getAvatarUrl
(
userObj
))
.
username
(
userObj
.
getString
(
"username"
))
.
nickname
(
userObj
.
getString
(
"first_name"
)
+
" "
+
userObj
.
getString
(
"last_name"
))
.
gender
(
AuthUserGender
.
UNKNOWN
)
.
remark
(
userObj
.
getString
(
"bio"
))
.
token
(
authToken
)
.
source
(
PINTEREST
)
.
build
();
}
private
String
getAvatarUrl
(
JSONObject
userObj
)
{
// image is a map data structure
JSONObject
jsonObject
=
userObj
.
getJSONObject
(
"image"
);
if
(
Objects
.
isNull
(
jsonObject
))
{
return
null
;
}
return
jsonObject
.
getJSONObject
(
"60x60"
).
getString
(
"url"
);
}
}
src/main/java/me/zhyd/oauth/request/AuthRenrenRequest.java
浏览文件 @
d5189aa3
...
...
@@ -6,6 +6,7 @@ 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.AuthResponse
;
import
me.zhyd.oauth.model.AuthToken
;
import
me.zhyd.oauth.model.AuthUser
;
import
me.zhyd.oauth.model.AuthUserGender
;
...
...
@@ -14,6 +15,7 @@ import me.zhyd.oauth.utils.UrlBuilder;
import
java.util.Objects
;
import
static
me
.
zhyd
.
oauth
.
config
.
AuthSource
.
RENREN
;
import
static
me
.
zhyd
.
oauth
.
model
.
AuthResponseStatus
.
SUCCESS
;
/**
* 人人登录
...
...
@@ -30,22 +32,14 @@ public class AuthRenrenRequest extends AuthDefaultRequest {
@Override
protected
AuthToken
getAccessToken
(
AuthCallback
authCallback
)
{
HttpResponse
response
=
doPostAuthorizationCode
(
authCallback
.
getCode
());
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
();
return
getToken
(
this
.
urlBuilder
.
getAccessTokenUrl
(
authCallback
.
getCode
()));
}
@Override
protected
AuthUser
getUserInfo
(
AuthToken
authToken
)
{
HttpResponse
response
=
doGetUserInfo
(
authToken
);
JSONObject
userObj
=
JSONObject
.
parseObject
(
response
.
body
()).
getJSONObject
(
"response"
);
return
AuthUser
.
builder
()
...
...
@@ -59,6 +53,30 @@ public class AuthRenrenRequest extends AuthDefaultRequest {
.
build
();
}
@Override
public
AuthResponse
refresh
(
AuthToken
authToken
)
{
return
AuthResponse
.
builder
()
.
code
(
SUCCESS
.
getCode
())
.
data
(
getToken
(
this
.
urlBuilder
.
getRefreshUrl
(
authToken
.
getRefreshToken
())))
.
build
();
}
private
AuthToken
getToken
(
String
url
)
{
HttpResponse
response
=
HttpRequest
.
post
(
url
).
execute
();
JSONObject
jsonObject
=
JSONObject
.
parseObject
(
response
.
body
());
if
(!
response
.
isOk
())
{
throw
new
AuthException
(
"Failed to get token from Renren: "
+
jsonObject
);
}
return
AuthToken
.
builder
()
.
tokenType
(
jsonObject
.
getString
(
"token_type"
))
.
expireIn
(
jsonObject
.
getIntValue
(
"expires_in"
))
.
accessToken
(
jsonObject
.
getString
(
"access_token"
))
.
refreshToken
(
jsonObject
.
getString
(
"refresh_token"
))
.
openId
(
jsonObject
.
getJSONObject
(
"user"
).
getString
(
"id"
))
.
build
();
}
private
String
getAvatarUrl
(
JSONObject
userObj
)
{
JSONArray
jsonArray
=
userObj
.
getJSONArray
(
"avatar"
);
if
(
Objects
.
isNull
(
jsonArray
)
||
jsonArray
.
isEmpty
())
{
...
...
src/main/java/me/zhyd/oauth/request/AuthStackOverflowRequest.java
0 → 100644
浏览文件 @
d5189aa3
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
;
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.AuthStackOverflowUrlBuilder
;
import
me.zhyd.oauth.url.entity.AuthUserInfoEntity
;
import
static
me
.
zhyd
.
oauth
.
config
.
AuthSource
.
STACK_OVERFLOW
;
import
static
me
.
zhyd
.
oauth
.
utils
.
GlobalAuthUtil
.
parseQueryToMap
;
/**
* Stack Overflow登录
*
* @author hongwei.peng (pengisgood(at)gmail(dot)com)
* @version 1.9.0
* @since 1.9.0
*/
public
class
AuthStackOverflowRequest
extends
AuthDefaultRequest
{
public
AuthStackOverflowRequest
(
AuthConfig
config
)
{
super
(
config
,
STACK_OVERFLOW
,
new
AuthStackOverflowUrlBuilder
());
}
@Override
protected
AuthToken
getAccessToken
(
AuthCallback
authCallback
)
{
String
accessTokenUrl
=
this
.
urlBuilder
.
getAccessTokenUrl
(
authCallback
.
getCode
());
HttpResponse
response
=
HttpRequest
.
post
(
accessTokenUrl
)
.
contentType
(
"application/x-www-form-urlencoded"
)
.
form
(
parseQueryToMap
(
accessTokenUrl
))
.
execute
();
JSONObject
accessTokenObject
=
JSONObject
.
parseObject
(
response
.
body
());
if
(!
response
.
isOk
())
{
throw
new
AuthException
(
"Unable to get token from Stack Overflow using code ["
+
authCallback
.
getCode
()
+
"]: "
+
accessTokenObject
);
}
return
AuthToken
.
builder
()
.
accessToken
(
accessTokenObject
.
getString
(
"access_token"
))
.
expireIn
(
accessTokenObject
.
getIntValue
(
"expires"
))
.
build
();
}
@Override
protected
AuthUser
getUserInfo
(
AuthToken
authToken
)
{
String
accessToken
=
authToken
.
getAccessToken
();
HttpResponse
response
=
HttpRequest
.
get
(
this
.
urlBuilder
.
getUserInfoUrl
(
AuthUserInfoEntity
.
builder
()
.
accessToken
(
accessToken
)
.
build
())).
execute
();
JSONObject
userObj
=
JSONObject
.
parseObject
(
response
.
body
()).
getJSONArray
(
"items"
).
getJSONObject
(
0
);
return
AuthUser
.
builder
()
.
uuid
(
userObj
.
getString
(
"user_id"
))
.
avatar
(
userObj
.
getString
(
"profile_image"
))
.
location
(
userObj
.
getString
(
"location"
))
.
nickname
(
userObj
.
getString
(
"display_name"
))
.
blog
(
userObj
.
getString
(
"website_url"
))
.
gender
(
AuthUserGender
.
UNKNOWN
)
.
token
(
authToken
)
.
source
(
STACK_OVERFLOW
)
.
build
();
}
}
src/main/java/me/zhyd/oauth/url/AuthPinterestUrlBuilder.java
0 → 100644
浏览文件 @
d5189aa3
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
.
PINTEREST
;
/**
* Pinterest相关的URL构建类
*
* @author hongwei.peng (pengisgood(at)gmail(dot)com)
* @version 1.9.0
* @since 1.9.0
*/
public
class
AuthPinterestUrlBuilder
extends
AuthDefaultUrlBuilder
{
private
static
final
String
PINTEREST_ACCESS_TOKEN_PATTERN
=
"{0}?client_id={1}&client_secret={2}&grant_type=authorization_code&code={3}"
;
private
static
final
String
PINTEREST_USER_INFO_PATTERN
=
"{0}?access_token={1}&fields=id,username,first_name,last_name,bio,image"
;
private
static
final
String
PINTEREST_AUTHORIZE_PATTERN
=
"{0}?client_id={1}&response_type=code&redirect_uri={2}&state={3}&scope=read_public"
;
@Override
public
String
getAccessTokenUrl
(
String
code
)
{
return
MessageFormat
.
format
(
PINTEREST_ACCESS_TOKEN_PATTERN
,
PINTEREST
.
accessToken
(),
config
.
getClientId
(),
config
.
getClientSecret
(),
code
);
}
@Override
public
String
getUserInfoUrl
(
AuthUserInfoEntity
userInfoEntity
)
{
return
MessageFormat
.
format
(
PINTEREST_USER_INFO_PATTERN
,
PINTEREST
.
userInfo
(),
userInfoEntity
.
getAccessToken
());
}
@Override
public
String
getAuthorizeUrl
()
{
return
MessageFormat
.
format
(
PINTEREST_AUTHORIZE_PATTERN
,
PINTEREST
.
authorize
(),
config
.
getClientId
(),
config
.
getRedirectUri
(),
this
.
getRealState
(
config
.
getState
()));
}
@Override
public
String
getRefreshUrl
(
String
refreshToken
)
{
throw
new
AuthException
(
AuthResponseStatus
.
UNSUPPORTED
);
}
@Override
public
String
getRevokeUrl
(
String
accessToken
)
{
throw
new
AuthException
(
AuthResponseStatus
.
UNSUPPORTED
);
}
}
src/main/java/me/zhyd/oauth/url/AuthStackOverflowUrlBuilder.java
0 → 100644
浏览文件 @
d5189aa3
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
.
STACK_OVERFLOW
;
/**
* Stack Overflow相关的URL构建类
*
* @author hongwei.peng (pengisgood(at)gmail(dot)com)
* @version 1.9.0
* @since 1.9.0
*/
public
class
AuthStackOverflowUrlBuilder
extends
AuthDefaultUrlBuilder
{
private
static
final
String
SO_ACCESS_TOKEN_PATTERN
=
"{0}?client_id={1}&client_secret={2}&redirect_uri={3}&code={4}"
;
private
static
final
String
SO_USER_INFO_PATTERN
=
"{0}?access_token={1}&site=stackoverflow&key={2}"
;
private
static
final
String
SO_AUTHORIZE_PATTERN
=
"{0}?client_id={1}&response_type=code&redirect_uri={2}&state={3}"
;
@Override
public
String
getAccessTokenUrl
(
String
code
)
{
return
MessageFormat
.
format
(
SO_ACCESS_TOKEN_PATTERN
,
STACK_OVERFLOW
.
accessToken
(),
config
.
getClientId
(),
config
.
getClientSecret
(),
config
.
getRedirectUri
(),
code
);
}
@Override
public
String
getUserInfoUrl
(
AuthUserInfoEntity
userInfoEntity
)
{
return
MessageFormat
.
format
(
SO_USER_INFO_PATTERN
,
STACK_OVERFLOW
.
userInfo
(),
userInfoEntity
.
getAccessToken
(),
config
.
getStackOverflowKey
());
}
@Override
public
String
getAuthorizeUrl
()
{
return
MessageFormat
.
format
(
SO_AUTHORIZE_PATTERN
,
STACK_OVERFLOW
.
authorize
(),
config
.
getClientId
(),
config
.
getRedirectUri
(),
this
.
getRealState
(
config
.
getState
()));
}
@Override
public
String
getRefreshUrl
(
String
refreshToken
)
{
throw
new
AuthException
(
AuthResponseStatus
.
UNSUPPORTED
);
}
@Override
public
String
getRevokeUrl
(
String
accessToken
)
{
throw
new
AuthException
(
AuthResponseStatus
.
UNSUPPORTED
);
}
}
src/main/java/me/zhyd/oauth/utils/GlobalAuthUtil.java
浏览文件 @
d5189aa3
...
...
@@ -3,6 +3,7 @@ package me.zhyd.oauth.utils;
import
cn.hutool.core.codec.Base64
;
import
cn.hutool.core.collection.CollUtil
;
import
cn.hutool.core.util.ObjectUtil
;
import
cn.hutool.http.HttpUtil
;
import
me.zhyd.oauth.exception.AuthException
;
import
javax.crypto.Mac
;
...
...
@@ -82,6 +83,7 @@ public class GlobalAuthUtil {
return
res
;
}
public
static
String
parseMapToString
(
Map
<
String
,
Object
>
params
,
boolean
encode
)
{
List
<
String
>
paramList
=
new
ArrayList
<>();
params
.
forEach
((
k
,
v
)
->
{
...
...
@@ -94,6 +96,12 @@ public class GlobalAuthUtil {
});
return
CollUtil
.
join
(
paramList
,
"&"
);
}
public
static
Map
<
String
,
Object
>
parseQueryToMap
(
String
url
)
{
Map
<
String
,
Object
>
paramMap
=
new
HashMap
<>();
HttpUtil
.
decodeParamMap
(
url
,
"UTF-8"
).
forEach
(
paramMap:
:
put
);
return
paramMap
;
}
public
static
boolean
isHttpProtocol
(
String
url
)
{
if
(
StringUtils
.
isEmpty
(
url
))
{
...
...
update.md
浏览文件 @
d5189aa3
### 2019/07/18
1.
合并github上
[
@pengisgood
](
https://github.com/pengisgood
)
的
[
pr#19
](
https://github.com/zhangyd-c/JustAuth/pull/19
)
,集成人人
2.
合并github上
[
@pengisgood
](
https://github.com/pengisgood
)
的
[
pr#20
](
https://github.com/zhangyd-c/JustAuth/pull/20
)
,集成Pinterest
2.
合并github上
[
@pengisgood
](
https://github.com/pengisgood
)
的
[
pr#21
](
https://github.com/zhangyd-c/JustAuth/pull/21
)
,集成StackOverflow
### 2019/07/17
1.
优化代码
2.
集成Teambition登录
### 2019/07/16
1.
重构UrlBuilder类
2.
将CSDN相关的类置为
`Deprecated`
,后续可能会删除,也可能一直保留。毕竟CSDN的openAPI已经不对外开放了。
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录