forked from Georg/limnoria-keycloak
Skeleton IRC group query function
Signed-off-by: Georg <georg@lysergic.dev>
This commit is contained in:
parent
31ed2ed1fe
commit
cdd640ab9e
73
plugin.py
73
plugin.py
@ -32,6 +32,7 @@ import re
|
|||||||
import requests
|
import requests
|
||||||
import secrets
|
import secrets
|
||||||
import string
|
import string
|
||||||
|
import json
|
||||||
from supybot import utils, plugins, ircutils, callbacks, ircmsgs
|
from supybot import utils, plugins, ircutils, callbacks, ircmsgs
|
||||||
from supybot.commands import *
|
from supybot.commands import *
|
||||||
from supybot.ircmsgs import nick
|
from supybot.ircmsgs import nick
|
||||||
@ -150,21 +151,25 @@ class Keycloak(callbacks.Plugin):
|
|||||||
except:
|
except:
|
||||||
print("ERROR: Keycloak token could not be installed.")
|
print("ERROR: Keycloak token could not be installed.")
|
||||||
irc.error(usererr)
|
irc.error(usererr)
|
||||||
try:
|
url = server + '/auth/admin/realms/' + realm + '/users/' + uid + '/groups/' + gid
|
||||||
url = server + '/auth/admin/realms/' + realm + '/users/' + uid + '/groups/' + gid
|
if option == 'true' or option == 'on' or option == '1':
|
||||||
if option == 'true' or option == 'on' or option == '1':
|
choice = 'enable'
|
||||||
option = 'enable'
|
elif option == 'false' or option == 'off' or option == '0':
|
||||||
response = requests.put(
|
choice = 'disable'
|
||||||
url,
|
elif option == 'query' or option == 'status':
|
||||||
headers = {'Content-Type': 'application/json', 'Authorization': 'Bearer ' + token})
|
choice = 'query'
|
||||||
if option == 'false' or option == 'off' or option == '0':
|
else:
|
||||||
option == 'disable'
|
choice = 'faulty'
|
||||||
response = requests.delete(
|
if choice == 'enable':
|
||||||
url,
|
response = requests.put(
|
||||||
headers = {'Content-Type': 'application/json', 'Authorization': 'Bearer ' + token})
|
url,
|
||||||
if option != 'true' != 'on' != '1' != 'false' != 'off' != '0':
|
headers = {'Content-Type': 'application/json', 'Authorization': 'Bearer ' + token})
|
||||||
irc.error('Invalid argument.')
|
if choice == 'disable':
|
||||||
else:
|
response = requests.delete(
|
||||||
|
url,
|
||||||
|
headers = {'Content-Type': 'application/json', 'Authorization': 'Bearer ' + token})
|
||||||
|
if choice == 'enable' or choice == 'disable':
|
||||||
|
try:
|
||||||
print("Keycloak: HTTP Status ", response.status_code)
|
print("Keycloak: HTTP Status ", response.status_code)
|
||||||
try:
|
try:
|
||||||
print("Keycloak: Response Text: ", response.text)
|
print("Keycloak: Response Text: ", response.text)
|
||||||
@ -176,14 +181,40 @@ class Keycloak(callbacks.Plugin):
|
|||||||
print("Keycloak: No or invalid response JSON. This it not an error.")
|
print("Keycloak: No or invalid response JSON. This it not an error.")
|
||||||
status = response.status_code
|
status = response.status_code
|
||||||
if status == 204:
|
if status == 204:
|
||||||
print(" SSO user " + user + " is now authorized to authenticate IRC user " + user)
|
print(" SSO user " + user + " has been added to group, if it wasn't already.")
|
||||||
irc.queueMsg(msg=ircmsgs.IrcMsg(command='PRIVMSG', args=(msg.nick, f'{pw}')))
|
#irc.reply("SSO user " + user + " is now authorized to authenticate IRC user " + user) - we currently cannot actually tell
|
||||||
irc.reply("OK, I sent you a private message.")
|
irc.reply("Success.")
|
||||||
if status != 204:
|
if status != 204:
|
||||||
print("ERROR: HTTP request did not succeed.")
|
print("ERROR: HTTP request did not succeed. I tried these values:")
|
||||||
|
print("URL: " + url)
|
||||||
|
print("Group: " + gid)
|
||||||
|
print("User: " + uid)
|
||||||
irc.error(usererr)
|
irc.error(usererr)
|
||||||
except:
|
except:
|
||||||
print('Operation failed.')
|
print('Operation failed.')
|
||||||
|
# if choice == 'query':
|
||||||
|
# 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)
|
||||||
|
# userdata = response.json()
|
||||||
|
# print(userdata)
|
||||||
|
# print(response)
|
||||||
|
# userjson = json.loads(userdata)
|
||||||
|
# print(userjson)
|
||||||
|
# if userdetails != '[]' or '{}':
|
||||||
|
# if gid in userjson:
|
||||||
|
# irc.reply("Your IRC user is enabled for SSO authentication.")
|
||||||
|
# print(userdetails)
|
||||||
|
# else:
|
||||||
|
# irc.reply("Your IRC user is not enabled for SSO authentication.")
|
||||||
|
# except:
|
||||||
|
# print('Operation failed.')
|
||||||
|
else:
|
||||||
|
irc.error('Invalid argument.')
|
||||||
|
|
||||||
ircprom = wrap(ircprom, ['anything'])
|
ircprom = wrap(ircprom, ['anything'])
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user