github.com/whoyao/protocol@v0.0.0-20230519045905-2d8ace718ca5/ingress/token.go (about)

     1  package ingress
     2  
     3  import (
     4  	"time"
     5  
     6  	"github.com/whoyao/protocol/auth"
     7  )
     8  
     9  func BuildIngressToken(apiKey, secret, roomName, participantIdentity, participantName string) (string, error) {
    10  	f := false
    11  	t := true
    12  	grant := &auth.VideoGrant{
    13  		RoomJoin:     true,
    14  		Room:         roomName,
    15  		CanSubscribe: &f,
    16  		CanPublish:   &t,
    17  	}
    18  
    19  	at := auth.NewAccessToken(apiKey, secret).
    20  		AddGrant(grant).
    21  		SetIdentity(participantIdentity).
    22  		SetName(participantName).
    23  		SetValidFor(24 * time.Hour)
    24  
    25  	return at.ToJWT()
    26  }