Skip to content

Sending a notification results in a 401 Unauthorized response. (authorization header must be specified) #325

Closed
@Tikolu

Description

@Tikolu

Please confirm the following:

  • I have read the README entirely
  • I have verified in the issues that my problem hasn't already been resolved

Setup

Please provide the following details, the more info you can provide the
better.

  • Operating System: Linux
  • PHP Version: 8.0.3
  • web-push-php Version: 6.0.5

Please check that you have installed and enabled these PHP extensions :

  • gmp
  • mbstring
  • curl
  • openssl

Please select any browsers that you are experiencing problems with:

  • Chrome

Please specify the versions (i.e. Chrome Beta, Firefox Beta etc).

  • Chrome 89

Problem

Sending a notification to a FCM endpoint does not work. The endpoint sends back a 401 response with the following message:
authorization header must be specified

Expected

The notification would be sent to the endpoint without any errors.
According to the usage section of the README, this library supports fcm.googleapis.com endpoints for Chrome.

Features Used

  • VAPID Support
  • Sending with Payload

Example / Reproduce Case

use Minishlink\WebPush\WebPush;
use Minishlink\WebPush\Subscription;

$publicKey = "(88 character key)";

$webPush = new WebPush([
    "subject" => "(link to website)",
    "publicKey" => $publicKey,
    "privateKey" => "(44 character key)"
]);

$subscription = Subscription::create([
    "endpoint" => "https://fcm.googleapis.com/fcm/send/...",
    "publicKey" => $publicKey,
    "authToken" => "(24 character key)",
   "contentEncoding" => "aes128gcm"
]);

$response = $webPush -> sendOneNotification($subscription);
print_r($response); // -> Client error: `POST (endpoint)` resulted in a `401 Unauthorized` response: authorization header must be specified.

I would greatly appreciate if someone could help me out with this issue, as I've been struggling with it for a few days now.
Thank you very much.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions