Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
S
sso
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
曲欣亮
sso
Commits
4aab0770
Commit
4aab0770
authored
Aug 07, 2019
by
Quxl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
x
parent
bdbb231c
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
55 additions
and
14 deletions
+55
-14
OAuthToken.java
src/main/java/com/egolm/sso/oauth/OAuthToken.java
+24
-14
UrlBuilder.java
src/main/java/com/egolm/sso/oauth/UrlBuilder.java
+31
-0
No files found.
src/main/java/com/egolm/sso/oauth/OAuthToken.java
View file @
4aab0770
...
...
@@ -2,10 +2,18 @@ package com.egolm.sso.oauth;
import
java.io.Serializable
;
import
org.apache.axis.encoding.Base64
;
import
com.alibaba.fastjson.JSON
;
/**
* 例如: <pre>{
"access_token": "0a379729-4c5b-45b9-a598-eed9cedfecd8",
"refresh_token": "784d4e94-efa2-4a64-94ad-942ef18db3c1",
"scope": "openid profile",
"id_token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJhdF9oYXNoIjoiczBtRHJvLUxBQXRLMnFDRWdtSWM3dyIsIkVtYWlsIjoicGFydGhhc2FyYXRoaS5wYWxAbWFpbGluYXRvci5jb20iLCJpbmR1c3RyeVNlZ21lbnQiOiJJRDUiLCJwb3N0YWxDb2RlIjoiNDM0NDIiLCJjb21wYW55U3RhdGUiOiJBSCIsImlzcyI6Imh0dHBzOi8vaWRlbnRpdHktc3RnLnNjaG5laWRlci1lbGVjdHJpYy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wiYyI6IkNOIiwiRmlyc3ROYW1lIjoicGFydGhhc2FyYXRoaSIsIm1vYmlsZSI6IjcwMjEwMTAxMDEwIiwibCI6Ikt1bmdzYmFja2EiLCJnaXZlbl9uYW1lIjoicGFydGhhc2FyYXRoaSIsImFpbF9hcHBsaWNhdGlvbnMiOiJvYXV0aFNhbXBsZUFwcCxBdXRvbWF0aW9uSG9tZSxBcHAiLCJlbXBsb3llZVR5cGUiOiJAV29yayIsInVwZGF0ZVNvdXJjZSI6IlVpbXMiLCJmZWRlcmF0ZWRJZCI6ImNuMDBaT2p3LWUyY2UtRzVuOC02dFNxLVlXYjlCMjFtTW5BViIsInJlYWxtIjoiL3NlIiwiaW5ldFVzZXJTdGF0dXMiOiJBY3RpdmUiLCJmYW1pbHlfbmFtZSI6InBhbCJ9.yly0EYywEjkVtXwrrlH8_dZ62YqFDxoEjX5uGpbg8C4",
"token_type": "Bearer",
"expires_in": 3599
}</pre>
* @author Quxl
*
*/
public
class
OAuthToken
implements
Serializable
{
private
static
final
long
serialVersionUID
=
-
73234152183180980L
;
...
...
@@ -31,12 +39,23 @@ public class OAuthToken implements Serializable {
private
String
tokenType
;
/**
* 过期时间
* 过期时间
(秒?)
*/
private
Long
expiresIn
;
/**
* Token创建时间(毫秒)
*/
private
Long
createMillis
;
/**
* 构造函数
* @param accessToken access_token
* @param refreshToken refresh_token
* @param idToken id_token
* @param tokenType token_type
* @param expiresIn expires_in
*/
public
OAuthToken
(
String
accessToken
,
String
refreshToken
,
String
idToken
,
String
tokenType
,
Long
expiresIn
)
{
this
.
accessToken
=
accessToken
;
this
.
refreshToken
=
refreshToken
;
...
...
@@ -74,13 +93,4 @@ public class OAuthToken implements Serializable {
return
createMillis
;
}
public
static
void
main
(
String
[]
args
)
{
String
str
=
"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJhdF9oYXNoIjoiczBtRHJvLUxBQXRLMnFDRWdtSWM3dyIsIkVtYWlsIjoicGFydGhhc2FyYXR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yIjoiZmFsc2UiLCJhenAiOiJteUNsaWVudElEIiwic3RyZWV0IjoiSGFudHZlcmtzZ2F0YW4yOCIsImN1cnJlbmN5IjoiQ05ZIiwiaWF0IjoxNTYzMjU2NDg1LCJlbWFpbCI6InBhcnRoYXNhcmF0aGkucGFsQG1haWxpbmF0b3IuY29tIiwiYyI6IkNOIiwiRmlyc3ROYW1lIjoicGFydGhhc2FyYXRoaSIsIm1vYmlsZSI6IjcwMjEwMTAxMDEwIiwibCI6Ikt1bmdzYmFja2EiLCJnaXZlbl9uYW1lIjoicGFydGhhc2FyYXRoaSIsImFpbF9hcHBsaWNhdGlvbnMiOiJvYXV0aFNhbXBsZUFwcCxBdXRvbWF0aW9uSG9tZSxBcHAiLCJlbXBsb3llZVR5cGUiOiJAV29yayIsInVwZGF0ZVNvdXJjZSI6IlVpbXMiLCJmZWRlcmF0ZWRJZCI6ImNuMDBaT2p3LWUyY2UtRzVuOC02dFNxLVlXYjlCMjFtTW5BViIsInJlYWxtIjoiL3NlIiwiaW5ldFVzZXJTdGF0dXMiOiJBY3RpdmUiLCJmYW1pbHlfbmFtZSI6InBhbCJ9.yly0EYywEjkVtXwrrlH8_dZ62YqFDxoEjX5uGpbg8C4"
;
String
[]
strs
=
str
.
split
(
"\\."
);
System
.
out
.
println
(
JSON
.
parseObject
(
new
String
(
Base64
.
decode
(
strs
[
0
]))));
System
.
out
.
println
(
JSON
.
parseObject
(
new
String
(
Base64
.
decode
(
strs
[
1
]))));
System
.
out
.
println
(
strs
[
2
]);
}
}
src/main/java/com/egolm/sso/oauth/UrlBuilder.java
View file @
4aab0770
...
...
@@ -5,6 +5,12 @@ import java.net.URLEncoder;
import
java.util.Map
;
import
java.util.TreeMap
;
/**
* HTTP URL 构造器
* 用于组装构造HTTP完整链接
* @author Quxl
*
*/
public
class
UrlBuilder
{
private
String
url
;
...
...
@@ -15,20 +21,41 @@ public class UrlBuilder {
this
.
url
=
url
;
}
/**
* 设置参数
* @param key 参数名
* @param value 参数值
* @return
*/
public
UrlBuilder
setParameter
(
String
key
,
String
value
)
{
parameters
.
put
(
key
,
value
);
return
this
;
}
/**
* 设置头信息
* @param key 参数名
* @param value 参数值
* @return
*/
public
UrlBuilder
setHeader
(
String
key
,
String
value
)
{
headers
.
put
(
key
,
value
);
return
this
;
}
/**
* 获取全部头信息
* @return
*/
public
Map
<
String
,
String
>
getHeaders
()
{
return
headers
;
}
/**
* 转为HTTP链接(URL已编码)
* @return
* @throws UnsupportedEncodingException
*/
public
String
toEncodeUrlString
()
throws
UnsupportedEncodingException
{
StringBuffer
sb
=
new
StringBuffer
(
url
);
if
(!
url
.
contains
(
"?"
))
{
...
...
@@ -51,6 +78,10 @@ public class UrlBuilder {
return
urlString
;
}
/**
* 转为HTTP链接(URL未编码)
* @return
*/
public
String
toUrlString
()
{
StringBuffer
sb
=
new
StringBuffer
(
url
);
if
(!
url
.
contains
(
"?"
))
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment