A Go sdk utility for creating JWT token with JWS signature as per IETF RFC 7515 specifications. It mimics token generation implementation by streem sdk for nodejs project and generates token with Compact Serialization technique.
Use Init()
method to initialize the Streem SDK. Init
sets the package's config. This is required before creating a TokenBuilder
func Init(apiKeyId, apiKeySecret, apiEnvironment string) (error)
- apiKeyId
- apiKeySecret
- apiEnvironment
Key Id, Secret and Environment corresponds to Streem account for which token builder need to be configured.
To create a Streem Token, first create a TokenBuilder
builder := streem.NewTokenBuilder()
Then specify the details for the currently logged-in user:
// required
builder.SetUserId("someId")
// recommended
builder.SetName("T Rex")
builder.SetEmail("some@email.com")
builder.SetAvatarUrl("some.avatar.url")
// optional
addDurationToNow := builder.AddTime()
builder.SetTokenExpirationMs(addDurationToNow(time.Minute * 30))
builder.SetSessionExpirationMs(addDurationToNow(time.Hour * 12))
// If using the Group Reservation feature, set the reservation sid from the API response
builder.SetReservationSid("rsv_abc123")
Finally, call build()
to generate the token string:
token, err := builder.Build()
if err != nil {
fmt.Println("err: ", err)
return
}
fmt.Printf("Got token %s\n", token)
err := streem.Init(apiKeyId, apiKeySecret, apiEnvironment)
if err != nil {
fmt.Println("err: ", err)
os.Exit(1)
}
builder := streem.NewTokenBuilder()
// required
builder.SetUserId("someId")
// recommended
builder.SetName("T Rex")
builder.SetEmail("some@email.com")
builder.SetAvatarUrl("some.avatar.url")
// optional
addDurationToNow := builder.AddTime()
builder.SetTokenExpirationMs(addDurationToNow(time.Minute * 30))
builder.SetSessionExpirationMs(addDurationToNow(time.Hour * 12))
token, err := builder.Build()
if err != nil {
fmt.Println("err: ", err)
return
}
fmt.Printf("Got token %s\n", token)