-
Notifications
You must be signed in to change notification settings - Fork 301
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
Microsoft Edge Always Returns 401 Not Authorised Invalid Token #233
Comments
same issue > Chrome, Firefox and Opera works but not Microsoft Edge 44.18362.449.0 / Microsoft EdgeHTML 18.18362 I got the following response:
How to fix the issue |
Same issue .... Works fine on Mozilla, Chrome. |
Hello? anything? |
My Microsoft Edge on Windows 10 2004 works fine, but not on 1607 (LTSB). Receive 401 all the time. At the same time Microsoft's test page ( https://webpushdemo.azurewebsites.net/ ) works fine on both versions of Windows. |
Also a 401 all the time, the webpushdemo works. Edge version: 44.19041.1.0 |
see bug #278 |
i can confirm, replacing "+" to "%2b" works |
God bless you mokraemer. Replacing '+' with '%2b' works!!! |
Hi together, I still don't understand:
The token looks already url-encoded. But if I reuse it exactly as it is, I run into 401 error |
Make sure to base64 encode the string and decode it just before sending! |
This comment was marked as resolved.
This comment was marked as resolved.
Damn, one problem solved: the endpoint length is more than 255 chars... Ok... now the encoding problem ... I am still investigating 😆 Finally the message was created ... token length in database was the problem. Now I have to find out, why message does not appear in Edge => Windows 11 Notfiy Settings 🤣 |
Hello @mokraemer, I am having the same issue on Edge. and after decoding it, became like this: https://wns2-bl2p.notify.windows.com/w/?token=BQYAAAAAgYrxLzjPS7Xx2t9XoqmGVxPKRhhhwinm6Fe8Bkg/cpadDTvEh8X9HC3FxsIW2KLCllCY8DlvFLuv45+4MZyRZ9IBbmE/slIuv3oP/ELOQ/6j7rexCTjXLfsGOsjZG8rpyngxm4ZUuFwF+hxBbm9P1/j5vTxp+8H2dI1StYQLODdqI+wVIb86hPO But I'm still getting Received unexpected response code: 401. Am I doing something wrong here? |
Shortly before end of work, I quickly looked at our code: And this works fine with this code and without any encoding/decoding on our side /**
* @param list<Subscription> $subscriptions
*/
private function sendNotifications(array $subscriptions): void
{
$auth = [
'VAPID' => [
'subject' => 'YOUR SUBJECT',
'publicKey' => WEBPUSH_VAPID_PUBLIC_KEY,
'privateKey' => WEBPUSH_VAPID_PRIVATE_KEY,
],
];
$webPush = new \Minishlink\WebPush\WebPush($auth);
foreach ($this->createNotfications($subscriptions) as $notification) {
$webPush->queueNotification(
$notification['subscription'],
$notification['payload'],
);
}
foreach ($webPush->flush() as $report) {
$endpoint = $report->getRequest()->getUri()->__toString();
if (!$report->isSuccess()) {
(new SubscriptionRepository())->deleteSubscription($endpoint);
}
}
}
/**
* @param list<Subscription> $storedSubscriptions
*
* @return list<array{subscription: \Minishlink\WebPush\Subscription, payload: string}>
*/
private function createNotfications(array $storedSubscriptions): array
{
$notifications = [];
foreach ($storedSubscriptions as $storedSubscription) {
$notifications[] = [
'subscription' => \Minishlink\WebPush\Subscription::create([
'endpoint' => $storedSubscription->endpoint,
'publicKey' => $storedSubscription->publicKey,
'authToken' => $storedSubscription->authToken,
'contentEncoding' => $storedSubscription->contentEncoding,
]),
'payload' => $this->getPayload(),
];
}
return $notifications;
} At first I thought I was having encoding problems as well. |
@trailsnail You're actually right, it was the column length on the DB that was too short 😅 . |
I had the exact same issue and realized thanks to this discussion that my DB field was too short as well 😅 |
NOTE: Please test in a least two browsers (i.e. Chrome and Firefox). This
helps with diagnosing problems quicker.
Setup
Problem
When pushing to subscription endpoint in Edge, a 401 error is always returned with the WWW-Authenticate header containing 'bearer error="invalid_request",error_description="Invalid token".
I think this may be because Microsoft Push Notification Service requires a (Bearer) Access Token to be passed in the Authorisation header as explained in https://docs.microsoft.com/en-us/previous-versions/windows/apps/hh868206(v%3dwin.10).
Does this library have a facility to pass the bearer token to Microsoft Endpoints? If so, please could the README be updated to provide example of how to make a push to Microsoft Push Service.
If not is it possible to extend the library to allow custom HTTP headers to be inserted into the post to the notification endpoints?
Expected
Push notification to be sent to device.
Features Used
Example / Reproduce Case
Other
The text was updated successfully, but these errors were encountered: