Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue #3256745 by paul121: Move default farm OAuth2 client to a separ…
…ate module
- Loading branch information
Showing
5 changed files
with
89 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
modules/core/api/modules/farm_api_default_consumer/farm_api_default_consumer.info.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
name: farmOS Default API Consumer | ||
description: Provides a default consumer for using the farmOS API. | ||
type: module | ||
package: farmOS | ||
core_version_requirement: ^10 | ||
dependencies: | ||
- farm:farm_api | ||
- simple_oauth_password_grant:simple_oauth_password_grant |
55 changes: 55 additions & 0 deletions
55
modules/core/api/modules/farm_api_default_consumer/farm_api_default_consumer.install
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php | ||
|
||
/** | ||
* @file | ||
* Install and uninstall functions for the farm_api_default_consumer module. | ||
*/ | ||
|
||
use Drupal\consumers\Entity\Consumer; | ||
|
||
/** | ||
* Implements hook_install(). | ||
*/ | ||
function farm_api_default_consumer_install() { | ||
|
||
// Check for an existing farm default consumer. | ||
$consumers = \Drupal::entityTypeManager()->getStorage('consumer') | ||
->loadByProperties(['client_id' => 'farm']); | ||
|
||
// If not found, create the farm default consumer. | ||
if (empty($consumers)) { | ||
$base_url = \Drupal::service('router.request_context')->getCompleteBaseUrl(); | ||
$farm_consumer = Consumer::create([ | ||
'label' => 'Farm default', | ||
'client_id' => 'farm', | ||
'access_token_expiration' => 3600, | ||
'grant_types' => [ | ||
'password', | ||
], | ||
'redirect' => $base_url, | ||
'is_default' => TRUE, | ||
'owner_id' => NULL, | ||
'secret' => NULL, | ||
'confidential' => FALSE, | ||
'third_party' => FALSE, | ||
]); | ||
$farm_consumer->save(); | ||
} | ||
|
||
} | ||
|
||
/** | ||
* Implements hook_uninstall(). | ||
*/ | ||
function farm_api_default_consumer_uninstall() { | ||
|
||
// Load the default farm consumer. | ||
$consumers = \Drupal::entityTypeManager()->getStorage('consumer') | ||
->loadByProperties(['client_id' => 'farm']); | ||
|
||
// If found, delete the consumer. | ||
if (!empty($consumers)) { | ||
$farm_consumer = reset($consumers); | ||
$farm_consumer->delete(); | ||
} | ||
} |