Skip to content

Commit

Permalink
Update fieldkit consumer to only use refresh_token and password grants
Browse files Browse the repository at this point in the history
  • Loading branch information
paul121 authored and mstenta committed Nov 1, 2023
1 parent d0e305d commit 4226394
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
6 changes: 5 additions & 1 deletion modules/core/fieldkit/farm_fieldkit.install
Expand Up @@ -17,9 +17,13 @@ function farm_fieldkit_install() {
'label' => 'Field Kit',
'client_id' => 'fieldkit',
'access_token_expiration' => 3600,
'grant_types' => [
'refresh_token',
'password',
],
'redirect' => 'https://farmOS.app',
'allowed_origins' => 'https://farmos.app',
'owner_id' => '',
'owner_id' => NULL,
'secret' => NULL,
'confidential' => FALSE,
'third_party' => FALSE,
Expand Down
13 changes: 13 additions & 0 deletions modules/core/fieldkit/farm_fieldkit.post_update.php
Expand Up @@ -9,7 +9,20 @@
* Enable simple oauth password grant.
*/
function farm_fieldkit_post_update_enable_password_grant(&$sandbox = NULL) {

// Enable password grant module.
if (!\Drupal::service('module_handler')->moduleExists('simple_oauth_password_grant')) {
\Drupal::service('module_installer')->install(['simple_oauth_password_grant']);
}

// Update existing fieldkit consumer.
$consumers = \Drupal::entityTypeManager()->getStorage('consumer')
->loadByProperties(['client_id' => 'fieldkit']);
if (!empty($consumers)) {
/** @var \Drupal\consumers\Entity\ConsumerInterface $fieldkit */
$fieldkit = reset($consumers);
$fieldkit->set('user_id', NULL);
$fieldkit->set('grant_types', ['refresh_token', 'password']);
$fieldkit->save();
}
}

0 comments on commit 4226394

Please sign in to comment.