I'm trying to retrieve and store the guilds a Discord user is in so that at in application specific policies there can be checked per application if a user is in a specific guild or not.
The method to actually store more data alongside a user or have it retain in the current authentication session is not clear to me (the policy below doesn't actually store the guild ids).
Is there a way to "store" this data in the authentication session or the user model somehow?
Somewhere in a (semi) persistent location so it can be access in policies that define access to specific applications?
See the authentication flow and the retrieval policy for what I've gotten up with so far.
Thanks in advance ๐
# Get the user-source connection object from the context, and get the access token
connection = context["goauthentik.io/sources/connection"]
access_token = connection.access_token
guilds_response = requests.get(
"https://discord.com/api/users/@me/guilds",
headers={
"Authorization": "Bearer " + access_token
}
)
if guilds_response.status_code is not 200:
return False
guilds_response.raise_for_status()
guilds = guilds_response.json()
guilds = list(map(lambda x: x['id'], guilds))
request.context["flow_plan"].context["pending_user"].attributes["discord"] = {}
request.context["flow_plan"].context["pending_user"].attributes["discord"]["guilds"] = guilds
return True