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:
@@ -164,6 +164,19 @@ func (h *TURNAuthHandler) CreateUsername(apiKey string, pID livekit.ParticipantI
|
|||||||
return base62.EncodeToString([]byte(fmt.Sprintf("%s|%s", apiKey, pID)))
|
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) {
|
func (h *TURNAuthHandler) CreatePassword(apiKey string, pID livekit.ParticipantID) (string, error) {
|
||||||
secret := h.keyProvider.GetSecret(apiKey)
|
secret := h.keyProvider.GetSecret(apiKey)
|
||||||
if secret == "" {
|
if secret == "" {
|
||||||
|
|||||||
Reference in New Issue
Block a user