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 {
...
@@ -35,7 +35,7 @@ public interface OAuthApi {
final
String
OAUTH_TOKEN_SESSION
=
"OAUTH2_TOKEN_SESSION_KEY"
;
final
String
OAUTH_TOKEN_SESSION
=
"OAUTH2_TOKEN_SESSION_KEY"
;
default
boolean
is
Logi
n
()
{
default
boolean
is
ExistsOAuthToke
n
()
{
return
getOAuthToken
()
!=
null
;
return
getOAuthToken
()
!=
null
;
}
}
...
@@ -88,31 +88,25 @@ public interface OAuthApi {
...
@@ -88,31 +88,25 @@ public interface OAuthApi {
default
void
callback
()
{
default
void
callback
()
{
try
{
try
{
HttpServletRequest
request
=
this
.
getHttpServletRequest
();
HttpServletRequest
request
=
this
.
getHttpServletRequest
();
HttpSession
session
=
request
.
getSession
();
OAuthConfig
config
=
this
.
getOAuthConfig
();
OAuthToken
token
=
(
OAuthToken
)
session
.
getAttribute
(
OAUTH_TOKEN_SESSION
);
OAuthAuthzResponse
oauthAuthzResponse
=
OAuthAuthzResponse
.
oauthCodeAuthzResponse
(
request
);
if
(
token
==
null
)
{
String
code
=
oauthAuthzResponse
.
getCode
();
OAuthConfig
config
=
this
.
getOAuthConfig
();
TokenRequestBuilder
builder
=
OAuthClientRequest
.
tokenLocation
(
config
.
getAccessTokenUrl
());
OAuthAuthzResponse
oauthAuthzResponse
=
OAuthAuthzResponse
.
oauthCodeAuthzResponse
(
request
);
builder
.
setGrantType
(
GrantType
.
AUTHORIZATION_CODE
);
String
code
=
oauthAuthzResponse
.
getCode
();
builder
.
setClientId
(
config
.
getClientId
());
TokenRequestBuilder
builder
=
OAuthClientRequest
.
tokenLocation
(
config
.
getAccessTokenUrl
());
builder
.
setClientSecret
(
config
.
getClientSecret
());
builder
.
setGrantType
(
GrantType
.
AUTHORIZATION_CODE
);
builder
.
setRedirectURI
(
config
.
getRediretUrl
());
builder
.
setClientId
(
config
.
getClientId
());
builder
.
setCode
(
code
);
builder
.
setClientSecret
(
config
.
getClientSecret
());
OAuthClientRequest
oauthClientRequest
=
builder
.
buildQueryMessage
();
builder
.
setRedirectURI
(
config
.
getRediretUrl
());
OAuthClient
oAuthClient
=
new
OAuthClient
(
new
URLConnectionClient
());
builder
.
setCode
(
code
);
OAuthJSONAccessTokenResponse
oAuthResponse
=
oAuthClient
.
accessToken
(
oauthClientRequest
,
OAuth
.
HttpMethod
.
POST
);
OAuthClientRequest
oauthClientRequest
=
builder
.
buildQueryMessage
();
String
accessToken
=
oAuthResponse
.
getAccessToken
();
OAuthClient
oAuthClient
=
new
OAuthClient
(
new
URLConnectionClient
());
String
refreshToken
=
oAuthResponse
.
getRefreshToken
();
OAuthJSONAccessTokenResponse
oAuthResponse
=
oAuthClient
.
accessToken
(
oauthClientRequest
,
OAuth
.
HttpMethod
.
POST
);
Long
expiresIn
=
oAuthResponse
.
getExpiresIn
();
String
accessToken
=
oAuthResponse
.
getAccessToken
();
String
idToken
=
oAuthResponse
.
getParam
(
"id_token"
);
String
refreshToken
=
oAuthResponse
.
getRefreshToken
();
String
tokenType
=
oAuthResponse
.
getTokenType
();
Long
expiresIn
=
oAuthResponse
.
getExpiresIn
();
OAuthToken
token
=
new
OAuthToken
(
accessToken
,
refreshToken
,
idToken
,
tokenType
,
expiresIn
);
String
idToken
=
oAuthResponse
.
getParam
(
"id_token"
);
saveOAuthToken
(
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"
);
}
}
catch
(
OAuthApiException
e
)
{
}
catch
(
OAuthApiException
e
)
{
throw
e
;
throw
e
;
}
catch
(
Throwable
e
)
{
}
catch
(
Throwable
e
)
{
...
@@ -120,6 +114,12 @@ public interface OAuthApi {
...
@@ -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
()
{
default
void
removeOAuthToken
()
{
try
{
try
{
HttpServletRequest
request
=
this
.
getHttpServletRequest
();
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