Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
justauth
JustAuth
提交
5a5827a7
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看板
提交
5a5827a7
编写于
7月 18, 2019
作者:
智布道
👁
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'dev' of
https://github.com/zhangyd-c/JustAuth
into dev
上级
a5da3b97
27583b15
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
145 addition
and
0 deletion
+145
-0
developer.md
developer.md
+1
-0
src/main/java/me/zhyd/oauth/config/AuthSource.java
src/main/java/me/zhyd/oauth/config/AuthSource.java
+20
-0
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/url/AuthPinterestUrlBuilder.java
src/main/java/me/zhyd/oauth/url/AuthPinterestUrlBuilder.java
+48
-0
未找到文件。
developer.md
浏览文件 @
5a5827a7
...
...
@@ -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>
-
千年等一回,我只为等你...
src/main/java/me/zhyd/oauth/config/AuthSource.java
浏览文件 @
5a5827a7
...
...
@@ -469,6 +469,26 @@ 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"
;
}
};
/**
...
...
src/main/java/me/zhyd/oauth/request/AuthPinterestRequest.java
0 → 100644
浏览文件 @
5a5827a7
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/url/AuthPinterestUrlBuilder.java
0 → 100644
浏览文件 @
5a5827a7
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
);
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录