public async Task <HttpResponseMessage> GetConversationsToken(string name) { // create an access token generator w/ specific permission grants var token = new AccessToken( settings.Account.Sid, settings.ApiKey, settings.ApiSecret); token.Identity = name == "browser" ? Identity.Name.Split('@')[0] : name; var convoGrant = new ConversationsGrant { ConfigurationProfileSid = settings.Conversation.Sid }; var voiceGrant = new VoiceGrant(); token.AddGrant(convoGrant); token.AddGrant(voiceGrant); var response = new ApiResponse <TwilioToken>(new TwilioToken { Identity = name, Token = token.ToJWT() }); return(SendHttpResponse(response)); }
// GET: /token public ActionResult Index(string Device) { // Load Twilio configuration from Web.config var accountSid = ConfigurationManager.AppSettings["TwilioAccountSid"]; var apiKey = ConfigurationManager.AppSettings["TwilioApiKey"]; var apiSecret = ConfigurationManager.AppSettings["TwilioApiSecret"]; var videoConfigSid = ConfigurationManager.AppSettings["TwilioConfigurationSid"]; // Create a random identity for the client var identity = Internet.UserName(); // Create an Access Token generator var token = new AccessToken(accountSid, apiKey, apiSecret); token.Identity = identity; // Create a video grant for this token var grant = new ConversationsGrant(); token.AddGrant(grant); return(Json(new { identity = identity, token = token.ToJWT() }, JsonRequestBehavior.AllowGet)); }