Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
justauth
JustAuth
提交
da8ec82e
J
JustAuth
项目概览
justauth
/
JustAuth
大约 1 年 前同步成功
通知
382
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,发现更多精彩内容 >>
提交
da8ec82e
编写于
9月 30, 2019
作者:
H
Hongwei Peng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactor
上级
5ed7e156
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
24 addition
and
9 deletion
+24
-9
src/main/java/me/zhyd/oauth/request/AuthTwitterRequest.java
src/main/java/me/zhyd/oauth/request/AuthTwitterRequest.java
+24
-9
未找到文件。
src/main/java/me/zhyd/oauth/request/AuthTwitterRequest.java
浏览文件 @
da8ec82e
...
@@ -27,6 +27,8 @@ import static me.zhyd.oauth.utils.GlobalAuthUtil.urlEncode;
...
@@ -27,6 +27,8 @@ import static me.zhyd.oauth.utils.GlobalAuthUtil.urlEncode;
*/
*/
public
class
AuthTwitterRequest
extends
AuthDefaultRequest
{
public
class
AuthTwitterRequest
extends
AuthDefaultRequest
{
private
static
final
String
PREAMBLE
=
"OAuth"
;
public
AuthTwitterRequest
(
AuthConfig
config
)
{
public
AuthTwitterRequest
(
AuthConfig
config
)
{
super
(
config
,
TWITTER
);
super
(
config
,
TWITTER
);
}
}
...
@@ -47,10 +49,9 @@ public class AuthTwitterRequest extends AuthDefaultRequest {
...
@@ -47,10 +49,9 @@ public class AuthTwitterRequest extends AuthDefaultRequest {
Map
<
String
,
Object
>
oauthParams
=
buildOauthParams
();
Map
<
String
,
Object
>
oauthParams
=
buildOauthParams
();
oauthParams
.
put
(
"oauth_callback"
,
config
.
getRedirectUri
());
oauthParams
.
put
(
"oauth_callback"
,
config
.
getRedirectUri
());
oauthParams
.
put
(
"oauth_signature"
,
generateTwitterSignature
(
oauthParams
,
"POST"
,
baseUrl
,
config
.
getClientSecret
(),
null
));
oauthParams
.
put
(
"oauth_signature"
,
generateTwitterSignature
(
oauthParams
,
"POST"
,
baseUrl
,
config
.
getClientSecret
(),
null
));
oauthParams
.
forEach
((
k
,
v
)
->
oauthParams
.
put
(
k
,
"\""
+
urlEncode
(
v
.
toString
())
+
"\""
));
String
header
=
buildHeader
(
oauthParams
);
HttpResponse
requestToken
=
HttpRequest
.
post
(
baseUrl
)
HttpResponse
requestToken
=
HttpRequest
.
post
(
baseUrl
)
.
header
(
"Authorization"
,
"OAuth "
+
GlobalAuthUtil
.
parseMapToString
(
oauthParams
,
false
).
replaceAll
(
"&"
,
", "
)
)
.
header
(
"Authorization"
,
header
)
.
execute
();
.
execute
();
checkResponse
(
requestToken
);
checkResponse
(
requestToken
);
...
@@ -75,10 +76,9 @@ public class AuthTwitterRequest extends AuthDefaultRequest {
...
@@ -75,10 +76,9 @@ public class AuthTwitterRequest extends AuthDefaultRequest {
oauthParams
.
put
(
"oauth_token"
,
authCallback
.
getOauthToken
());
oauthParams
.
put
(
"oauth_token"
,
authCallback
.
getOauthToken
());
oauthParams
.
put
(
"oauth_verifier"
,
authCallback
.
getOauthVerifier
());
oauthParams
.
put
(
"oauth_verifier"
,
authCallback
.
getOauthVerifier
());
oauthParams
.
put
(
"oauth_signature"
,
generateTwitterSignature
(
oauthParams
,
"POST"
,
source
.
accessToken
(),
config
.
getClientSecret
(),
authCallback
.
getOauthToken
()));
oauthParams
.
put
(
"oauth_signature"
,
generateTwitterSignature
(
oauthParams
,
"POST"
,
source
.
accessToken
(),
config
.
getClientSecret
(),
authCallback
.
getOauthToken
()));
oauthParams
.
forEach
((
k
,
v
)
->
oauthParams
.
put
(
k
,
"\""
+
urlEncode
(
v
.
toString
())
+
"\""
));
String
header
=
buildHeader
(
oauthParams
);
HttpResponse
response
=
HttpRequest
.
post
(
source
.
accessToken
())
HttpResponse
response
=
HttpRequest
.
post
(
source
.
accessToken
())
.
header
(
"Authorization"
,
"OAuth "
+
GlobalAuthUtil
.
parseMapToString
(
oauthParams
,
false
).
replaceAll
(
"&"
,
", "
)
)
.
header
(
"Authorization"
,
header
)
.
header
(
"Content-Type"
,
"application/x-www-form-urlencoded"
)
.
header
(
"Content-Type"
,
"application/x-www-form-urlencoded"
)
.
form
(
"oauth_verifier"
,
authCallback
.
getOauthVerifier
())
.
form
(
"oauth_verifier"
,
authCallback
.
getOauthVerifier
())
.
execute
();
.
execute
();
...
@@ -108,10 +108,9 @@ public class AuthTwitterRequest extends AuthDefaultRequest {
...
@@ -108,10 +108,9 @@ public class AuthTwitterRequest extends AuthDefaultRequest {
Map
<
String
,
Object
>
params
=
new
HashMap
<>(
oauthParams
);
Map
<
String
,
Object
>
params
=
new
HashMap
<>(
oauthParams
);
params
.
putAll
(
queryParams
);
params
.
putAll
(
queryParams
);
oauthParams
.
put
(
"oauth_signature"
,
generateTwitterSignature
(
params
,
"GET"
,
source
.
userInfo
(),
config
.
getClientSecret
(),
authToken
.
getOauthTokenSecret
()));
oauthParams
.
put
(
"oauth_signature"
,
generateTwitterSignature
(
params
,
"GET"
,
source
.
userInfo
(),
config
.
getClientSecret
(),
authToken
.
getOauthTokenSecret
()));
oauthParams
.
forEach
((
k
,
v
)
->
oauthParams
.
put
(
k
,
"\""
+
urlEncode
(
v
.
toString
())
+
"\""
));
String
header
=
buildHeader
(
oauthParams
);
HttpResponse
response
=
HttpRequest
.
get
(
userInfoUrl
(
authToken
))
HttpResponse
response
=
HttpRequest
.
get
(
userInfoUrl
(
authToken
))
.
header
(
"Authorization"
,
"OAuth "
+
GlobalAuthUtil
.
parseMapToString
(
oauthParams
,
false
).
replaceAll
(
"&"
,
", "
)
)
.
header
(
"Authorization"
,
header
)
.
execute
();
.
execute
();
checkResponse
(
response
);
checkResponse
(
response
);
JSONObject
userInfo
=
JSONObject
.
parseObject
(
response
.
body
());
JSONObject
userInfo
=
JSONObject
.
parseObject
(
response
.
body
());
...
@@ -148,6 +147,22 @@ public class AuthTwitterRequest extends AuthDefaultRequest {
...
@@ -148,6 +147,22 @@ public class AuthTwitterRequest extends AuthDefaultRequest {
return
params
;
return
params
;
}
}
private
String
buildHeader
(
Map
<
String
,
Object
>
oauthParams
)
{
final
StringBuilder
sb
=
new
StringBuilder
(
PREAMBLE
);
for
(
Map
.
Entry
<
String
,
Object
>
param
:
oauthParams
.
entrySet
())
{
if
(
sb
.
length
()
>
PREAMBLE
.
length
())
{
sb
.
append
(
", "
);
}
sb
.
append
(
param
.
getKey
())
.
append
(
"=\""
)
.
append
(
urlEncode
(
param
.
getValue
().
toString
()))
.
append
(
'"'
);
}
return
sb
.
toString
();
}
private
void
checkResponse
(
HttpResponse
response
)
{
private
void
checkResponse
(
HttpResponse
response
)
{
if
(!
response
.
isOk
())
{
if
(!
response
.
isOk
())
{
throw
new
AuthException
(
response
.
body
());
throw
new
AuthException
(
response
.
body
());
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录