Update fieldkit consumer to only use refresh_token and password grants

This commit is contained in:
Paul Weidner 2023-10-30 14:52:24 -07:00 committed by Michael Stenta
parent d0e305d0c1
commit 4226394e74
2 changed files with 18 additions and 1 deletions

View File

@ -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,

View File

@ -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();
}
}