Skip to content

Instantly share code, notes, and snippets.

@rgpublic
Created July 24, 2018 10:17
Show Gist options
  • Save rgpublic/8457d98b0fcc0c54893b9907f9b8b825 to your computer and use it in GitHub Desktop.
Save rgpublic/8457d98b0fcc0c54893b9907f9b8b825 to your computer and use it in GitHub Desktop.
Synapse deactive user
#!/bin/bash
echo -e "\e[97mPlease enter password for Synapse/Matrix root user:\e[0m";
read -s password
echo -e "\e[97mEnter user you'd like to deactivate\e[0m";
read user
url_user=`echo -n "$user" | jq -s -R -r @uri`
json=`curl -s --insecure -XPOST -d '{"type":"m.login.password", "user":"root", "password":"'$password'"}' "https://localhost:8448/_matrix/client/r0/login"`
access_token=`echo "$json" | jq -r ".access_token"`
curl --insecure -XPOST -H "Authorization: Bearer $access_token" -H "Content-Type: application/json" -d \
'{}' "https://localhost:8448/_matrix/client/r0/admin/deactivate/$url_user"
@krombel
Copy link

krombel commented Jul 29, 2018

  1. It might be easier to just extract the access_token from a running admin-user session (e.g. through settings in riot-web)

  2. If you are going the login-first way you propably want to add a call to remove the new session as well. If you else run this script very often you will have a lot of sessions which it might get hard to delete all of them (especially as it might get hard to distinguish the "real" from the one-time access_tokens)

@djotaku
Copy link

djotaku commented Apr 6, 2020

what is jq? My computer doesn't have that

@djotaku
Copy link

djotaku commented Apr 6, 2020

oh, it's a command. I was able to install.

@kenmickles
Copy link

@catchra
Copy link

catchra commented Feb 19, 2022

@rgpublic
it doesn't look like you're script works anymore as it looks like the API endpoint has changed

from
https://localhost:8448/_matrix/client/r0/admin/deactivate/$url_user

to
https://localhost:8448/_synapse/admin/v1/deactivate/$url_user

other than that the script works well and it's very helpful

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment