Skip to content

Instantly share code, notes, and snippets.

@benoitongit
Created April 22, 2017 18:21
Show Gist options
  • Save benoitongit/1d252a21cc17bb781795655d2bd085d9 to your computer and use it in GitHub Desktop.
Save benoitongit/1d252a21cc17bb781795655d2bd085d9 to your computer and use it in GitHub Desktop.
Generate Twilio access token for video usage in ruby
module App
class Twilio
ACCOUNT_SID = 'XXXXXXXXXXXXXXXXX'.freeze
API_KEY_SID = 'XXXXXXXXXXXXXXXXX'.freeze
API_SECRET = 'XXXXXXXXXXXXXXXXX'.freeze
VIDEO_SID = 'XXXXXXXXXXXXXXXXX'.freeze
def generate_token(user_id)
# Create an Access Token for Video usage
token = ::Twilio::Util::AccessToken.new ACCOUNT_SID, API_KEY_SID, API_SECRET, 3600, user_id
# Grant access to Twilio Video
grant = ::Twilio::Util::AccessToken::ConversationsGrant.new
grant.configuration_profile_sid = VIDEO_SID
token.add_grant grant
token.to_jwt
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment