token

package
v0.0.0-...-8faff26 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 1, 2020 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Create them on your server and pass them to a client to help verify a client's identity, and to grant access to features in client API's.

For more information, please see the Twilio docs: https://www.twilio.com/docs/api/rest/access-tokens

Example
package main

import (
	"fmt"
	"time"

	"github.com/kevinburke/twilio-go/token"
)

func main() {
	t := token.New("AC123", "456bef", "secretkey", "test@example.com", time.Hour)
	grant := token.NewConversationsGrant("a-conversation-sid")
	t.AddGrant(grant)
	jwt, _ := t.JWT()
	fmt.Println(jwt) // A string encoded with the given values.
}
Output:

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AccessToken

type AccessToken struct {
	NotBefore time.Time
	// contains filtered or unexported fields
}

AccessToken holds properties that can generate a signature to talk to the Messaging/Voice/Video API's.

func New

func New(accountSid, apiKey, apiSecret, identity string, ttl time.Duration) *AccessToken

New generates a new AccessToken with the specified properties. identity is a unique ID for a particular user.

To generate an apiKey and apiSecret follow this instructions: https://www.twilio.com/docs/api/rest/access-tokens#jwt-format

func (*AccessToken) AddGrant

func (t *AccessToken) AddGrant(grant Grant)

func (*AccessToken) JWT

func (t *AccessToken) JWT() (string, error)

type ChatGrant

type ChatGrant struct {
	// contains filtered or unexported fields
}

ChatGrant is for Twilio Programmable Chat

func NewChatGrant

func NewChatGrant(sid string) *ChatGrant

func (*ChatGrant) Key

func (cg *ChatGrant) Key() string

func (*ChatGrant) ToPayload

func (cg *ChatGrant) ToPayload() map[string]interface{}

type ConversationsGrant

type ConversationsGrant struct {
	// contains filtered or unexported fields
}

ConversationsGrant is for Twilio Conversations

func NewConversationsGrant

func NewConversationsGrant(sid string) *ConversationsGrant

func (*ConversationsGrant) Key

func (gr *ConversationsGrant) Key() string

func (*ConversationsGrant) ToPayload

func (gr *ConversationsGrant) ToPayload() map[string]interface{}

type Grant

type Grant interface {
	ToPayload() map[string]interface{}
	Key() string
}

Grant is a Twilio SID resource that can be added to an AccessToken for extra services. Implement this interface to create a custom Grant.

type IPMessageGrant

type IPMessageGrant struct {
	// contains filtered or unexported fields
}

IPMessageGrant is a grant for accessing Twilio IP Messaging

func NewIPMessageGrant

func NewIPMessageGrant(serviceSid, endpointID, deploymentRoleSid, pushCredentialSid string) *IPMessageGrant

func (*IPMessageGrant) Key

func (gr *IPMessageGrant) Key() string

func (*IPMessageGrant) ToPayload

func (gr *IPMessageGrant) ToPayload() map[string]interface{}

type VideoGrant

type VideoGrant struct {
	// contains filtered or unexported fields
}

VideoGrant is for Twilio Programmable Video access

func NewVideoGrant

func NewVideoGrant(sid string) *VideoGrant

func (*VideoGrant) Key

func (gr *VideoGrant) Key() string

func (*VideoGrant) ToPayload

func (gr *VideoGrant) ToPayload() map[string]interface{}

type VoiceGrant

type VoiceGrant struct {
	// contains filtered or unexported fields
}

VoiceGrant is a grant for accessing Twilio IP Messaging

func NewVoiceGrant

func NewVoiceGrant(outAppSid string, outAppParams map[string]interface{}, endpointID string, pushCredentialSid string) *VoiceGrant

func (*VoiceGrant) Key

func (gr *VoiceGrant) Key() string

func (*VoiceGrant) ToPayload

func (gr *VoiceGrant) ToPayload() map[string]interface{}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL