onsip / SIP.js

A simple, intuitive, and powerful JavaScript signaling library
https://sipjs.com
MIT License
1.88k stars 700 forks source link

Bearer Authentication #1051

Open Bill-Niz opened 1 year ago

Bill-Niz commented 1 year ago

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.

fpaaske commented 11 months ago

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>']
});
jagrodal commented 10 months ago

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?

Bill-Niz commented 10 months ago

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

jagrodal commented 10 months ago

@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!