@@ -168,7 +168,7 @@ public function add(): Response
168168
169169 $ owner = $ this ->authorization ->isAdmin () ? null : $ this ->authorization ->getUserId ();
170170
171- $ client = $ this ->buildClientFromFormData (
171+ $ client = $ this ->buildClientEntityFromFormData (
172172 $ form ,
173173 $ this ->sspBridge ->utils ()->random ()->generateID (),
174174 $ this ->sspBridge ->utils ()->random ()->generateID (),
@@ -179,6 +179,8 @@ public function add(): Response
179179 $ owner ,
180180 );
181181
182+ // TODO mivanci Check if the entity identifier already exists.
183+
182184 $ this ->clientRepository ->add ($ client );
183185
184186 // Also persist allowed origins for this client.
@@ -209,11 +211,75 @@ public function add(): Response
209211 );
210212 }
211213
214+ /**
215+ * @throws \SimpleSAML\Error\ConfigurationError
216+ * @throws \SimpleSAML\Module\oidc\Server\Exceptions\OidcServerException
217+ * @throws \SimpleSAML\Error\Exception
218+ * @throws \SimpleSAML\Module\oidc\Exceptions\OidcException
219+ * @throws \JsonException
220+ */
221+ public function edit (Request $ request ): Response
222+ {
223+ $ originalClient = $ this ->getClientFromRequest ($ request );
224+ $ clientAllowedOrigins = $ this ->allowedOriginRepository ->get ($ originalClient ->getIdentifier ());
225+ $ form = $ this ->formFactory ->build (ClientForm::class);
226+
227+ $ clientData = $ originalClient ->toArray ();
228+ $ clientData ['allowed_origin ' ] = $ clientAllowedOrigins ;
229+ $ form ->setDefaults ($ clientData );
230+
231+ if ($ form ->isSuccess ()) {
232+ $ updatedAt = $ this ->helpers ->dateTime ()->getUtc ();
233+
234+ $ updatedClient = $ this ->buildClientEntityFromFormData (
235+ $ form ,
236+ $ originalClient ->getIdentifier (),
237+ $ originalClient ->getSecret (),
238+ $ originalClient ->getRegistrationType (),
239+ $ updatedAt ,
240+ $ originalClient ->getCreatedAt (),
241+ $ originalClient ->getExpiresAt (),
242+ $ originalClient ->getOwner (),
243+ );
244+
245+ // TODO mivanci Check if the entity identifier already exists for other client.
246+
247+ $ this ->clientRepository ->update ($ updatedClient );
248+
249+ // Also persist allowed origins for this client.
250+ is_array ($ allowedOrigins = $ form ->getValues ('array ' )['allowed_origin ' ] ?? []) ||
251+ throw new OidcException ('Unexpected value for allowed origins. ' );
252+ /** @var string[] $allowedOrigins */
253+ $ this ->allowedOriginRepository ->set ($ originalClient ->getIdentifier (), $ allowedOrigins );
254+
255+ $ this ->sessionMessagesService ->addMessage (Translate::noop ('Client has been updated. ' ));
256+
257+ return $ this ->routes ->getRedirectResponseToModuleUrl (
258+ RoutesEnum::AdminClientsShow->value ,
259+ [ParametersEnum::ClientId->value => $ originalClient ->getIdentifier ()],
260+ );
261+ }
262+
263+ return $ this ->templateFactory ->build (
264+ 'oidc:clients/edit.twig ' ,
265+ [
266+ 'originalClient ' => $ originalClient ,
267+ 'form ' => $ form ,
268+ 'actionRoute ' => $ this ->routes ->urlAdminClientsEdit ($ originalClient ->getIdentifier ()),
269+ 'regexUri ' => ClientForm::REGEX_URI ,
270+ 'regexAllowedOriginUrl ' => ClientForm::REGEX_ALLOWED_ORIGIN_URL ,
271+ 'regexHttpUri ' => ClientForm::REGEX_HTTP_URI ,
272+ 'regexHttpUriPath ' => ClientForm::REGEX_HTTP_URI_PATH ,
273+ ],
274+ RoutesEnum::AdminClients->value ,
275+ );
276+ }
277+
212278 /**
213279 * TODO mivanci Move to ClientEntityFactory::fromRegistrationData on dynamic client registration implementation.
214280 * @throws \SimpleSAML\Module\oidc\Exceptions\OidcException
215281 */
216- protected function buildClientFromFormData (
282+ protected function buildClientEntityFromFormData (
217283 Form $ form ,
218284 string $ identifier ,
219285 string $ secret ,
0 commit comments