Use site and secret keys from settings.php or environment variables

Created on 10 May 2024, 7 months ago
Updated 26 June 2024, 6 months ago

Problem/Motivation

Currently, the site key and secret keys are stored in configuration files. With sites who are running a typical workflow of running the sites on multiple environments, this could be a problem as domain names are different for each environment and often change. Whitelist domains for each environment from turnsitle might not be a solution for environment so each environment should be able to provide its own values without breaking configuration import workflow.

Steps to reproduce

Proposed resolution

Modify code so that it override values from settings file if available.

Remaining tasks

User interface changes

Potentially disable the secret and site keys fields in back-end if the values are set in settings.

API changes

Just a rough idea, happy to provide a complete tested patch if author and others think this feature might be useful for community:
In turnstile.module file, add this after line 29 and 92:

  // Override values from settings.php
  if (!empty(Settings::get('turnstile_site_key')) && !empty(Settings::get('turnstile_secret_key'))) {
    $turnstile_site_key = Settings::get('turnstile_site_key');
    $turnstile_secret_key = Settings::get('turnstile_secret_key');
  }

and optionally do the same condition check in form file to disable fields if the values are in settings.

Data model changes

✨ Feature request
Status

Closed: works as designed

Version

1.1

Component

Code

Created by

πŸ‡¦πŸ‡ΊAustralia iaslam

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @iaslam
  • Status changed to Postponed: needs info 7 months ago
  • πŸ‡ΊπŸ‡ΈUnited States greatmatter

    Hi! Have you considered using

    $config['turnstile.settings']['site_key'] = $_ENV['YOUR ENVIRONMENT VARIABLE NAME'];
    $config['turnstile.settings']['secret_key'] = $_ENV['YOUR ENVIRONMENT VARIABLE NAME'];

    in $settings.php, or am I missing the point?

  • Status changed to Closed: works as designed 6 months ago
  • πŸ‡¬πŸ‡§United Kingdom smaz England, UK

    Can confirm the suggestion in #2 works & allows you to have secret keys outside of config files.

Production build 0.71.5 2024