Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BI8CLL灬
JustAuth
提交
d1d7587f
J
JustAuth
项目概览
BI8CLL灬
/
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,发现更多精彩内容 >>
提交
d1d7587f
编写于
7月 18, 2019
作者:
智布道
👁
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
🔀
merge
上级
d5e60165
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
26 addition
and
125 deletion
+26
-125
src/main/java/me/zhyd/oauth/request/AuthPinterestRequest.java
...main/java/me/zhyd/oauth/request/AuthPinterestRequest.java
+7
-9
src/main/java/me/zhyd/oauth/request/AuthRenrenRequest.java
src/main/java/me/zhyd/oauth/request/AuthRenrenRequest.java
+4
-9
src/main/java/me/zhyd/oauth/request/AuthStackOverflowRequest.java
.../java/me/zhyd/oauth/request/AuthStackOverflowRequest.java
+8
-8
src/main/java/me/zhyd/oauth/url/AuthPinterestUrlBuilder.java
src/main/java/me/zhyd/oauth/url/AuthPinterestUrlBuilder.java
+0
-48
src/main/java/me/zhyd/oauth/url/AuthStackOverflowUrlBuilder.java
...n/java/me/zhyd/oauth/url/AuthStackOverflowUrlBuilder.java
+0
-48
src/main/java/me/zhyd/oauth/utils/UrlBuilder.java
src/main/java/me/zhyd/oauth/utils/UrlBuilder.java
+7
-3
未找到文件。
src/main/java/me/zhyd/oauth/request/AuthPinterestRequest.java
浏览文件 @
d1d7587f
...
...
@@ -9,8 +9,7 @@ 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
me.zhyd.oauth.utils.UrlBuilder
;
import
java.util.Objects
;
...
...
@@ -26,13 +25,12 @@ import static me.zhyd.oauth.config.AuthSource.PINTEREST;
public
class
AuthPinterestRequest
extends
AuthDefaultRequest
{
public
AuthPinterestRequest
(
AuthConfig
config
)
{
super
(
config
,
PINTEREST
,
new
AuthPinterestUrlBuilder
()
);
super
(
config
,
PINTEREST
);
}
@Override
protected
AuthToken
getAccessToken
(
AuthCallback
authCallback
)
{
String
accessTokenUrl
=
this
.
urlBuilder
.
getAccessTokenUrl
(
authCallback
.
getCode
());
HttpResponse
response
=
HttpRequest
.
post
(
accessTokenUrl
).
execute
();
HttpResponse
response
=
doPostAuthorizationCode
(
authCallback
.
getCode
());
JSONObject
accessTokenObject
=
JSONObject
.
parseObject
(
response
.
body
());
if
(!
response
.
isOk
())
{
throw
new
AuthException
(
"Unable to get token from Pinterest using code ["
+
authCallback
.
getCode
()
+
"]: "
+
accessTokenObject
);
...
...
@@ -46,10 +44,10 @@ public class AuthPinterestRequest extends AuthDefaultRequest {
@Override
protected
AuthUser
getUserInfo
(
AuthToken
authToken
)
{
String
accessToken
=
authToken
.
getAccessToken
();
HttpResponse
response
=
HttpRequest
.
get
(
this
.
urlBuilder
.
getUserInfoUrl
(
AuthUserInfoEntity
.
builder
(
)
.
accessToken
(
accessToken
)
.
build
())
).
execute
();
String
userinfoUrl
=
UrlBuilder
.
fromBaseUrl
(
userInfoUrl
(
authToken
))
.
queryParam
(
"fields"
,
"id,username,first_name,last_name,bio,image"
)
.
build
();
HttpResponse
response
=
HttpRequest
.
post
(
userinfoUrl
).
execute
();
JSONObject
userObj
=
JSONObject
.
parseObject
(
response
.
body
()).
getJSONObject
(
"data"
);
return
AuthUser
.
builder
()
...
...
src/main/java/me/zhyd/oauth/request/AuthRenrenRequest.java
浏览文件 @
d1d7587f
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.AuthResponse
;
import
me.zhyd.oauth.model.AuthToken
;
import
me.zhyd.oauth.model.AuthUser
;
import
me.zhyd.oauth.model.AuthUserGender
;
import
me.zhyd.oauth.model.*
;
import
me.zhyd.oauth.utils.UrlBuilder
;
import
java.util.Objects
;
...
...
@@ -32,14 +29,12 @@ public class AuthRenrenRequest extends AuthDefaultRequest {
@Override
protected
AuthToken
getAccessToken
(
AuthCallback
authCallback
)
{
return
getToken
(
this
.
urlBuilder
.
getA
ccessTokenUrl
(
authCallback
.
getCode
()));
return
this
.
getToken
(
a
ccessTokenUrl
(
authCallback
.
getCode
()));
}
@Override
protected
AuthUser
getUserInfo
(
AuthToken
authToken
)
{
HttpResponse
response
=
doGetUserInfo
(
authToken
);
JSONObject
userObj
=
JSONObject
.
parseObject
(
response
.
body
()).
getJSONObject
(
"response"
);
return
AuthUser
.
builder
()
...
...
@@ -57,7 +52,7 @@ public class AuthRenrenRequest extends AuthDefaultRequest {
public
AuthResponse
refresh
(
AuthToken
authToken
)
{
return
AuthResponse
.
builder
()
.
code
(
SUCCESS
.
getCode
())
.
data
(
getToken
(
this
.
urlBuilder
.
getRefresh
Url
(
authToken
.
getRefreshToken
())))
.
data
(
getToken
(
this
.
refreshToken
Url
(
authToken
.
getRefreshToken
())))
.
build
();
}
...
...
src/main/java/me/zhyd/oauth/request/AuthStackOverflowRequest.java
浏览文件 @
d1d7587f
...
...
@@ -9,8 +9,7 @@ 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
me.zhyd.oauth.utils.UrlBuilder
;
import
static
me
.
zhyd
.
oauth
.
config
.
AuthSource
.
STACK_OVERFLOW
;
import
static
me
.
zhyd
.
oauth
.
utils
.
GlobalAuthUtil
.
parseQueryToMap
;
...
...
@@ -25,12 +24,12 @@ import static me.zhyd.oauth.utils.GlobalAuthUtil.parseQueryToMap;
public
class
AuthStackOverflowRequest
extends
AuthDefaultRequest
{
public
AuthStackOverflowRequest
(
AuthConfig
config
)
{
super
(
config
,
STACK_OVERFLOW
,
new
AuthStackOverflowUrlBuilder
()
);
super
(
config
,
STACK_OVERFLOW
);
}
@Override
protected
AuthToken
getAccessToken
(
AuthCallback
authCallback
)
{
String
accessTokenUrl
=
this
.
urlBuilder
.
getA
ccessTokenUrl
(
authCallback
.
getCode
());
String
accessTokenUrl
=
a
ccessTokenUrl
(
authCallback
.
getCode
());
HttpResponse
response
=
HttpRequest
.
post
(
accessTokenUrl
)
.
contentType
(
"application/x-www-form-urlencoded"
)
.
form
(
parseQueryToMap
(
accessTokenUrl
))
...
...
@@ -48,10 +47,11 @@ public class AuthStackOverflowRequest extends AuthDefaultRequest {
@Override
protected
AuthUser
getUserInfo
(
AuthToken
authToken
)
{
String
accessToken
=
authToken
.
getAccessToken
();
HttpResponse
response
=
HttpRequest
.
get
(
this
.
urlBuilder
.
getUserInfoUrl
(
AuthUserInfoEntity
.
builder
()
.
accessToken
(
accessToken
)
.
build
())).
execute
();
String
userInfoUrl
=
UrlBuilder
.
fromBaseUrl
(
userInfoUrl
(
authToken
))
.
queryParam
(
"site"
,
"stackoverflow"
)
.
queryParam
(
"key"
,
this
.
config
.
getStackOverflowKey
())
.
build
();
HttpResponse
response
=
HttpRequest
.
get
(
userInfoUrl
).
execute
();
JSONObject
userObj
=
JSONObject
.
parseObject
(
response
.
body
()).
getJSONArray
(
"items"
).
getJSONObject
(
0
);
return
AuthUser
.
builder
()
...
...
src/main/java/me/zhyd/oauth/url/AuthPinterestUrlBuilder.java
已删除
100644 → 0
浏览文件 @
d5e60165
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
已删除
100644 → 0
浏览文件 @
d5e60165
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/UrlBuilder.java
浏览文件 @
d1d7587f
...
...
@@ -3,7 +3,7 @@ package me.zhyd.oauth.utils;
import
cn.hutool.core.lang.Assert
;
import
cn.hutool.core.map.MapUtil
;
import
cn.hutool.core.util.StrUtil
;
import
lombok.
Data
;
import
lombok.
Setter
;
import
java.util.LinkedHashMap
;
import
java.util.Map
;
...
...
@@ -16,11 +16,15 @@ import java.util.Map;
* @author yangkai.shen (https://xkcoding.com)
* @date Created in 2019-07-18 15:47
*/
@
Data
@
Setter
public
class
UrlBuilder
{
private
String
baseUrl
;
private
final
Map
<
String
,
Object
>
params
=
new
LinkedHashMap
<>(
4
);
private
String
baseUrl
;
private
UrlBuilder
()
{
}
/**
* @param baseUrl 基础路径
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录