Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
9 tasks done
Tikolu opened this issue Apr 10, 2021 · 1 comment

Comments

@Tikolu
Copy link

Tikolu commented Apr 10, 2021

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.

@Tikolu
Copy link
Author

Tikolu commented Jul 15, 2021

Okay, I managed to find what I was doing wrong. When initialising$webPush, I was entering all security keys directly, instead of placing them all under a "VAPID" key.

I was entering my security keys like this:

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

But I should have entered them like this:

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

@Tikolu Tikolu closed this as completed Jul 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant