Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
canifa_note
Project
Project
Details
Activity
Releases
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
Vũ Hoàng Anh
canifa_note
Commits
8bcc2bd7
Unverified
Commit
8bcc2bd7
authored
Jul 19, 2023
by
Jianwei Zhang
Committed by
GitHub
Jul 19, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: access token will expired after 24h (#1988)
parent
83b771d5
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
4 additions
and
8 deletions
+4
-8
jwt.go
api/v1/jwt.go
+4
-8
No files found.
api/v1/jwt.go
View file @
8bcc2bd7
...
@@ -112,14 +112,6 @@ func JWTMiddleware(server *APIV1Service, next echo.HandlerFunc, secret string) e
...
@@ -112,14 +112,6 @@ func JWTMiddleware(server *APIV1Service, next echo.HandlerFunc, secret string) e
return
nil
,
errors
.
Errorf
(
"unexpected access token kid=%v"
,
t
.
Header
[
"kid"
])
return
nil
,
errors
.
Errorf
(
"unexpected access token kid=%v"
,
t
.
Header
[
"kid"
])
})
})
if
!
accessToken
.
Valid
{
auth
.
RemoveTokensAndCookies
(
c
)
return
echo
.
NewHTTPError
(
http
.
StatusUnauthorized
,
"Invalid access token."
)
}
if
!
audienceContains
(
claims
.
Audience
,
auth
.
AccessTokenAudienceName
)
{
return
echo
.
NewHTTPError
(
http
.
StatusUnauthorized
,
fmt
.
Sprintf
(
"Invalid access token, audience mismatch, got %q, expected %q."
,
claims
.
Audience
,
auth
.
AccessTokenAudienceName
))
}
generateToken
:=
time
.
Until
(
claims
.
ExpiresAt
.
Time
)
<
auth
.
RefreshThresholdDuration
generateToken
:=
time
.
Until
(
claims
.
ExpiresAt
.
Time
)
<
auth
.
RefreshThresholdDuration
if
err
!=
nil
{
if
err
!=
nil
{
var
ve
*
jwt
.
ValidationError
var
ve
*
jwt
.
ValidationError
...
@@ -135,6 +127,10 @@ func JWTMiddleware(server *APIV1Service, next echo.HandlerFunc, secret string) e
...
@@ -135,6 +127,10 @@ func JWTMiddleware(server *APIV1Service, next echo.HandlerFunc, secret string) e
}
}
}
}
if
!
audienceContains
(
claims
.
Audience
,
auth
.
AccessTokenAudienceName
)
{
return
echo
.
NewHTTPError
(
http
.
StatusUnauthorized
,
fmt
.
Sprintf
(
"Invalid access token, audience mismatch, got %q, expected %q."
,
claims
.
Audience
,
auth
.
AccessTokenAudienceName
))
}
// We either have a valid access token or we will attempt to generate new access token and refresh token
// We either have a valid access token or we will attempt to generate new access token and refresh token
ctx
:=
c
.
Request
()
.
Context
()
ctx
:=
c
.
Request
()
.
Context
()
userID
,
err
:=
strconv
.
Atoi
(
claims
.
Subject
)
userID
,
err
:=
strconv
.
Atoi
(
claims
.
Subject
)
...
...
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