summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGeorg2021-09-02 21:08:18 +0200
committerGeorg2021-09-02 21:08:18 +0200
commit4f9b155d66524d4644e7ac94430148e1f9a4618a (patch)
tree59c9934f81966a792300fabc269193140b432ea9
parentcdd640ab9ef08181529a72395be36c75b6726a90 (diff)
downloadkeycloak-4f9b155d66524d4644e7ac94430148e1f9a4618a.tar.gz
keycloak-4f9b155d66524d4644e7ac94430148e1f9a4618a.tar.bz2
keycloak-4f9b155d66524d4644e7ac94430148e1f9a4618a.zip
Generic user group query function
Signed-off-by: Georg <georg@lysergic.dev>
-rw-r--r--plugin.py44
1 files changed, 43 insertions, 1 deletions
diff --git a/plugin.py b/plugin.py
index ec247a7..23a7f82 100644
--- a/plugin.py
+++ b/plugin.py
@@ -128,7 +128,7 @@ class Keycloak(callbacks.Plugin):
register = wrap(register, ['anything'])
def ircprom(self, irc, msg, args, option):
- """<status>
+ """<option>
true/on = enable authentication to your IRC account with an SSO account going by the same username --
false/off = allow authentication to your IRC account ONLY with internal IRC credentials (NickServ) --
Warning: Enabling this without having an SSO account with the same username as your IRC nickname is a security risk."""
@@ -218,6 +218,48 @@ class Keycloak(callbacks.Plugin):
ircprom = wrap(ircprom, ['anything'])
+ def user(self, irc, msg, args, option):
+ """<option>
+ groups = dumps the groups you are joined to."""
+
+ user = msg.nick
+ server = self.registryValue('backend.server')
+ realm = self.registryValue('backend.realm')
+ tokenurl = self.registryValue('backend.token')
+ usererr = self.registryValue('replies.error')
+ try:
+ tokendl = requests.get(tokenurl)
+ tokendata = tokendl.json()
+ token = tokendata['access_token']
+ url = server + '/auth/admin/realms/' + realm + '/users'
+ userdata = requests.get(url, params = {'username': user}, headers = {'Content-Type': 'application/json', 'Authorization': 'Bearer ' + token})
+ userresp = userdata.json()
+ uid = userresp[0]['id']
+ print(user, uid)
+ except:
+ print("ERROR: Keycloak token could not be installed.")
+ irc.error(usererr)
+ if option == 'groups':
+ try:
+ url = server + '/auth/admin/realms/' + realm + '/users/' + uid + '/groups'
+ response = requests.get(
+ url,
+ headers = {'Content-Type': 'application/json', 'Authorization': 'Bearer ' + token})
+ test = "{}"
+ print(url)
+ usergroups = response.json()
+ if usergroups:
+ for group in usergroups:
+ groupname = usergroups[0]['name']
+ irc.reply(groupname)
+ else:
+ irc.reply("No groups.")
+ except:
+ print('Operation failed.')
+ irc.reply(usererr)
+
+ user = wrap(user, ['anything'])
+
Class = Keycloak