Skip to content

Commit 9305058

Browse files
committed
don't force using GCM API key for FCM
1 parent 3241a18 commit 9305058

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/WebPush.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -213,16 +213,18 @@ private function prepareAndSend(array $notifications)
213213
}
214214

215215
// if GCM or FCM url
216-
if (substr($endpoint, 0, Utils::safe_strlen(self::GCM_URL)) === self::GCM_URL
217-
|| substr($endpoint, 0, Utils::safe_strlen(self::FCM_URL)) === self::FCM_URL) {
216+
$isGCM = substr($endpoint, 0, strlen(self::GCM_URL)) === self::GCM_URL;
217+
if ($isGCM || substr($endpoint, 0, strlen(self::FCM_URL)) === self::FCM_URL) {
218218
if (array_key_exists('GCM', $this->auth)) {
219219
$headers['Authorization'] = 'key='.$this->auth['GCM'];
220-
} else {
220+
} elseif ($isGCM) {
221+
// FCM doesn't need an API key, it's optional if you're using VAPID
221222
throw new \ErrorException('No GCM/FCM API Key specified.');
222223
}
223224
}
224-
// if VAPID
225-
elseif (array_key_exists('VAPID', $this->auth)) {
225+
226+
// if VAPID (GCM doesn't support it but FCM does)
227+
if (array_key_exists('VAPID', $this->auth) && !$isGCM) {
226228
$vapid = $this->auth['VAPID'];
227229

228230
$audience = parse_url($endpoint, PHP_URL_SCHEME).'//'.parse_url($endpoint, PHP_URL_HOST);

0 commit comments

Comments
 (0)