Enable manual updating of key

Created on 10 November 2022, almost 2 years ago
Updated 13 December 2023, 10 months ago

Problem/Motivation

I have keys from a separate application that I'd like to migrate to Drupal. Also, if a user inadvertently hits "generate new key" there is no way to recover/restore the old key.

Proposed resolution

Add the ability to create/edit the key manually: an additional form field and a permission to edit manually. Similar to the functionality in D7 Services API Keys Authentication

Remaining tasks

User interface changes

API changes

Data model changes

Feature request
Status

Needs review

Version

2.0

Component

User interface

Created by

🇺🇸United States boinkster

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

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • Open on Drupal.org →
    Core: 9.5.x + Environment: PHP 7.4 & MySQL 5.7
    last update about 1 year ago
    Waiting for branch to pass
  • 🇫🇮Finland oakulm

    I had a same request so here is a patch. Added a new button next to "Generate new key" called "Save key" and changed markup field to input field and added a handler for "Save key" action.

  • Open on Drupal.org →
    Core: 9.5.x + Environment: PHP 7.4 & MySQL 5.7
    last update about 1 year ago
    Waiting for branch to pass
  • Open in Jenkins → Open on Drupal.org →
    Core: 10.1.x + Environment: PHP 8.0 & MySQL 5.7
    last update about 1 year ago
    Composer require failure
  • 🇺🇸United States Jon Pugh Newburgh, NY

    I don't recommend this approach in the core module.

    However I too need the ability to insert an existing key.

    My use case is for testing and development of a number of sites at once. I want to hard code a key into the development settings so that I don't have to generate a new one and set it in the client everytime I install or sync the site in.

    To add a key, just set the api_key field on users. Custom code or an add on module for managing keys could be created.

    See UserKeyAuthForm::submitForm():

     // Generate a new key.
        User::load($form['#uid'])
          ->set('api_key', $this->keyAuth->generateKey())
          ->save();
    
  • Open on Drupal.org →
    Core: 9.5.x + Environment: PHP 7.4 & MySQL 5.7
    last update about 1 year ago
    Waiting for branch to pass
  • @jon-pugh opened merge request.
  • Open on Drupal.org →
    Core: 9.5.x + Environment: PHP 7.4 & MySQL 5.7
    last update about 1 year ago
    Waiting for branch to pass
  • 🇺🇸United States Jon Pugh Newburgh, NY

    I created a new branch and merge request to add a drush command: 'key:set'

    Patch attached.

    MR here: https://git.drupalcode.org/project/key_auth/-/merge_requests/13

  • Open on Drupal.org →
    Core: 9.5.x + Environment: PHP 7.4 & MySQL 5.7
    last update about 1 year ago
    Waiting for branch to pass
  • 🇺🇸United States Jon Pugh Newburgh, NY

    Here's what it looks like:

    www-data@7840126ff815:~$ drush key:set admin
    
    In KeyAuthCommands.php line 64:
                                                                     
      User already has API key. Use --force option to overwrite it.  
                                                                     
    
    www-data@7840126ff815:~$ drush key:set admin --force
    
     ! [NOTE] User's existing API key was removed.                                             
    
     [success] API key for user admin was set to 9a99e567bbd5983beb318274baf96273.
    www-data@7840126ff815:~$ drush key:set admin abc123 --force
    
     ! [NOTE] User's existing API key was removed.                                             
    
     [success] API key for user admin was set to abc123.
    
  • Open on Drupal.org →
    Core: 9.5.x + Environment: PHP 7.4 & MySQL 5.7
    last update about 1 year ago
    Waiting for branch to pass
  • 🇺🇸United States Jon Pugh Newburgh, NY

    Catch missing user and improve messaging.

  • Open on Drupal.org →
    Core: 9.5.x + Environment: PHP 7.4 & MySQL 5.7
    last update about 1 year ago
    Waiting for branch to pass
  • 🇫🇮Finland oakulm

    I don't recommend this approach in the core module.

    Hi! Could you explain this a bit more? Because I can't really see much the difference if you use drush or admin UI for this.

  • Status changed to Needs work 10 months ago
  • Still needs a permission added for whether a user role can edit the key manually.

  • Status changed to Needs review 10 months ago
  • 🇮🇳India rajeshreeputra Pune

    @jonpugh, @solideogloria would you mind joining the project to maintain, as I get very less time to look into it.

  • I could possibly co-maintain, but I don't have any real experience maintaining a module. I've only done patches and merge requests. Though the Media: YouTube module is listed on my profile, I didn't do anything for that module and removed myself from being maintainer.

    I also don't have a dev environment set up for contributing, so when I want to contribute patches or code to a module, I don't have any phpcs integration in my IDE; I just open the folder in a workspace and modify the files. I have yet to figure that out.

Production build 0.71.5 2024