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
23750014
Commit
23750014
authored
Sep 18, 2023
by
Steven
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
chore: fix acl interceptor
parent
462f10ab
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
5 deletions
+10
-5
acl.go
api/v2/acl.go
+10
-5
No files found.
api/v2/acl.go
View file @
23750014
...
...
@@ -13,6 +13,7 @@ import (
"google.golang.org/grpc/status"
"github.com/usememos/memos/api/auth"
"github.com/usememos/memos/common/util"
storepb
"github.com/usememos/memos/proto/gen/store"
"github.com/usememos/memos/store"
)
...
...
@@ -103,18 +104,22 @@ func (in *GRPCAuthInterceptor) authenticate(ctx context.Context, accessToken str
)
}
username
:=
claims
.
Name
// We either have a valid access token or we will attempt to generate new access token.
userID
,
err
:=
util
.
ConvertStringToInt32
(
claims
.
Subject
)
if
err
!=
nil
{
return
""
,
errors
.
Wrap
(
err
,
"malformed ID in the token"
)
}
user
,
err
:=
in
.
Store
.
GetUser
(
ctx
,
&
store
.
FindUser
{
Username
:
&
username
,
ID
:
&
userID
,
})
if
err
!=
nil
{
return
""
,
errors
.
Wrap
(
err
,
"failed to get user"
)
}
if
user
==
nil
{
return
""
,
errors
.
Errorf
(
"user %q not exists
in the access token"
,
username
)
return
""
,
errors
.
Errorf
(
"user %q not exists
"
,
userID
)
}
if
user
.
RowStatus
==
store
.
Archived
{
return
""
,
errors
.
Errorf
(
"user %q is archived"
,
user
name
)
return
""
,
errors
.
Errorf
(
"user %q is archived"
,
user
ID
)
}
accessTokens
,
err
:=
in
.
Store
.
GetUserAccessTokens
(
ctx
,
user
.
ID
)
...
...
@@ -125,7 +130,7 @@ func (in *GRPCAuthInterceptor) authenticate(ctx context.Context, accessToken str
return
""
,
status
.
Errorf
(
codes
.
Unauthenticated
,
"invalid access token"
)
}
return
username
,
nil
return
user
.
User
name
,
nil
}
func
getTokenFromMetadata
(
md
metadata
.
MD
)
(
string
,
error
)
{
...
...
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