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
fb15386d
Commit
fb15386d
authored
May 20, 2024
by
Steven
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
chore: remove access token after sign out
parent
21838d0a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
3 deletions
+16
-3
acl.go
server/router/api/v1/acl.go
+4
-3
auth_service.go
server/router/api/v1/auth_service.go
+12
-0
No files found.
server/router/api/v1/acl.go
View file @
fb15386d
...
@@ -24,6 +24,7 @@ const (
...
@@ -24,6 +24,7 @@ const (
// The key name used to store username in the context
// The key name used to store username in the context
// user id is extracted from the jwt token subject field.
// user id is extracted from the jwt token subject field.
usernameContextKey
ContextKey
=
iota
usernameContextKey
ContextKey
=
iota
accessTokenContextKey
)
)
// GRPCAuthInterceptor is the auth interceptor for gRPC server.
// GRPCAuthInterceptor is the auth interceptor for gRPC server.
...
@@ -74,9 +75,9 @@ func (in *GRPCAuthInterceptor) AuthenticationInterceptor(ctx context.Context, re
...
@@ -74,9 +75,9 @@ func (in *GRPCAuthInterceptor) AuthenticationInterceptor(ctx context.Context, re
return
nil
,
errors
.
Errorf
(
"user %q is not admin"
,
username
)
return
nil
,
errors
.
Errorf
(
"user %q is not admin"
,
username
)
}
}
// Stores userID into context.
ctx
=
context
.
WithValue
(
ctx
,
usernameContextKey
,
username
)
c
hildCtx
:=
context
.
WithValue
(
ctx
,
usernameContextKey
,
username
)
c
tx
=
context
.
WithValue
(
ctx
,
accessTokenContextKey
,
accessToken
)
return
handler
(
c
hildC
tx
,
request
)
return
handler
(
ctx
,
request
)
}
}
func
(
in
*
GRPCAuthInterceptor
)
authenticate
(
ctx
context
.
Context
,
accessToken
string
)
(
string
,
error
)
{
func
(
in
*
GRPCAuthInterceptor
)
authenticate
(
ctx
context
.
Context
,
accessToken
string
)
(
string
,
error
)
{
...
...
server/router/api/v1/auth_service.go
View file @
fb15386d
...
@@ -3,6 +3,7 @@ package v1
...
@@ -3,6 +3,7 @@ package v1
import
(
import
(
"context"
"context"
"fmt"
"fmt"
"log/slog"
"regexp"
"regexp"
"strings"
"strings"
"time"
"time"
...
@@ -214,6 +215,17 @@ func (s *APIV1Service) SignUp(ctx context.Context, request *v1pb.SignUpRequest)
...
@@ -214,6 +215,17 @@ func (s *APIV1Service) SignUp(ctx context.Context, request *v1pb.SignUpRequest)
}
}
func
(
s
*
APIV1Service
)
SignOut
(
ctx
context
.
Context
,
_
*
v1pb
.
SignOutRequest
)
(
*
emptypb
.
Empty
,
error
)
{
func
(
s
*
APIV1Service
)
SignOut
(
ctx
context
.
Context
,
_
*
v1pb
.
SignOutRequest
)
(
*
emptypb
.
Empty
,
error
)
{
accessToken
,
ok
:=
ctx
.
Value
(
accessTokenContextKey
)
.
(
string
)
// Try to delete the access token from the store.
if
ok
{
_
,
err
:=
s
.
DeleteUserAccessToken
(
ctx
,
&
v1pb
.
DeleteUserAccessTokenRequest
{
AccessToken
:
accessToken
,
})
if
err
!=
nil
{
slog
.
Error
(
"failed to delete access token"
,
err
)
}
}
if
err
:=
s
.
clearAccessTokenCookie
(
ctx
);
err
!=
nil
{
if
err
:=
s
.
clearAccessTokenCookie
(
ctx
);
err
!=
nil
{
return
nil
,
status
.
Errorf
(
codes
.
Internal
,
"failed to set grpc header, error: %v"
,
err
)
return
nil
,
status
.
Errorf
(
codes
.
Internal
,
"failed to set grpc header, error: %v"
,
err
)
}
}
...
...
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