#!/usr/bin/env python3 # Copyright (C) 2020-2021 The Software Heritage developers # See the AUTHORS file at the top-level directory of this distribution # License: GNU Affero General Public License version 3, or any later version # See top-level LICENSE file for more information from keycloak import KeycloakAdmin SERVER_URL = "https://auth.softwareheritage.org/auth/" REALM_NAME = "SoftwareHeritage" ADMIN = {"username": "anlambert", "password": "***"} # login as admin in swh realm KEYCLOAK_ADMIN = KeycloakAdmin( SERVER_URL, ADMIN["username"], ADMIN["password"], REALM_NAME ) roles = [] for role in ["offline_access", "uma_authorization"]: realm_role = KEYCLOAK_ADMIN.get_realm_role(role) roles.append(realm_role) for user in KEYCLOAK_ADMIN.get_users(): KEYCLOAK_ADMIN.assign_realm_roles(user["id"], "", roles)