Skip to content

Documentation, Examples, Issue Tracking for the Streem SDK Go Module

Notifications You must be signed in to change notification settings

streem/streem-sdk-go

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Streem SDK

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.

Usage

Init

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)

Params required

  1. apiKeyId
  2. apiKeySecret
  3. apiEnvironment

Key Id, Secret and Environment corresponds to Streem account for which token builder need to be configured.

NewTokenBuilder

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)

Example

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)

About

Documentation, Examples, Issue Tracking for the Streem SDK Go Module

Resources

Stars

Watchers

Forks

Packages

No packages published