Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
wds12580
JustAuth
提交
0e8308e6
J
JustAuth
项目概览
wds12580
/
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,发现更多精彩内容 >>
提交
0e8308e6
编写于
3月 29, 2021
作者:
智布道
👁
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
🥚
集成 Line
上级
3933b3b7
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
144 addition
and
0 deletion
+144
-0
src/main/java/me/zhyd/oauth/enums/scope/AuthLineScope.java
src/main/java/me/zhyd/oauth/enums/scope/AuthLineScope.java
+28
-0
src/main/java/me/zhyd/oauth/request/AuthLineRequest.java
src/main/java/me/zhyd/oauth/request/AuthLineRequest.java
+116
-0
未找到文件。
src/main/java/me/zhyd/oauth/enums/scope/AuthLineScope.java
0 → 100644
浏览文件 @
0e8308e6
package
me.zhyd.oauth.enums.scope
;
import
lombok.AllArgsConstructor
;
import
lombok.Getter
;
/**
* Line 平台 OAuth 授权范围
*
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
* @since 1.16.0
*/
@Getter
@AllArgsConstructor
public
enum
AuthLineScope
implements
AuthScope
{
/**
* {@code scope} 含义,以{@code description} 为准
*/
PROFILE
(
"profile"
,
"Get profile details"
,
true
),
OPENID
(
"openid"
,
"Get id token"
,
true
),
EMAIL
(
"email"
,
"Get email (separate authorization required)"
,
false
);
private
final
String
scope
;
private
final
String
description
;
private
final
boolean
isDefault
;
}
src/main/java/me/zhyd/oauth/request/AuthLineRequest.java
0 → 100644
浏览文件 @
0e8308e6
package
me.zhyd.oauth.request
;
import
com.alibaba.fastjson.JSONObject
;
import
com.xkcoding.http.support.HttpHeader
;
import
me.zhyd.oauth.cache.AuthStateCache
;
import
me.zhyd.oauth.config.AuthConfig
;
import
me.zhyd.oauth.config.AuthDefaultSource
;
import
me.zhyd.oauth.enums.AuthResponseStatus
;
import
me.zhyd.oauth.enums.AuthUserGender
;
import
me.zhyd.oauth.enums.scope.AuthLineScope
;
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.utils.AuthScopeUtils
;
import
me.zhyd.oauth.utils.HttpUtils
;
import
me.zhyd.oauth.utils.UrlBuilder
;
import
java.util.HashMap
;
import
java.util.Map
;
/**
* LINE 登录, line.biz
*
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
* @since 1.16.0
*/
public
class
AuthLineRequest
extends
AuthDefaultRequest
{
public
AuthLineRequest
(
AuthConfig
config
)
{
super
(
config
,
AuthDefaultSource
.
LINE
);
}
public
AuthLineRequest
(
AuthConfig
config
,
AuthStateCache
authStateCache
)
{
super
(
config
,
AuthDefaultSource
.
LINE
,
authStateCache
);
}
@Override
protected
AuthToken
getAccessToken
(
AuthCallback
authCallback
)
{
return
this
.
getToken
(
accessTokenUrl
(
authCallback
.
getCode
()));
}
@Override
protected
AuthUser
getUserInfo
(
AuthToken
authToken
)
{
String
userInfo
=
new
HttpUtils
(
config
.
getHttpConfig
()).
get
(
source
.
userInfo
(),
null
,
new
HttpHeader
()
.
add
(
"Content-Type"
,
"application/x-www-form-urlencoded"
)
.
add
(
"Authorization"
,
"Bearer "
.
concat
(
authToken
.
getAccessToken
())),
false
);
JSONObject
object
=
JSONObject
.
parseObject
(
userInfo
);
return
AuthUser
.
builder
()
.
rawUserInfo
(
object
)
.
uuid
(
object
.
getString
(
"userId"
))
.
username
(
object
.
getString
(
"displayName"
))
.
nickname
(
object
.
getString
(
"displayName"
))
.
avatar
(
object
.
getString
(
"pictureUrl"
))
.
remark
(
object
.
getString
(
"statusMessage"
))
.
gender
(
AuthUserGender
.
UNKNOWN
)
.
token
(
authToken
)
.
source
(
source
.
toString
())
.
build
();
}
@Override
public
AuthResponse
revoke
(
AuthToken
authToken
)
{
Map
<
String
,
String
>
params
=
new
HashMap
<>(
5
);
params
.
put
(
"access_token"
,
authToken
.
getAccessToken
());
params
.
put
(
"client_id"
,
config
.
getClientId
());
params
.
put
(
"client_secret"
,
config
.
getClientSecret
());
String
userInfo
=
new
HttpUtils
(
config
.
getHttpConfig
()).
post
(
source
.
revoke
(),
params
,
false
);
JSONObject
object
=
JSONObject
.
parseObject
(
userInfo
);
// 返回1表示取消授权成功,否则失败
AuthResponseStatus
status
=
object
.
getBooleanValue
(
"revoked"
)
?
AuthResponseStatus
.
SUCCESS
:
AuthResponseStatus
.
FAILURE
;
return
AuthResponse
.
builder
().
code
(
status
.
getCode
()).
msg
(
status
.
getMsg
()).
build
();
}
@Override
public
AuthResponse
refresh
(
AuthToken
oldToken
)
{
return
AuthResponse
.
builder
()
.
code
(
AuthResponseStatus
.
SUCCESS
.
getCode
())
.
data
(
this
.
getToken
(
refreshTokenUrl
(
oldToken
.
getRefreshToken
())))
.
build
();
}
/**
* 获取token,适用于获取access_token和刷新token
*
* @param accessTokenUrl 实际请求token的地址
* @return token对象
*/
private
AuthToken
getToken
(
String
accessTokenUrl
)
{
String
response
=
new
HttpUtils
(
config
.
getHttpConfig
()).
post
(
accessTokenUrl
);
JSONObject
accessTokenObject
=
JSONObject
.
parseObject
(
response
);
return
AuthToken
.
builder
()
.
accessToken
(
accessTokenObject
.
getString
(
"access_token"
))
.
refreshToken
(
accessTokenObject
.
getString
(
"refresh_token"
))
.
expireIn
(
accessTokenObject
.
getIntValue
(
"expires_in"
))
.
idToken
(
accessTokenObject
.
getString
(
"id_token"
))
.
scope
(
accessTokenObject
.
getString
(
"scope"
))
.
tokenType
(
accessTokenObject
.
getString
(
"token_type"
))
.
build
();
}
@Override
public
String
userInfoUrl
(
AuthToken
authToken
)
{
return
UrlBuilder
.
fromBaseUrl
(
source
.
userInfo
())
.
queryParam
(
"user"
,
authToken
.
getUid
())
.
build
();
}
@Override
public
String
authorize
(
String
state
)
{
return
UrlBuilder
.
fromBaseUrl
(
super
.
authorize
(
state
))
.
queryParam
(
"nonce"
,
state
)
.
queryParam
(
"scope"
,
this
.
getScopes
(
" "
,
true
,
AuthScopeUtils
.
getDefaultScopes
(
AuthLineScope
.
values
())))
.
build
();
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录