From 3e43c25d84b9e9bd6906985e9192b7fc30126d15 Mon Sep 17 00:00:00 2001 From: Helmut Merz Date: Mon, 4 Aug 2025 18:39:18 +0200 Subject: [PATCH] org.user, web.client: user update on zitadel working --- scopes/org/user.py | 34 ++++++++++++++++++++++++++++++---- scopes/web/client.py | 19 ++++++++++++++----- 2 files changed, 44 insertions(+), 9 deletions(-) diff --git a/scopes/org/user.py b/scopes/org/user.py index 4c97879..fc03143 100644 --- a/scopes/org/user.py +++ b/scopes/org/user.py @@ -50,12 +50,38 @@ class ExtUser: ), organization=dict(orgId=params['organization_id']), ) - if self.user.hashedPassword: - data['hashedPassword'] = self.user.hashedPassword return data - def send(self): + def create(self, updateIfExits=False): clt = client.ApiClient(config.oidc_provider) data = self.asDict() - res = clt.post(self.endpoints['users_human'], data) + if self.user.hashedPassword: + data['hashedPassword'] = self.user.hashedPassword + status, res = clt.post(self.endpoints['users_human'], data) + if status > 201: + if updateIfExits: + return self.update() + else: + return status, res + if self.user.grants: + return self.createGrants() + def update(self, createIfMissing=False): + clt = client.ApiClient(config.oidc_provider) + data = self.asDict() + if self.user.hashedPassword: + data['password'] = dict(hashedPassword=self.user.hashedPassword) + status, res = clt.put(self.endpoints['users_human'], self.userId, data) + if status > 200: + if createIfMissing: + return self.create() + else: + return status, res + if self.user.grants: + return self.updateGrants() + + def createGrants(self): + pass + + def updateGrants(self): + pass diff --git a/scopes/web/client.py b/scopes/web/client.py index 7cc5ce6..bfd3742 100644 --- a/scopes/web/client.py +++ b/scopes/web/client.py @@ -24,12 +24,21 @@ class ApiClient: def post(self, endpoint, data): headers = self.authentication() + headers['Content-Type'] = 'application/json' # self.makeUrl(endpoint) url = '/'.join((self.baseUrl, endpoint)) resp = requests.post(url, json=data, headers=headers) - if resp.status_code != 200: - logger.error('post %s: %s', url, resp.text) - return resp.text - data = resp.json() - return data + if resp.status_code >= 400: + logger.error('post %s: %s %s', url, resp.status_code, resp.text) + return resp.status_code, resp.json() + + def put(self, endpoint, objId, data): + headers = self.authentication() + headers['Content-Type'] = 'application/json' + # self.makeUrl(endpoint) + url = '/'.join((self.baseUrl, endpoint, objId)) + resp = requests.put(url, json=data, headers=headers) + if resp.status_code >= 400: + logger.error('post %s: %s %s', url, resp.status_code, resp.text) + return resp.status_code, resp.json()