Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Matrix
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Container Registry
Model registry
Operate
Environments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
TeDomum
Matrix
Commits
b19d9e21
Unverified
Commit
b19d9e21
authored
7 years ago
by
David Baker
Committed by
GitHub
7 years ago
Browse files
Options
Downloads
Plain Diff
Merge pull request #2624 from matrix-org/rav/password_provider_notify_logout
Notify auth providers on logout
parents
1f080a6c
bc8a5c03
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
docs/password_auth_providers.rst
+10
-0
10 additions, 0 deletions
docs/password_auth_providers.rst
synapse/handlers/auth.py
+24
-2
24 additions, 2 deletions
synapse/handlers/auth.py
synapse/storage/registration.py
+8
-5
8 additions, 5 deletions
synapse/storage/registration.py
with
42 additions
and
7 deletions
docs/password_auth_providers.rst
+
10
−
0
View file @
b19d9e21
...
@@ -87,3 +87,13 @@ Password auth provider classes may optionally provide the following methods.
...
@@ -87,3 +87,13 @@ Password auth provider classes may optionally provide the following methods.
The method should return a Twisted ``Deferred`` object, which resolves to
The method should return a Twisted ``Deferred`` object, which resolves to
``True`` if authentication is successful, and ``False`` if not.
``True`` if authentication is successful, and ``False`` if not.
``someprovider.on_logged_out``\(*user_id*, *device_id*, *access_token*)
This method, if implemented, is called when a user logs out. It is passed
the qualified user ID, the ID of the deactivated device (if any: access
tokens are occasionally created without an associated device ID), and the
(now deactivated) access token.
It may return a Twisted ``Deferred`` object; the logout request will wait
for the deferred to complete but the result is ignored.
This diff is collapsed.
Click to expand it.
synapse/handlers/auth.py
+
24
−
2
View file @
b19d9e21
...
@@ -687,6 +687,7 @@ class AuthHandler(BaseHandler):
...
@@ -687,6 +687,7 @@ class AuthHandler(BaseHandler):
yield
self
.
store
.
user_delete_threepids
(
user_id
)
yield
self
.
store
.
user_delete_threepids
(
user_id
)
yield
self
.
store
.
user_set_password_hash
(
user_id
,
None
)
yield
self
.
store
.
user_set_password_hash
(
user_id
,
None
)
@defer.inlineCallbacks
def
delete_access_token
(
self
,
access_token
):
def
delete_access_token
(
self
,
access_token
):
"""
Invalidate a single access token
"""
Invalidate a single access token
...
@@ -696,8 +697,19 @@ class AuthHandler(BaseHandler):
...
@@ -696,8 +697,19 @@ class AuthHandler(BaseHandler):
Returns:
Returns:
Deferred
Deferred
"""
"""
return
self
.
store
.
delete_access_token
(
access_token
)
user_info
=
yield
self
.
auth
.
get_user_by_access_token
(
access_token
)
yield
self
.
store
.
delete_access_token
(
access_token
)
# see if any of our auth providers want to know about this
for
provider
in
self
.
password_providers
:
if
hasattr
(
provider
,
"
on_logged_out
"
):
yield
provider
.
on_logged_out
(
user_id
=
str
(
user_info
[
"
user
"
]),
device_id
=
user_info
[
"
device_id
"
],
access_token
=
access_token
,
)
@defer.inlineCallbacks
def
delete_access_tokens_for_user
(
self
,
user_id
,
except_token_id
=
None
,
def
delete_access_tokens_for_user
(
self
,
user_id
,
except_token_id
=
None
,
device_id
=
None
):
device_id
=
None
):
"""
Invalidate access tokens belonging to a user
"""
Invalidate access tokens belonging to a user
...
@@ -712,10 +724,20 @@ class AuthHandler(BaseHandler):
...
@@ -712,10 +724,20 @@ class AuthHandler(BaseHandler):
Returns:
Returns:
Deferred
Deferred
"""
"""
return
self
.
store
.
user_delete_access_tokens
(
tokens_and_devices
=
yield
self
.
store
.
user_delete_access_tokens
(
user_id
,
except_token_id
=
except_token_id
,
device_id
=
device_id
,
user_id
,
except_token_id
=
except_token_id
,
device_id
=
device_id
,
)
)
# see if any of our auth providers want to know about this
for
provider
in
self
.
password_providers
:
if
hasattr
(
provider
,
"
on_logged_out
"
):
for
token
,
device_id
in
tokens_and_devices
:
yield
provider
.
on_logged_out
(
user_id
=
user_id
,
device_id
=
device_id
,
access_token
=
token
,
)
@defer.inlineCallbacks
@defer.inlineCallbacks
def
add_threepid
(
self
,
user_id
,
medium
,
address
,
validated_at
):
def
add_threepid
(
self
,
user_id
,
medium
,
address
,
validated_at
):
# 'Canonicalise' email addresses down to lower case.
# 'Canonicalise' email addresses down to lower case.
...
...
This diff is collapsed.
Click to expand it.
synapse/storage/registration.py
+
8
−
5
View file @
b19d9e21
...
@@ -255,7 +255,8 @@ class RegistrationStore(background_updates.BackgroundUpdateStore):
...
@@ -255,7 +255,8 @@ class RegistrationStore(background_updates.BackgroundUpdateStore):
If None, tokens associated with any device (or no device) will
If None, tokens associated with any device (or no device) will
be deleted
be deleted
Returns:
Returns:
defer.Deferred:
defer.Deferred[list[str, str|None]]: a list of the deleted tokens
and device IDs
"""
"""
def
f
(
txn
):
def
f
(
txn
):
keyvalues
=
{
keyvalues
=
{
...
@@ -272,14 +273,14 @@ class RegistrationStore(background_updates.BackgroundUpdateStore):
...
@@ -272,14 +273,14 @@ class RegistrationStore(background_updates.BackgroundUpdateStore):
values
.
append
(
except_token_id
)
values
.
append
(
except_token_id
)
txn
.
execute
(
txn
.
execute
(
"
SELECT token FROM access_tokens WHERE %s
"
%
where_clause
,
"
SELECT token
, device_id
FROM access_tokens WHERE %s
"
%
where_clause
,
values
values
)
)
rows
=
self
.
cursor_to_dict
(
txn
)
tokens_and_devices
=
[(
r
[
0
],
r
[
1
])
for
r
in
txn
]
for
row
in
row
s
:
for
token
,
_
in
tokens_and_device
s
:
self
.
_invalidate_cache_and_stream
(
self
.
_invalidate_cache_and_stream
(
txn
,
self
.
get_user_by_access_token
,
(
row
[
"
token
"
]
,)
txn
,
self
.
get_user_by_access_token
,
(
token
,)
)
)
txn
.
execute
(
txn
.
execute
(
...
@@ -287,6 +288,8 @@ class RegistrationStore(background_updates.BackgroundUpdateStore):
...
@@ -287,6 +288,8 @@ class RegistrationStore(background_updates.BackgroundUpdateStore):
values
values
)
)
return
tokens_and_devices
yield
self
.
runInteraction
(
yield
self
.
runInteraction
(
"
user_delete_access_tokens
"
,
f
,
"
user_delete_access_tokens
"
,
f
,
)
)
...
...
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