2016-11-10 49 views
0

我打算使用Web推送通知;我不知道我在哪裏可以找到auth鍵:Javascript Web推送:我可以在哪裏獲得「身份驗證」密鑰?

var pushSubscription = { 
    endpoint: '< Push Subscription URL >', 
    keys: { 
    p256dh: '< User Public Encryption Key >', 
    auth: '< ???? User Auth Secret ???? >' 
    } 
}; 

我可以從ServiceWorker>registeration.pushManager.getSubscription()endpointp256dh但不auth關鍵。

感謝

回答

0

可以使用getKey方法同時獲得p256dhauth(見the specsthe example from the specs)。

getSubscription承諾返回的PushSubscription對象調用JSON.stringify更加簡單。

+0

如果你想在JS中使用該對象(獲得鍵),請不要使用ab2string convertions或pushSubscription.keyKeys()...(Spoiler:不起作用。)只需執行以下操作: 'var subJSObject = JSON.parse(JSON.stringify(pushSubscription)); var endpoint = subJSObject.endpoint; var auth = subJSObject.keys.auth; var p256dh = subJSObject.keys.p256dh;' – mondjunge

相關問題