$this->l->t('Your redirect URL needs to be a full URL for example: https://yourdomain.com/path')], Http::STATUS_BAD_REQUEST); } $client = new Client(); $client->setName($name); $client->setRedirectUri($redirectUri); $secret = $this->secureRandom->generate(64, self::validChars); $hashedSecret = bin2hex($this->crypto->calculateHMAC($secret)); $client->setSecret($hashedSecret); $client->setClientIdentifier($this->secureRandom->generate(64, self::validChars)); $client = $this->clientMapper->insert($client); $result = [ 'id' => $client->getId(), 'name' => $client->getName(), 'redirectUri' => $client->getRedirectUri(), 'clientId' => $client->getClientIdentifier(), 'clientSecret' => $secret, ]; return new JSONResponse($result); } #[PasswordConfirmationRequired] public function deleteClient(int $id): JSONResponse { $client = $this->clientMapper->getByUid($id); $this->userManager->callForSeenUsers(function (IUser $user) use ($client): void { // Skip tokens that are marked for remote wipe so revoking the // OAuth2 client does not silently cancel a pending wipe. $tokens = $this->tokenProvider->getTokenByUser($user->getUID()); foreach ($tokens as $token) { if ($token->getName() !== $client->getName()) { continue; } try { $this->tokenProvider->getTokenById($token->getId()); } catch (WipeTokenException $e) { $this->logger->info('Preserving token {tokenId} of user {uid}: marked for remote wipe, OAuth2 client revoke would cancel the wipe.', [ 'tokenId' => $token->getId(), 'uid' => $user->getUID(), ]); continue; } catch (InvalidTokenException $e) { // Token already invalid; let invalidateTokenById handle it. } $this->tokenProvider->invalidateTokenById($user->getUID(), $token->getId()); } }); $this->accessTokenMapper->deleteByClientId($id); $this->clientMapper->delete($client); return new JSONResponse([]); } }