ParseUsername utility for TURN user name. (#3547)

* ParseUsername utility for TURN user name.

NOTE: There is no state, so no need for struct method, but just doing it
similar to CreateUsername which also does not have state, but uses
struct method.

* missed base62 decode
This commit is contained in:
Raja Subramanian
2025-03-22 13:16:13 +05:30
committed by GitHub
parent 55909ed7c4
commit 26822b6b49
+13
View File
@@ -164,6 +164,19 @@ func (h *TURNAuthHandler) CreateUsername(apiKey string, pID livekit.ParticipantI
return base62.EncodeToString([]byte(fmt.Sprintf("%s|%s", apiKey, pID)))
}
func (h *TURNAuthHandler) ParseUsername(username string) (apiKey string, pID livekit.ParticipantID, err error) {
decoded, err := base62.DecodeString(username)
if err != nil {
return "", "", err
}
parts := strings.Split(string(decoded), "|")
if len(parts) != 2 {
return "", "", errors.New("invalid username")
}
return parts[0], livekit.ParticipantID(parts[1]), nil
}
func (h *TURNAuthHandler) CreatePassword(apiKey string, pID livekit.ParticipantID) (string, error) {
secret := h.keyProvider.GetSecret(apiKey)
if secret == "" {