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
c1deebfc
Commit
c1deebfc
authored
Aug 07, 2019
by
Quxl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
x
parent
d68cf3a3
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
26 deletions
+26
-26
OAuthApi.java
src/main/java/com/egolm/sso/oauth/OAuthApi.java
+26
-26
No files found.
src/main/java/com/egolm/sso/oauth/OAuthApi.java
View file @
c1deebfc
...
...
@@ -35,7 +35,7 @@ public interface OAuthApi {
final
String
OAUTH_TOKEN_SESSION
=
"OAUTH2_TOKEN_SESSION_KEY"
;
default
boolean
is
Logi
n
()
{
default
boolean
is
ExistsOAuthToke
n
()
{
return
getOAuthToken
()
!=
null
;
}
...
...
@@ -88,31 +88,25 @@ public interface OAuthApi {
default
void
callback
()
{
try
{
HttpServletRequest
request
=
this
.
getHttpServletRequest
();
HttpSession
session
=
request
.
getSession
();
OAuthToken
token
=
(
OAuthToken
)
session
.
getAttribute
(
OAUTH_TOKEN_SESSION
);
if
(
token
==
null
)
{
OAuthConfig
config
=
this
.
getOAuthConfig
();
OAuthAuthzResponse
oauthAuthzResponse
=
OAuthAuthzResponse
.
oauthCodeAuthzResponse
(
request
);
String
code
=
oauthAuthzResponse
.
getCode
();
TokenRequestBuilder
builder
=
OAuthClientRequest
.
tokenLocation
(
config
.
getAccessTokenUrl
());
builder
.
setGrantType
(
GrantType
.
AUTHORIZATION_CODE
);
builder
.
setClientId
(
config
.
getClientId
());
builder
.
setClientSecret
(
config
.
getClientSecret
());
builder
.
setRedirectURI
(
config
.
getRediretUrl
());
builder
.
setCode
(
code
);
OAuthClientRequest
oauthClientRequest
=
builder
.
buildQueryMessage
();
OAuthClient
oAuthClient
=
new
OAuthClient
(
new
URLConnectionClient
());
OAuthJSONAccessTokenResponse
oAuthResponse
=
oAuthClient
.
accessToken
(
oauthClientRequest
,
OAuth
.
HttpMethod
.
POST
);
String
accessToken
=
oAuthResponse
.
getAccessToken
();
String
refreshToken
=
oAuthResponse
.
getRefreshToken
();
Long
expiresIn
=
oAuthResponse
.
getExpiresIn
();
String
idToken
=
oAuthResponse
.
getParam
(
"id_token"
);
String
tokenType
=
oAuthResponse
.
getTokenType
();
token
=
new
OAuthToken
(
accessToken
,
refreshToken
,
idToken
,
tokenType
,
expiresIn
);
session
.
setAttribute
(
OAUTH_TOKEN_SESSION
,
token
);
}
else
{
throw
new
OAuthApiException
(
"OAuthToken already exists"
);
}
OAuthConfig
config
=
this
.
getOAuthConfig
();
OAuthAuthzResponse
oauthAuthzResponse
=
OAuthAuthzResponse
.
oauthCodeAuthzResponse
(
request
);
String
code
=
oauthAuthzResponse
.
getCode
();
TokenRequestBuilder
builder
=
OAuthClientRequest
.
tokenLocation
(
config
.
getAccessTokenUrl
());
builder
.
setGrantType
(
GrantType
.
AUTHORIZATION_CODE
);
builder
.
setClientId
(
config
.
getClientId
());
builder
.
setClientSecret
(
config
.
getClientSecret
());
builder
.
setRedirectURI
(
config
.
getRediretUrl
());
builder
.
setCode
(
code
);
OAuthClientRequest
oauthClientRequest
=
builder
.
buildQueryMessage
();
OAuthClient
oAuthClient
=
new
OAuthClient
(
new
URLConnectionClient
());
OAuthJSONAccessTokenResponse
oAuthResponse
=
oAuthClient
.
accessToken
(
oauthClientRequest
,
OAuth
.
HttpMethod
.
POST
);
String
accessToken
=
oAuthResponse
.
getAccessToken
();
String
refreshToken
=
oAuthResponse
.
getRefreshToken
();
Long
expiresIn
=
oAuthResponse
.
getExpiresIn
();
String
idToken
=
oAuthResponse
.
getParam
(
"id_token"
);
String
tokenType
=
oAuthResponse
.
getTokenType
();
OAuthToken
token
=
new
OAuthToken
(
accessToken
,
refreshToken
,
idToken
,
tokenType
,
expiresIn
);
saveOAuthToken
(
token
);
}
catch
(
OAuthApiException
e
)
{
throw
e
;
}
catch
(
Throwable
e
)
{
...
...
@@ -120,6 +114,12 @@ public interface OAuthApi {
}
}
default
void
saveOAuthToken
(
OAuthToken
token
)
{
HttpServletRequest
request
=
this
.
getHttpServletRequest
();
HttpSession
session
=
request
.
getSession
();
session
.
setAttribute
(
OAUTH_TOKEN_SESSION
,
token
);
}
default
void
removeOAuthToken
()
{
try
{
HttpServletRequest
request
=
this
.
getHttpServletRequest
();
...
...
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