This repository was archived by the owner on Aug 30, 2024. It is now read-only.
File tree 2 files changed +28
-3
lines changed
2 files changed +28
-3
lines changed Original file line number Diff line number Diff line change @@ -104,14 +104,18 @@ type tunnneler struct {
104
104
}
105
105
106
106
func (c * tunnneler ) start (ctx context.Context ) error {
107
+ username , password , err := wsnet .TURNCredentials (c .token )
108
+ if err != nil {
109
+ return xerrors .Errorf ("failed to parse credentials from token" )
110
+ }
107
111
server := webrtc.ICEServer {
108
112
URLs : []string {wsnet .TURNEndpoint (c .brokerAddr )},
109
- Username : "insecure" ,
110
- Credential : "pass" ,
113
+ Username : username ,
114
+ Credential : password ,
111
115
CredentialType : webrtc .ICECredentialTypePassword ,
112
116
}
113
117
114
- err : = wsnet .DialICE (server , nil )
118
+ err = wsnet .DialICE (server , nil )
115
119
if errors .Is (err , wsnet .ErrInvalidCredentials ) {
116
120
return xerrors .Errorf ("failed to authenticate your user for this workspace" )
117
121
}
Original file line number Diff line number Diff line change
1
+ package wsnet
2
+
3
+ import (
4
+ "crypto/sha256"
5
+ "errors"
6
+ "strings"
7
+ )
8
+
9
+ // TURNCredentials returns a username and password pair
10
+ // for a Coder token.
11
+ func TURNCredentials (token string ) (username , password string , err error ) {
12
+ str := strings .SplitN (token , "-" , 2 )
13
+ if len (str ) != 2 {
14
+ err = errors .New ("invalid token format" )
15
+ return
16
+ }
17
+ username = str [0 ]
18
+ hash := sha256 .Sum256 ([]byte (str [1 ]))
19
+ password = string (hash [:])
20
+ return
21
+ }
You can’t perform that action at this time.
0 commit comments