SIP.js icon indicating copy to clipboard operation
SIP.js copied to clipboard

Bearer Authentication

Open Bill-Niz opened this issue 2 years ago • 4 comments

Hello, I'm trying to implement Bearer Authentication. But i can't override Authentication factory. What's the preferred way to implement Bearer Authentication? Thanks.

Bill-Niz avatar Aug 23 '23 08:08 Bill-Niz

You can provide the header with the token in the different SIP message classes' extraHeaders. For example here in the Registerer: https://github.com/onsip/SIP.js/blob/main/docs/api/sip.js.registereroptions.md

new Registerer(this.userAgent, {
  extraHeaders: ['Authorization: Bearer <token>']
});

fpaaske avatar Nov 06 '23 09:11 fpaaske

When the token expires we want to send a new one (refreshed token) in the next REGISTER. Is this possible somehow? How can we manipulate headers in the next REGISTER message?

jagrodal avatar Nov 13 '23 12:11 jagrodal

@jagrodal You can re-register again using the new bearer registerer.register({ requestOptions: { extraHeaders: "Authorization: Bearer ey......", }, })

Bill-Niz avatar Nov 13 '23 13:11 Bill-Niz

@jagrodal You can re-register again using the new bearer registerer.register({ requestOptions: { extraHeaders: "Authorization: Bearer ey......", }, })

Will probably work, but I prefer using the built-in re-register mechanism. I ended up extending the Transport implementation and overriding the send() method (inserting the auth header here). Seems to be working. Thanks anyway!

jagrodal avatar Nov 14 '23 09:11 jagrodal