Skip to content

Instantly share code, notes, and snippets.

@Javiseeker
Last active August 31, 2021 21:02
Show Gist options
  • Select an option

  • Save Javiseeker/c84368ccd832ae8a8297cee26fa1bd9e to your computer and use it in GitHub Desktop.

Select an option

Save Javiseeker/c84368ccd832ae8a8297cee26fa1bd9e to your computer and use it in GitHub Desktop.
go script to fetch Twilio credentials for STUN and TURN servers. By default the credentials last for 1 day before requesting again.
module github.com/twilio-test/trying
go 1.16
require github.com/twilio/twilio-go v0.10.0
package main
import (
"encoding/json"
"fmt"
twilio "github.com/twilio/twilio-go"
openapi "github.com/twilio/twilio-go/rest/api/v2010"
)
func main() {
//this go func will generate STUN/TURN TWILIO server credentials. REQUIRES ACCOUNT SID AND AUTH TOKEN.
accountSid := "twilio acc sid"
authToken := "twilio auth tok" //os.Getenv("TWILIOACCAUTHTOKEN")
client := twilio.NewRestClient(accountSid, authToken)
params := &openapi.CreateTokenParams{}
params.SetTtl(86400)
token, err := client.ApiV2010.CreateToken(params)
if err != nil {
fmt.Println(err.Error())
err = nil
} else {
tokenResponse, _ := json.Marshal(*token.IceServers)
fmt.Println("\n TURN/STUN Servers \n")
fmt.Println("Response: " + string(tokenResponse))
fmt.Println("\n Username \n")
fmt.Println(*token.Username)
fmt.Println("\n Password \n")
fmt.Print(string(*token.Password))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment