Files
protocol/sip/token.go
David Zhao e0c49d3c9d Support for key/value attributes on Participant (#733)
* Support for key/value attributes on Participant

Key/value attributes lets us:
* allow various components to provide more information about the participant (i.e. SIP including the phone number)
* allow Agents to communicate their own status to the end user via RTC
* enable applications to update specific fields without overriding others

* generated protobuf

* Attribute support for SIP.

* generated protobuf

* generated protobuf

* allow specifying attributes during token generation

* Remove sip prefix and rename phone number attrs.

* regenerate protos

* update tests

* add kv attrs to sip token

* add attribute test

* changeset

---------

Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Denys Smirnov <dennwc@pm.me>
2024-06-19 22:27:09 -07:00

46 lines
1.2 KiB
Go

// Copyright 2023 LiveKit, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package sip
import (
"time"
"github.com/livekit/protocol/auth"
"github.com/livekit/protocol/livekit"
)
func BuildSIPToken(
apiKey, secret, roomName string,
participantIdentity, participantName, participantMeta string,
participantAttrs map[string]string,
) (string, error) {
t := true
at := auth.NewAccessToken(apiKey, secret).
AddGrant(&auth.VideoGrant{
RoomJoin: true,
Room: roomName,
CanSubscribe: &t,
CanPublish: &t,
}).
SetIdentity(participantIdentity).
SetName(participantName).
SetMetadata(participantMeta).
SetAttributes(participantAttrs).
SetKind(livekit.ParticipantInfo_SIP).
SetValidFor(24 * time.Hour)
return at.ToJWT()
}