refactor bearer token on the client side
This commit is contained in:
@@ -72,11 +72,15 @@ func NewWebSocketConn(host, token string) (*websocket.Conn, error) {
|
||||
return nil, err
|
||||
}
|
||||
requestHeader := make(http.Header)
|
||||
requestHeader.Set("Authorization", "Bearer "+token)
|
||||
SetAuthorizationToken(requestHeader, token)
|
||||
conn, _, err := websocket.DefaultDialer.Dial(u.String(), requestHeader)
|
||||
return conn, err
|
||||
}
|
||||
|
||||
func SetAuthorizationToken(header http.Header, token string) {
|
||||
header.Set("Authorization", "Bearer "+token)
|
||||
}
|
||||
|
||||
func NewRTCClient(conn *websocket.Conn) (*RTCClient, error) {
|
||||
// Create a new RTCPeerConnection
|
||||
peerConn, err := webrtc.NewPeerConnection(rtcConf)
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
"github.com/twitchtv/twirp"
|
||||
"github.com/urfave/cli/v2"
|
||||
|
||||
"github.com/livekit/livekit-server/cmd/cli/client"
|
||||
"github.com/livekit/livekit-server/pkg/auth"
|
||||
"github.com/livekit/livekit-server/pkg/logger"
|
||||
"github.com/livekit/livekit-server/proto/livekit"
|
||||
@@ -109,7 +110,7 @@ func contextWithAccessToken(c *cli.Context, grant *auth.VideoGrant) context.Cont
|
||||
}
|
||||
if token != "" {
|
||||
header := make(http.Header)
|
||||
header.Set("Authorization", "Bearer "+token)
|
||||
client.SetAuthorizationToken(header, token)
|
||||
if tctx, err := twirp.WithHTTPRequestHeaders(ctx, header); err == nil {
|
||||
logger.Debugw("requesting with token")
|
||||
ctx = tctx
|
||||
|
||||
+4
-1
@@ -2,7 +2,6 @@ package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"math/rand"
|
||||
@@ -14,6 +13,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/go-redis/redis/v8"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/urfave/cli/v2"
|
||||
|
||||
"github.com/livekit/livekit-server/pkg/auth"
|
||||
@@ -163,11 +163,13 @@ func startServer(c *cli.Context) error {
|
||||
|
||||
func createRouterAndStore(config *config.Config, node routing.LocalNode) (router routing.Router, store service.RoomStore, err error) {
|
||||
if config.MultiNode {
|
||||
logger.Infow("using multi-node routing via redis", "address", config.Redis.Address)
|
||||
rc := redis.NewClient(&redis.Options{
|
||||
Addr: config.Redis.Address,
|
||||
Password: config.Redis.Password,
|
||||
})
|
||||
if err = rc.Ping(context.Background()).Err(); err != nil {
|
||||
err = errors.Wrap(err, "unable to connect to redis")
|
||||
return
|
||||
}
|
||||
|
||||
@@ -175,6 +177,7 @@ func createRouterAndStore(config *config.Config, node routing.LocalNode) (router
|
||||
store = service.NewRedisRoomStore(rc)
|
||||
} else {
|
||||
// local routing and store
|
||||
logger.Infow("using single-node routing")
|
||||
router = routing.NewLocalRouter(node)
|
||||
store = service.NewLocalRoomStore()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user