[hydra] also set redirect url on setup

This commit is contained in:
tuxcoder 2023-12-24 11:10:49 +01:00
parent 2d2766ac30
commit aaf91cb580

View file

@ -24,6 +24,7 @@ class HydraService:
client_name = app.config['OAUTH_ID'] client_name = app.config['OAUTH_ID']
client_secret = app.config['OAUTH_SECRET'] client_secret = app.config['OAUTH_SECRET']
public_url = app.config['PUBLIC_URL']
clients = list_o_auth_2_clients.sync_detailed(_client=self.hydra_client).parsed clients = list_o_auth_2_clients.sync_detailed(_client=self.hydra_client).parsed
if clients is None: if clients is None:
@ -35,8 +36,7 @@ class HydraService:
break break
if client is None: if client is None:
public_url = app.config['PUBLIC_URL'] client_req = OAuth20Client(
client = OAuth20Client(
client_name="identiy_provider", client_name="identiy_provider",
# client_id=client_id, # client_id=client_id,
client_secret=client_secret, client_secret=client_secret,
@ -46,11 +46,13 @@ class HydraService:
redirect_uris=[ f"{public_url}/oauth/authorized" ], redirect_uris=[ f"{public_url}/oauth/authorized" ],
token_endpoint_auth_method="client_secret_basic", token_endpoint_auth_method="client_secret_basic",
) )
ret = create_o_auth_2_client.sync(json_body=client, _client=self.hydra_client) ret = create_o_auth_2_client.sync(json_body=client_req, _client=self.hydra_client)
if ret is None: if ret is None:
raise RuntimeError("could not create account") raise RuntimeError("could not create account")
client = ret
else: else:
client.client_secret = client_secret client.client_secret = client_secret
client.redirect_uris = [ f"{public_url}/oauth/authorized" ]
ret = set_o_auth_2_client.sync(id=client.client_id, json_body=client, _client=self.hydra_client) ret = set_o_auth_2_client.sync(id=client.client_id, json_body=client, _client=self.hydra_client)
if ret is None: if ret is None:
raise RuntimeError("could not update account") raise RuntimeError("could not update account")