Skip to content

Commit 812cd1c

Browse files
author
Pascal Benoit
committed
new correction for new auth
1 parent 2c0109c commit 812cd1c

File tree

7 files changed

+10
-10
lines changed

7 files changed

+10
-10
lines changed
File renamed without changes.

sip-to-webrtc/softphone/inboundcall.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ func (softphone *Softphone) CloseToInvite() {
4545

4646
// OnOK adds a handler that responds to any incoming ok events.
4747
func (softphone *Softphone) OnOK(hdlr func(string)) {
48+
4849
softphone.addMessageListener(func(message string) {
4950
if strings.HasPrefix(message, "SIP/2.0 200 OK") {
5051
parsed := SIPMessage{}.FromString(message)

sip-to-webrtc/softphone/invite.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ func (softphone *Softphone) Invite(extension, offer string) {
2424
softphone.request(sipMessage, func(message string) bool {
2525
authenticateHeader := SIPMessage{}.FromString(message).headers["Proxy-Authenticate"]
2626
ai := GetAuthInfo(authenticateHeader)
27-
ai.Uri = "sip:" + softphone.sipInfo.Domain
27+
ai.AuthType = "Proxy-Authorization"
28+
ai.Uri = "sip:"+ extension + "@"+ softphone.sipInfo.Domain
2829
ai.Method = "INVITE"
29-
3030
sipMessage.addAuthorization(*softphone, ai).addCseq(softphone).newViaBranch()
3131
softphone.request(sipMessage, func(msg string) bool {
3232
return false

sip-to-webrtc/softphone/register.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ func (softphone *Softphone) register() {
3333
}
3434

3535
message := string(bytes)
36-
// log.Print("↓↓↓\n", message)
36+
//log.Print("↓↓↓\n", message)
3737

3838
for _, ml := range softphone.messageListeners {
3939
go ml(message)
@@ -58,6 +58,7 @@ func (softphone *Softphone) register() {
5858
softphone.request(sipMessage, func(message string) bool {
5959
authenticateHeader := SIPMessage{}.FromString(message).headers["WWW-Authenticate"]
6060
ai := GetAuthInfo(authenticateHeader)
61+
ai.AuthType = "Authorization"
6162
ai.Uri = "sip:" + softphone.sipInfo.Domain
6263
ai.Method = "REGISTER"
6364
sipMessage.addAuthorization(*softphone,ai).addCseq(softphone).newViaBranch()

sip-to-webrtc/softphone/sipmessage.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,10 @@ type SIPMessage struct {
1616
}
1717

1818
func (sm *SIPMessage) addAuthorization(softphone Softphone, ai AuthInfo) *SIPMessage {
19-
sm.headers["Authorization"] = generateAuthorization(softphone.sipInfo, ai)
20-
19+
sm.headers[ai.AuthType] = generateAuthorization(softphone.sipInfo, ai)
2120
return sm
2221
}
2322

24-
2523
func (sm *SIPMessage) newViaBranch() {
2624
if val, ok := sm.headers["Via"]; ok {
2725
sm.headers["Via"] = regexp.MustCompile(";branch=z9hG4bK.+?$").ReplaceAllString(val, ";branch="+branch())

sip-to-webrtc/softphone/softphone.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
package softphone
33

44
import (
5-
"fmt"
65
"log"
76
"math/rand"
87
"strings"
@@ -56,7 +55,7 @@ func (softphone *Softphone) removeMessageListener(key string) {
5655
}
5756

5857
func (softphone Softphone) request2(sipMessage SIPMessage, expectedResp string) string {
59-
fmt.Println(sipMessage.ToString())
58+
6059

6160
if err := softphone.wsConn.WriteMessage(1, []byte(sipMessage.ToString())); err != nil {
6261
log.Panic(err)
@@ -92,7 +91,7 @@ func (softphone *Softphone) request(sipMessage SIPMessage, responseHandler func(
9291
}
9392

9493
func (softphone *Softphone) response(message string) {
95-
log.Print("↑↑↑\n", message)
94+
// log.Print("↑↑↑\n", message)
9695

9796
if err := softphone.wsConn.WriteMessage(1, []byte(message)); err != nil {
9897
log.Fatal(err)

sip-to-webrtc/softphone/utils.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ type SIPInfoResponse struct {
2121
}
2222

2323
type AuthInfo struct {
24+
AuthType string `json:"auth_type"`
2425
Realm string `json:"realm"`
2526
Nonce string `json:"nonce"`
2627
Uri string `json:"uri"`
@@ -111,4 +112,4 @@ func RandomString() string { // GENERATE A RANDOM CNONCE
111112

112113
func branch() string {
113114
return "z9hG4bK" + uuid.New().String()
114-
}
115+
}

0 commit comments

Comments
 (0)