Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

JWT Tokens

Kevin Sylvestre edited this pageAug 29, 2019 ·9 revisions

Client Capability Tokens

Twilio Client Capability Tokens are required for setting up a device tosend and receive calls viaTwilio Client.

Setup Work

require'twilio-ruby'# put your own account credentials here:account_sid='ACxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'auth_token='yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy'# set upcapability=Twilio::JWT::ClientCapability.newaccount_sid,auth_token

Allow Incoming Calls

# Allow incoming calls, and give the client a name.incoming_scope=Twilio::JWT::ClientCapability::IncomingClientScope.new'john'capability.add_scope(incoming_scope)# Generate the token string@token=capability.to_s

Allow Outgoing Calls

# Allow outgoing calls to an application.outgoing_scope=Twilio::JWT::ClientCapability::OutgoingClientScope.new'AP11111111111111111111111111111111','john'capability.add_scope(outgoing_scope)# Generate the token string@token=capability.to_s

Allow Outgoing Calls With Parameters

You can send parameters to your Application'sVoiceUrl by passing a hash in the initialization. Here we pass along a hypothetical user id.

params={'user_id'=>@user.id}# Allow outgoing calls to an application and pass the user id to your server.outgoingScope=Twilio::JWT::ClientCapability::OutgoingClientScope.new'AP11111111111111111111111111111111','john',paramscapability.add_scope(outgoingScope)# Generate the token string@token=capability.to_s

Theuser_id parameter and its value will be sent to your Application'sVoiceUrl along with the other parameters that Twilio usually sends, likeFrom,To andCallSid.

Allow Multiple Capabilities

You can generate a Capability Token that supports multiple capabilities, so thatyour Twilio Client device can make and receive calls.

client_name='john'# Allow incoming calls, and give the client a name.incomingScope=Twilio::JWT::ClientCapability::IncomingClientScope.newclient_namecapability.add_scope(incomingScope)# Allow outgoing calls to an application and pass the user id to your server.params={'user_id'=>@user.id}outgoingScope=Twilio::JWT::ClientCapability::OutgoingClientScope.new'AP11111111111111111111111111111111',client_name,paramscapability.add_scope(outgoingScope)# Generate the token string@token=capability.to_s

Change the TTL of the Token

By default all tokens generated with the Twilio helper libraries expire after one hour (3600s). But you should configure this expiration to be as short as possible for your application.

# Generate the token string with 5 seconds of expirationtoken=Twilio::JWT::ClientCapability.new(@account_sid,@auth_token,ttl:5)

Access Tokens

require'twilio-ruby'# Required for any Twilio Access Tokenaccount_sid='ACxxxxxxxxxxxx'api_key='SKxxxxxxxxxxxx'api_secret='xxxxxxxxxxxxxx'# Required for Videoidentity='user'# Create Video grant for our tokenvideo_grant=Twilio::JWT::AccessToken::VideoGrant.newvideo_grant.room='cool room'# Create an Access Tokentoken=Twilio::JWT::AccessToken.new(account_sid,api_key,api_secret,[video_grant],identity:identity)# Generate the tokenputstoken.to_jwt
Clone this wiki locally

[8]ページ先頭

©2009-2025 Movatter.jp