This repository was archived by the owner on Aug 15, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 6 files changed +23
-16
lines changed
rest/access-tokens/sync-example Expand file tree Collapse file tree 6 files changed +23
-16
lines changed Original file line number Diff line number Diff line change @@ -6,14 +6,14 @@ const SyncGrant = AccessToken.SyncGrant;
66const twilioAccountSid = process . env . TWILIO_ACCOUNT_SID ;
77const twilioApiKey = process . env . TWILIO_API_KEY ;
88const twilioApiSecret = process . env . TWILIO_API_SECRET ;
9+ const twilioSyncService = process . env . TWILIO_SYNC_SERVICE_SID ;
910
1011// Used specifically for creating Sync tokens
1112const identity = 'user' ;
1213
1314// Create a "grant" which enables a client to use Sync as a given user
1415const syncGrant = new SyncGrant ( {
15- outgoingApplicationSid : outgoingApplicationSid ,
16- incomingAllow : true , // Optional: add to allow incoming calls
16+ serviceSid : twilioSyncService ,
1717} ) ;
1818
1919// Create an access token which we will sign and return to the client,
Original file line number Diff line number Diff line change @@ -11,16 +11,16 @@ static void Main(string[] args)
1111 const string twilioAccountSid = Environment . GetEnvironmentVariable ( "TWILIO_ACCOUNT_SID" ) ;
1212 const string twilioApiKey = Environment . GetEnvironmentVariable ( "TWILIO_API_KEY" ) ;
1313 const string twilioApiSecret = Environment . GetEnvironmentVariable ( "TWILIO_API_SECRET" ) ;
14+ const string twilioSyncService = Environment . GetEnvironmentVariable ( "TWILIO_SYNC_SERVICE_SID" ) ;
1415
1516 // These are specific to Sync
1617 const string identity = "user" ;
1718
1819 // Create a Sync grant for this token
1920 var grant = new SyncGrant ( ) ;
20- grant . OutgoingApplicationSid = outgoingApplicationSid ;
2121
22- // Optional: add to allow incoming calls
23- grant . IncomingAllow = true ;
22+ // Create a "grant" which enables a client to use Sync as a given user
23+ grant . serviceSid = twilioSyncService ;
2424
2525 var grants = new HashSet < IGrant >
2626 {
Original file line number Diff line number Diff line change 99$ twilioAccountSid = getenv ('TWILIO_ACCOUNT_SID ' );
1010$ twilioApiKey = getenv ('TWILIO_API_KEY ' );
1111$ twilioApiSecret = getenv ('TWILIO_API_KEY_SECRET ' );
12+ $ twilioSyncService = getenv ("TWILIO_SYNC_SERVICE_SID " );
13+
1214
1315// Required for Sync grant
1416// An identifier for your app - can be anything you'd like
2527
2628// Create Sync grant
2729$ syncGrant = new SyncGrant ();
28- $ syncGrant ->setOutgoingApplicationSid ($ outgoingApplicationSid );
2930
30- // Optional: add to allow incoming calls
31- $ syncGrant ->setIncomingAllow (true );
31+ // Create a "grant" which enables a client to use Sync as a given user
32+ $ syncGrant ->setServiceSid ($ twilioSyncService );
33+
3234
3335// Add grant to token
3436$ token ->addGrant ($ syncGrant );
Original file line number Diff line number Diff line change 55account_sid = ENV [ 'TWILIO_ACCOUNT_SID' ]
66api_key = ENV [ 'TWILIO_API_KEY' ]
77api_secret = ENV [ 'TWILIO_API_KEY_SECRET' ]
8+ twilioSyncService = ENV [ 'TWILIO_SYNC_SERVICE_SID' ]
9+
810
911# Required for Sync
1012outgoing_application_sid = 'APxxxxxxxxxxxx'
1315# Create Sync grant for our token
1416grant = Twilio ::JWT ::AccessToken ::SyncGrant . new
1517
16- # Optional: add to allow incoming calls
17- grant . incoming_allow = true
18+ # Create a "grant" which enables a client to use Sync as a given user
19+ grant . serviceSid = twilioSyncService
1820
1921# Create an Access Token
2022token = Twilio ::JWT ::AccessToken . new (
Original file line number Diff line number Diff line change 77account_sid = os .environ ['TWILIO_ACCOUNT_SID' ]
88api_key = os .environ ['TWILIO_API_KEY' ]
99api_secret = os .environ ['TWILIO_API_KEY_SECRET' ]
10+ twilioSyncService = os .environ [process .env . ['TWILIO_SYNC_SERVICE_SID' ]
1011
1112# required for Sync grant
1213identity = 'user'
1617
1718# Create a Sync grant and add to token
1819sync_grant = SyncGrant (
19- outgoing_application_sid = outgoing_application_sid ,
20- incoming_allow = True , # Optional: add to allow incoming calls
20+ # Create a "grant" which enables a client to use Sync as a given user
21+ serviceSid = twilioSyncService
2122)
23+
2224token .add_grant (sync_grant )
2325
2426# Return token info as JSON
Original file line number Diff line number Diff line change @@ -10,17 +10,18 @@ public static void main(String[] args) {
1010 String twilioAccountSid = System .getenv ("TWILIO_ACCOUNT_SID" );
1111 String twilioApiKey = System .getenv ("TWILIO_API_KEY" );
1212 String twilioApiSecret = System .getenv ("TWILIO_API_SECRET" );
13+ String twilioSyncService = System .getenv ("TWILIO_SYNC_SERVICE_SID" );
14+
1315
1416 // Required for Sync
1517 String identity = "user" ;
1618
1719 // Create Sync grant
1820 SyncGrant grant = new SyncGrant ();
19- grant .setOutgoingApplicationSid (outgoingApplicationSid );
2021
21- // Optional: add to allow incoming calls
22- grant .setIncomingAllow ( true );
23-
22+ // Create a "grant" which enables a client to use Sync as a given user
23+ grant .setServiceSid ( twilioSyncService );
24+
2425 // Create access token
2526 AccessToken token = new AccessToken .Builder (
2627 twilioAccountSid ,
You can’t perform that action at this time.
0 commit comments