Skip to content

Implement automatic API key generation and regeneration with custom notifications - #154

Merged
itshypax merged 5 commits into
mainfrom
copilot/fix-api-key-creation-issue
Nov 6, 2025
Merged

Implement automatic API key generation and regeneration with custom notifications#154
itshypax merged 5 commits into
mainfrom
copilot/fix-api-key-creation-issue

Conversation

Copilot AI commented Nov 6, 2025

Copy link
Copy Markdown
Contributor

API keys were not automatically generated during setup after config system migration, and lacked UI for viewing/regenerating. Additionally, native browser dialogs needed replacement with the custom notification system.

Changes

Database Migration (insert_intra_config_defaults_04112025.php)

  • Generate cryptographically secure 64-char hex API key on setup using bin2hex(random_bytes(32))
  • Special ON DUPLICATE KEY UPDATE prevents overwriting existing keys on re-runs

Config UI (settings/system/config.php)

  • Display API_KEY in readonly input field with regeneration button
  • Replace native confirm()/alert() with showConfirm()/showAlert() from dialogs.js
  • Async regeneration flow with loading state and automatic field update
<?php if ($config['config_key'] === 'API_KEY'): ?>
    <div class="input-group">
        <input type="text" class="form-control" value="..." readonly>
        <button onclick="regenerateApiKey(event)">
            <i class="fa-solid fa-rotate"></i> Neu generieren
        </button>
    </div>
<?php endif; ?>

Regeneration Endpoint (settings/system/regenerate-api-key.php)

  • Admin-only POST endpoint with session validation
  • Returns new key via JSON, logs action in audit trail
  • Verifies database update success via rowCount()

Security

  • random_bytes() for cryptographic strength
  • Admin permission check + audit logging
  • XSS protection via json_encode(BASE_PATH)
  • API_KEY marked is_editable=0 to prevent accidental modification
Original prompt

This section details on the original issue you should resolve

<issue_title>API-Key wird nicht mehr random erstellt</issue_title>
<issue_description>## Reproduzierbar?
Konntest du den Fehler selbst erneut provozieren?

  • Ja
  • Nein

Wo tritt der Fehler auf?

  • Computer (Browser)
  • Handy (Browser)
  • Ingame (intraTab)

Welche Version wird verwendet?

//

Beschreibe den Fehler

Bis zur Änderung der config wurde der API_KEY im Setup automatisch erstellt, jetzt nicht mehr.

  1. Sollte der API_KEY in einem readonly oder disabled Feld trotzdem auf der config-Seite angezeigt werden
  2. Man sollte den API_KEY per Knopfdruck neu generieren können
    </issue_description>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 4 commits November 6, 2025 15:25
Co-authored-by: itshypax <33388336+itshypax@users.noreply.github.com>
Co-authored-by: itshypax <33388336+itshypax@users.noreply.github.com>
Co-authored-by: itshypax <33388336+itshypax@users.noreply.github.com>
Co-authored-by: itshypax <33388336+itshypax@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix issue with random API-Key generation Implement automatic API key generation and regeneration with custom notifications Nov 6, 2025
Copilot AI requested a review from itshypax November 6, 2025 15:39
@itshypax
itshypax marked this pull request as ready for review November 6, 2025 15:39
@itshypax
itshypax merged commit c212a09 into main Nov 6, 2025
2 checks passed
@itshypax
itshypax deleted the copilot/fix-api-key-creation-issue branch November 6, 2025 15:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

API-Key wird nicht mehr random erstellt

2 participants