Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
synapse
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Monitor
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Maunium
synapse
Commits
07fa53ec
Unverified
Commit
07fa53ec
authored
2 years ago
by
reivilibre
Committed by
GitHub
2 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Improve comments and error messages around access tokens. (#12577)
parent
b8fa24b0
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
changelog.d/12577.misc
+1
-0
1 addition, 0 deletions
changelog.d/12577.misc
synapse/api/auth.py
+11
-8
11 additions, 8 deletions
synapse/api/auth.py
with
12 additions
and
8 deletions
changelog.d/12577.misc
0 → 100644
+
1
−
0
View file @
07fa53ec
Improve comments and error messages around access tokens.
\ No newline at end of file
This diff is collapsed.
Click to expand it.
synapse/api/auth.py
+
11
−
8
View file @
07fa53ec
...
...
@@ -417,7 +417,8 @@ class Auth:
"""
if
rights
==
"
access
"
:
# first look in the database
# First look in the database to see if the access token is present
# as an opaque token.
r
=
await
self
.
store
.
get_user_by_access_token
(
token
)
if
r
:
valid_until_ms
=
r
.
valid_until_ms
...
...
@@ -434,7 +435,8 @@ class Auth:
return
r
# otherwise it needs to be a valid macaroon
# If the token isn't found in the database, then it could still be a
# macaroon, so we check that here.
try
:
user_id
,
guest
=
self
.
_parse_and_validate_macaroon
(
token
,
rights
)
...
...
@@ -482,8 +484,12 @@ class Auth:
TypeError
,
ValueError
,
)
as
e
:
logger
.
warning
(
"
Invalid macaroon in auth: %s %s
"
,
type
(
e
),
e
)
raise
InvalidClientTokenError
(
"
Invalid macaroon passed.
"
)
logger
.
warning
(
"
Invalid access token in auth: %s %s.
"
,
type
(
e
),
e
,
)
raise
InvalidClientTokenError
(
"
Invalid access token passed.
"
)
def
_parse_and_validate_macaroon
(
self
,
token
:
str
,
rights
:
str
=
"
access
"
...
...
@@ -504,10 +510,7 @@ class Auth:
try
:
macaroon
=
pymacaroons
.
Macaroon
.
deserialize
(
token
)
except
Exception
:
# deserialize can throw more-or-less anything
# doesn't look like a macaroon: treat it as an opaque token which
# must be in the database.
# TODO: it would be nice to get rid of this, but apparently some
# people use access tokens which aren't macaroons
# The access token doesn't look like a macaroon.
raise
_InvalidMacaroonException
()
try
:
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment