A Golang library for twilio server side SDK.
Install the package with go:
go get github.com/xaviiic/twilioGo
Import the package to your go file:
import (
twilio "github.com/xaviiic/twilioGo"
)
Access Tokens are short-lived tokens that you can use to authenticate Twilio Client SDKs like Video and IP Messaging. You create them on your server to verify a client's identity and grant access to client API features.
To create an access token, pass the Twilio API account information first.
// first create token with twilio api configurations
token := twilio.NewAccessToken(accountID, keyID, secret)
// setup token identity
token.SetIdentity(identity)
Once you have created a token instance, you can add access grant with desired API features.
// grant token access to progammable video API
grant := twilio.NewConversationGrant(configurationProfileID)
token.AddGrant(grant)
// grant token access to video API
grant := twiliogo.NewVideoGrant(room)
token.AddGrant(grant)
Then transform token to JWT format for client side usages.
jwt, err := token.ToJWT()
Capability tokens allow you to add Twilio capabilities to web and mobile applications without exposing your AuthToken in JavaScript or any other client-side environment.
Create a capability token instance first with API account information.
capability := twilio.NewCapability(accountID, authToken)
Then setup the capabilities of token and output a JWT format token.
// allow incoming connections
capability.AllowClientIncoming(clientName)
// allow outgoing connections
capability.AllowClientOutgoing(appID, nil)
jwt, err := capability.ToJWT()
Generating token steps can be chained together.
token, err := twilio.NewAccessToken(accountSid, apiKey, apiSecret).
SetIdentity(identity).
AddGrant(twilio.NewConversationGrant(configurationSid)).
SetTTL(30 * time.Minute).
ToJWT()
Copyright 2016 xaviiic
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
https://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.