Skip to content

Commit

Permalink
Get Project ID from Service Account (JSON file)
Browse files Browse the repository at this point in the history
  • Loading branch information
yurabakhtin committed Oct 14, 2024
1 parent 4c25069 commit 56b3f92
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Events.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public static function onServiceWorkerControllerInit($event): void
firebase.initializeApp({
messagingSenderId: "{$pushDriver->getSenderId()}",
projectId: "{$module->getConfigureForm()->firebaseProjectId}",
projectId: "{$module->getConfigureForm()->getJsonParam('project_id')}",
apiKey: "{$module->getConfigureForm()->firebaseApiKey}",
appId: "{$module->getConfigureForm()->firebaseAppId}"
});
Expand Down
2 changes: 1 addition & 1 deletion assets/FcmPushAsset.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public static function register($view)
Yii::$app->view->registerJsConfig('firebase', [
'tokenUpdateUrl' => Url::to(['/fcm-push/token/update']),
'senderId' => $pushDriver->getSenderId(),
'projectId' => $module->getConfigureForm()->firebaseProjectId,
'projectId' => $module->getConfigureForm()->getJsonParam('project_id'),
'apiKey' => $module->getConfigureForm()->firebaseApiKey,
'appId' => $module->getConfigureForm()->firebaseAppId,
'vapidKey' => $module->getConfigureForm()->firebaseVapidKey,
Expand Down
2 changes: 1 addition & 1 deletion driver/Fcm.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function isConfigured(): bool
{
return !empty($this->config->json) &&
!empty($this->config->senderId) &&
!empty($this->config->firebaseProjectId) &&
!empty($this->config->getJsonParam('project_id')) &&
!empty($this->config->firebaseApiKey) &&
!empty($this->config->firebaseAppId) &&
!empty($this->config->firebaseVapidKey);
Expand Down
11 changes: 6 additions & 5 deletions models/ConfigureForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ class ConfigureForm extends Model
public $humhubInstallId;

public $senderId;
public $firebaseProjectId;
public $firebaseApiKey;
public $firebaseAppId;
public $firebaseVapidKey;
Expand Down Expand Up @@ -93,7 +92,7 @@ public function rules()
return [
[['enableEmailGoService', 'disableAuthChoicesIos'], 'boolean'],
[['senderId'], 'number'],
[['firebaseProjectId', 'firebaseApiKey', 'firebaseAppId', 'firebaseVapidKey'], 'string'],
[['firebaseApiKey', 'firebaseAppId', 'firebaseVapidKey'], 'string'],
[['serverKey', 'json', 'humhubApiKey'], 'safe'],
[['fileAssetLinks', 'fileAppleAssociation'], 'string'],
['json', function ($attribute, $params, $validator) {
Expand Down Expand Up @@ -149,7 +148,6 @@ public function attributeLabels()
'humhubInstallId' => Yii::t('FcmPushModule.base', 'Install ID'),
'humhubApiKey' => Yii::t('FcmPushModule.base', 'API Key'),
'senderId' => Yii::t('FcmPushModule.base', 'Sender ID'),
'firebaseProjectId' => Yii::t('FcmPushModule.base', 'Project ID'),
'firebaseApiKey' => Yii::t('FcmPushModule.base', 'API Key'),
'firebaseAppId' => Yii::t('FcmPushModule.base', 'Application ID'),
'firebaseVapidKey' => Yii::t('FcmPushModule.base', 'VAPID key (Voluntary Application Server Identification)'),
Expand Down Expand Up @@ -200,7 +198,6 @@ public function loadSettings()
$this->enableEmailGoService = $settings->get('enableEmailGoService', false);
$this->humhubInstallId = $adminModule->settings->get('installationId');
$this->senderId = $settings->get('senderId');
$this->firebaseProjectId = $settings->get('firebaseProjectId');
$this->firebaseApiKey = $settings->get('firebaseApiKey');
$this->firebaseAppId = $settings->get('firebaseAppId');
$this->firebaseVapidKey = $settings->get('firebaseVapidKey');
Expand All @@ -221,7 +218,6 @@ public function saveSettings()

$module->settings->set('enableEmailGoService', $this->enableEmailGoService);
$module->settings->set('senderId', $this->senderId);
$module->settings->set('firebaseProjectId', $this->firebaseProjectId);
$module->settings->set('firebaseApiKey', $this->firebaseApiKey);
$module->settings->set('firebaseAppId', $this->firebaseAppId);
$module->settings->set('firebaseVapidKey', $this->firebaseVapidKey);
Expand All @@ -240,6 +236,11 @@ public function getJsonAsArray()
return Json::decode($this->json);
}

public function getJsonParam(string $param): ?string
{
return $this->getJsonAsArray()[$param] ?? null;
}

public static function getInstance()
{
$config = new static();
Expand Down
1 change: 0 additions & 1 deletion views/admin/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
</p>
<?= Button::info('Installation documentation')->link('https://marketplace.humhub.com/module/fcm-push/installation')->options(['target' => '_blank'])->loader(false) ?>
<?= $form->field($model, 'senderId') ?>
<?= $form->field($model, 'firebaseProjectId') ?>
<?= $form->field($model, 'firebaseApiKey') ?>
<?= $form->field($model, 'firebaseAppId') ?>
<?= $form->field($model, 'firebaseVapidKey') ?>
Expand Down

0 comments on commit 56b3f92

Please sign in to comment.