cli to support token based auth

This commit is contained in:
David Zhao
2020-12-27 22:02:19 -08:00
parent 46dadc25c2
commit 43a6db8a3a
13 changed files with 170 additions and 39 deletions
+24
View File
@@ -8,6 +8,8 @@ import (
"strings"
"github.com/urfave/cli/v2"
"github.com/livekit/livekit-server/pkg/auth"
)
var (
@@ -24,6 +26,14 @@ var (
Name: "host",
Value: "ws://localhost:7881",
}
apiKeyFlag = &cli.StringFlag{
Name: "api-key",
EnvVars: []string{"LK_API_KEY"},
}
secretFlag = &cli.StringFlag{
Name: "api-secret",
EnvVars: []string{"LK_API_SECRET"},
}
)
func PrintJSON(obj interface{}) {
@@ -39,3 +49,17 @@ func ExpandUser(p string) string {
return p
}
func accessToken(c *cli.Context, grant *auth.VideoGrant, identity string) (value string, err error) {
apiKey := c.String("api-key")
apiSecret := c.String("api-secret")
if apiKey == "" && apiSecret == "" {
// not provided, don't sign request
return
}
at := auth.NewAccessToken(apiKey, apiSecret).
AddGrant(grant).
SetIdentity(identity)
return at.ToJWT()
}