forked from TwilioDevEd/video-access-token-server-ruby
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.rb
executable file
·31 lines (25 loc) · 824 Bytes
/
app.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
require 'twilio-ruby'
require 'sinatra'
require 'sinatra/json'
require 'dotenv'
require 'faker'
# Load environment configuration
Dotenv.load
# Render home page
get '/' do
File.read(File.join('public', 'index.html'))
end
# Generate a token for use in our Video application
get '/token' do
# Create a random username for the client
identity = Faker::Internet.user_name
# Create an Access Token for Video usage
token = Twilio::Util::AccessToken.new ENV['TWILIO_ACCOUNT_SID'],
ENV['TWILIO_API_KEY'], ENV['TWILIO_API_SECRET'], 3600, identity
# Grant access to Video
grant = Twilio::Util::AccessToken::VideoGrant.new
grant.configuration_profile_sid = ENV['TWILIO_CONFIGURATION_SID']
token.add_grant grant
# Generate the token and send to client
json :identity => identity, :token => token.to_jwt
end