-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add logic to handle uploading an auth JSON file
- Loading branch information
Showing
6 changed files
with
176 additions
and
13 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace tr33m4n\OauthGmail\Exception; | ||
|
||
use Magento\Framework\Exception\LocalizedException; | ||
|
||
class AuthConfigException extends LocalizedException | ||
{ | ||
// | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace tr33m4n\OauthGmail\Model\Config\Backend; | ||
|
||
use Magento\Config\Model\Config\Backend\File; | ||
use Magento\Framework\App\Cache\TypeListInterface; | ||
use Magento\Framework\App\Config\ScopeConfigInterface; | ||
use Magento\Framework\App\Filesystem\DirectoryList; | ||
use Magento\Framework\Data\Collection\AbstractDb; | ||
use Magento\Framework\Filesystem; | ||
use Magento\Framework\Model\Context; | ||
use Magento\Framework\Model\ResourceModel\AbstractResource; | ||
use Magento\Framework\Registry; | ||
use Magento\MediaStorage\Model\File\UploaderFactory; | ||
|
||
class AuthFile extends File | ||
{ | ||
/** | ||
* AuthFile constructor. | ||
* | ||
* @throws \Magento\Framework\Exception\FileSystemException | ||
* @param \Magento\Framework\Model\Context $context | ||
* @param \Magento\Framework\Registry $registry | ||
* @param \Magento\Framework\App\Config\ScopeConfigInterface $config | ||
* @param \Magento\Framework\App\Cache\TypeListInterface $cacheTypeList | ||
* @param \Magento\MediaStorage\Model\File\UploaderFactory $uploaderFactory | ||
* @param \Magento\Config\Model\Config\Backend\File\RequestData\RequestDataInterface $requestData | ||
* @param \Magento\Framework\Filesystem $filesystem | ||
* @param \Magento\Framework\Model\ResourceModel\AbstractResource|null $resource | ||
* @param \Magento\Framework\Data\Collection\AbstractDb|null $resourceCollection | ||
* @param array<string, mixed> $data | ||
*/ | ||
public function __construct( | ||
Context $context, | ||
Registry $registry, | ||
ScopeConfigInterface $config, | ||
TypeListInterface $cacheTypeList, | ||
UploaderFactory $uploaderFactory, | ||
File\RequestData\RequestDataInterface $requestData, | ||
Filesystem $filesystem, AbstractResource $resource = null, | ||
AbstractDb $resourceCollection = null, | ||
array $data = [] | ||
) { | ||
// Ensure we do not save the auth JSON file in a public location | ||
$this->_mediaDirectory = $filesystem->getDirectoryWrite(DirectoryList::VAR_DIR); | ||
|
||
parent::__construct( | ||
$context, | ||
$registry, | ||
$config, | ||
$cacheTypeList, | ||
$uploaderFactory, | ||
$requestData, | ||
$filesystem, | ||
$resource, | ||
$resourceCollection, | ||
$data | ||
); | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
protected function _getAllowedExtensions(): array | ||
{ | ||
return ['json']; | ||
} | ||
} |
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,27 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace tr33m4n\OauthGmail\Model\Config\Source; | ||
|
||
use Magento\Framework\Data\OptionSourceInterface; | ||
|
||
class AuthType implements OptionSourceInterface | ||
{ | ||
public const AUTH_TYPE_FILE = 'file'; | ||
|
||
public const AUTH_TYPE_CLIENT_ID_SECRET = 'client_id_secret'; | ||
|
||
/** | ||
* {@inheritdoc} | ||
* | ||
* @return array[] | ||
*/ | ||
public function toOptionArray(): array | ||
{ | ||
return [ | ||
['label' => __('Client ID/Secret'), 'value' => self::AUTH_TYPE_CLIENT_ID_SECRET], | ||
['label' => __('File'), 'value' => self::AUTH_TYPE_FILE] | ||
]; | ||
} | ||
} |
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