public JsonResult GetToken() { // Load Twilio configuration from Web.config var accountSid = _configuration["TwilioSettings:AccountSid"]; var apiKey = _configuration["TwilioSettings:ApiKey"]; var apiSecret = _configuration["TwilioSettings:ApiSecret"]; // Create a random identity for the client var identity = HttpContext.Session.GetObject(StorageType.Name).ToString();// LocalStorageExtensions.Get(StorageType.Name); // Create a video grant for the token var grant = new VideoGrant(); grant.Room = "Care Portal - " + String.Format("{0:ddd, MMM d, yyyy}", DateTime.Now); var grants = new HashSet <IGrant> { grant }; // Create an Access Token generator var token = new Token(accountSid, apiKey, apiSecret, identity: identity, grants: grants); return(Json(new { identity = identity, token = token.ToJwt() })); }
public async Task <string> GetTwilioToken() { try { string twilioAccountSid = config.GetValue <string>("TwilioSettings:AccountSid"); string twilioApiKey = config.GetValue <string>("TwilioSettings:ApiKey"); string twilioApiSecret = config.GetValue <string>("TwilioSettings:ApiSecret"); // These are specific to Video const string identity = "user"; // Create a Video grant for this token var grant = new VideoGrant(); grant.Room = "cool room"; var grants = new HashSet <IGrant> { grant }; // Create an Access Token generator var token = new Token( twilioAccountSid, twilioApiKey, twilioApiSecret, identity: identity, grants: grants); //Console.WriteLine(token.ToJwt()); return(token.ToJwt()); } catch (Exception ex) { throw ex; } }
//private readonly ITokenService tokenService; //public HomeController(ITokenService tokenService) //{ // this.tokenService = tokenService; //} public ActionResult Index() { // var token = tokenService.GenerateRandomToken(); // Substitute your Twilio AccountSid and ApiKey details var accountSid = "ACe60fd0aea5789edf56167aeed10e79ae"; var apiKey = "SK88d8d89c9d57c43fc8677f1053169513"; var apiSecret = "asMg80rqKGWjy4Bo1PPVA9K53tceJT5b"; Random rand = new Random(); var identity = rand.Next().ToString(); // Create a random identity for the client // Create a video grant for the token var grant = new VideoGrant(); var grants = new HashSet <IGrant> { grant }; // Create an Access Token generator var token = new Token(accountSid, apiKey, apiSecret, identity: identity, grants: grants); var tokenstring = token.ToJwt(); System.Diagnostics.Debug.WriteLine("asdasdasd"); var model = new TokenProfile { Token = tokenstring }; return(View("Index", model)); }
public IActionResult Get([FromQuery] string identity) { // These values are necessary for any access token const string twilioAccountSid = "ACaac624ef42e8299f0e3bb25497dc839d"; const string twilioApiKey = "SK7ba2eaaf7a8ce751e4471ec7c290be69"; const string twilioApiSecret = "iVL4kfIKnWcX2Q3ivhjSfoUbXDf4S3rO"; // // These are specific to Chat // const string serviceSid = "ISXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"; // const string identity = "*****@*****.**"; // Create an Chat grant for this token var grant = new VideoGrant(); var grants = new HashSet <IGrant> { { grant } }; // Create an Access Token generator var token = new Token( twilioAccountSid, twilioApiKey, twilioApiSecret, identity, grants: grants); return(Ok(new { Token = token.ToJwt() })); }
public static string AccessTokenVideo() { const string twilioAccountSid = "ACaba23a7d277cde563020cbd18849eaa5"; const string twilioApiKey = "SK2c6f8ce2d5d052b46362c71e54f8d6e6"; const string twilioApiSecret = "jzIuH7vDf8SrQYDBoWyi3gQRpYA2ZuI7"; // These are specific to Video const string identity = "user"; // Create a Video grant for this token var grant = new VideoGrant(); grant.Room = "cool room"; var grants = new HashSet <IGrant> { grant }; // Create an Access Token generator var token = new Token( twilioAccountSid, twilioApiKey, twilioApiSecret, identity: identity, grants: grants); return(token.ToJwt()); }
public static string GetTwilioToken( this TwilioOptions opts, string name, string host, long start ) { var grant = new VideoGrant() { Room = $"{host}/{start}" }; var grants = new HashSet <IGrant> { grant }; var nbf = DateTimeOffset.FromUnixTimeMilliseconds(start).Subtract(TimeSpan.FromMinutes(5)); var token = new Token( accountSid: opts.AccountSid, signingKeySid: opts.ApiKeySid, secret: opts.ApiKeySecret, identity: name, expiration: nbf.AddMinutes(30).DateTime, nbf: nbf.DateTime, grants: grants); return(token.ToJwt()); }
public static string AccessTokenGenerator() { // Substitute your Twilio AccountSid and ApiKey details var AccountSid = "AC629d1233ead64b5341d2728f5eb160dc"; var ApiKeySid = "SK0678c0ad0045e85ac68f91d3eca7c87c"; var ApiKeySecret = "6AQNum22c9t20kZsbGXffSZQDpEyjyWs"; TwilioClient.Init(ApiKeySid, ApiKeySecret); //Console.WriteLine(room.Sid); var identity = "bhanus"; // Create a video grant for the token var grant = new VideoGrant(); string letters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ123456789"; Random rndm = new Random(); string ServerVariable = new string(Enumerable.Repeat(letters, 10).Select(s => s[rndm.Next(s.Length)]).ToArray()); grant.Room = "bhanu"; var grants = new HashSet <IGrant> { grant }; // Create an Access Token generator var token = new Token(AccountSid, ApiKeySid, ApiKeySecret, identity: identity, grants: grants); // Serialize the token as a JWT String Jwttoken = token.ToJwt(); Console.WriteLine(token.ToJwt()); return(Jwttoken); }
static void Main(string[] args) { // These values are necessary for any access token // To set up environmental variables, see http://twil.io/secure const string twilioAccountSid = Environment.GetEnvironmentVariable("TWILIO_ACCOUNT_SID"); const string twilioApiKey = Environment.GetEnvironmentVariable("TWILIO_API_KEY"); const string twilioApiSecret = Environment.GetEnvironmentVariable("TWILIO_API_SECRET"); // These are specific to Video const string identity = "user"; // Create a Video grant for this token var grant = new VideoGrant(); grant.Room = "cool room"; var grants = new HashSet <IGrant> { grant }; // Create an Access Token generator var token = new Token( twilioAccountSid, twilioApiKey, twilioApiSecret, identity: identity, grants: grants); Console.WriteLine(token.ToJwt()); }
public static string AccessTokenGenerator() { // Substitute your Twilio AccountSid and ApiKey details var AccountSid = "AC8afec90bbe166f208ecf04fb48717251"; var ApiKeySid = "SKd8aac04eba0fa8ed056c6263990fa85c"; var ApiKeySecret = "uUiLZ8XytHGuo15BPnU4EuZ5kdywBDWO"; TwilioClient.Init(ApiKeySid, ApiKeySecret); //Console.WriteLine(room.Sid); var identity = "bhan"; // Create a video grant for the token var grant = new VideoGrant(); string letters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ123456789"; Random rndm = new Random(); string ServerVariable = new string(Enumerable.Repeat(letters, 10).Select(s => s[rndm.Next(s.Length)]).ToArray()); grant.Room = "Alice"; var grants = new HashSet <IGrant> { grant }; // Create an Access Token generator var token = new Token(AccountSid, ApiKeySid, ApiKeySecret, identity: identity, grants: grants); // Serialize the token as a JWT String Jwttoken = token.ToJwt(); Console.WriteLine(token.ToJwt()); return(Jwttoken); }
public IActionResult Tokenization3(string id) { const string twilioApiKey = "SK00736ea2aac54066cc80e230ace02aa1"; const string twilioAccountSid = "AC42b1d323b12ebcfd750d1de681d47f80"; const string twilioApiSecret = "GeI7uS6MUgeOx7hRDwZ7N387rtvCmrVf"; // These are specific to Video //const string identity = "user1"; // Create a Video grant for this token var grant = new VideoGrant(); grant.Room = "my-new-room"; var grants = new HashSet <IGrant> { grant }; // Create an Access Token generator var token = new Token( twilioAccountSid, twilioApiKey, twilioApiSecret, identity: id, grants: grants); Console.WriteLine(token.ToJwt()); return(Json(new TokenDTO { token = token.ToJwt() })); }
public string GenerateRandomToken() { // Substitute your Twilio AccountSid and ApiKey details var accountSid = ""; var apiKey = ""; var apiSecret = ""; var identity = "example-user"; // Create a random identity for the client // Create a video grant for the token var grant = new VideoGrant(); grant.Room = "cool room"; var grants = new HashSet <IGrant> { grant }; // Create an Access Token generator var token = new Token(accountSid, apiKey, apiSecret, identity: identity, grants: grants); return(token.ToJwt()); }
// GET: Token public ActionResult Index() { // Load Twilio configuration from Web.config var accountSid = ConfigurationManager.AppSettings["TwilioAccountSid"]; var apiKey = ConfigurationManager.AppSettings["TwilioApiKey"]; var apiSecret = ConfigurationManager.AppSettings["TwilioApiSecret"]; // Create a random identity for the client var identity = Request.QueryString["identity"] ?? "identity"; // Create a video grant for the token var grant = new VideoGrant(); grant.Room = Request.QueryString["room"]; var grants = new HashSet <IGrant> { grant }; // Create an Access Token generator var token = new Token(accountSid, apiKey, apiSecret, identity: identity, grants: grants); return(Json(new { token = token.ToJwt() }, JsonRequestBehavior.AllowGet)); }
// GET: /token public ActionResult Index() { // 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 a video grant for the token var grant = new VideoGrant(); grant.ConfigurationProfileSid = videoConfigSid; var grants = new HashSet <IGrant> { grant }; // Create an Access Token generator var token = new Token(accountSid, apiKey, apiSecret, identity: identity, grants: grants); return(Json(new { identity, token = token.ToJwt() }, JsonRequestBehavior.AllowGet)); }
public static string AccessTokenGenerator() { // Substitute your Twilio AccountSid and ApiKey details var AccountSid = "ACfaeaf5681a4b27e04896c8d57b7a829b"; var ApiKeySid = "SK26a5ad58fe67cd4192caf9d49c11e160"; var ApiKeySecret = "3ROMylcwSwpUCn0ROstqRgSWmGr4alvk"; TwilioClient.Init(ApiKeySid, ApiKeySecret); //Console.WriteLine(room.Sid); var identity = "bhan"; // Create a video grant for the token var grant = new VideoGrant(); string letters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ123456789"; Random rndm = new Random(); string ServerVariable = new string(Enumerable.Repeat(letters, 10).Select(s => s[rndm.Next(s.Length)]).ToArray()); grant.Room = "Anu"; var grants = new HashSet <IGrant> { grant }; // Create an Access Token generator var token = new Token(AccountSid, ApiKeySid, ApiKeySecret, identity: identity, grants: grants); // Serialize the token as a JWT String Jwttoken = token.ToJwt(); Console.WriteLine(token.ToJwt()); return(Jwttoken); }
// 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; // Grant access to Video var grant = new VideoGrant(); grant.ConfigurationProfileSid = videoConfigSid; token.AddGrant(grant); return(Json(new { identity = identity, token = token.ToJWT() }, JsonRequestBehavior.AllowGet)); }
static void Main(string[] args) { // These values are necessary for any access token const string twilioAccountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"; const string twilioApiKey = "SKXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"; const string twilioApiSecret = "your_secret"; // These are specific to Video const string configurationProfileSid = "VSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"; const string identity = "user"; // Create a Video grant for this token var grant = new VideoGrant(); grant.ConfigurationProfileSid = configurationProfileSid; var grants = new HashSet <IGrant> { { grant } }; // Create an Access Token generator var token = new Token( twilioAccountSid, twilioApiKey, twilioApiSecret, identity, grants: grants); Console.WriteLine(token.ToJwt()); }
public string GenerateCode(string username, Guid appointment_id) { // These values are necessary for any access token const string twilioAccountSid = "AC861cc9e047e9ebed0cc411bffa22bb76"; const string twilioApiKey = "SK3297d49d323e5231d0327403aed505e2"; const string twilioApiSecret = "ApWMgQk3PJjkS8woWW3f212SuUy5u1R1"; // These are specific to Video const string identity = "use1r"; // Create a Video grant for this token var grant = new VideoGrant(); //grant.Room = "cool room"; grant.Room = appointment_id.ToString(); var grants = new HashSet <IGrant> { grant }; // Create an Access Token generator var token = new Token( twilioAccountSid, twilioApiKey, twilioApiSecret, identity: username, grants: grants); //Console.WriteLine(token.ToJwt()); return(token.ToJwt()); }
public string GetToken(string identity) { var grant = new VideoGrant(); grant.Room = "cool room"; var grants = new HashSet <IGrant> { grant }; return(_videoService.GetTwilioJwt(identity, grants)); }
// get twilio token private void GetTwilioToken() { var grant = new VideoGrant(); grant.Room = RoomId; var grants = new HashSet <IGrant> { grant }; var identity = UserId; var token = new Token(twilioAccountSid, twilioApiKey, twilioApiSecret, identity, grants: grants); Token = token.ToJwt(); }
public JsonResult Token() { // This can be tracked internally by your web app. var identity = randomUserId(); var grants = new HashSet <IGrant>(); var videoGrant = new VideoGrant(); grants.Add(videoGrant); if (_appSettings.TWILIO_CHAT_SERVICE_SID != String.Empty) { // Create a "grant" which enables a client to use IPM as a given user, // on a given device. var ipmGrant = new IpMessagingGrant() { ServiceSid = _appSettings.TWILIO_CHAT_SERVICE_SID, }; grants.Add(ipmGrant); } if (_appSettings.TWILIO_SYNC_SERVICE_SID != String.Empty) { var syncGrant = new SyncGrant() { ServiceSid = _appSettings.TWILIO_SYNC_SERVICE_SID }; grants.Add(syncGrant); } var token = new Token( _appSettings.TWILIO_ACCOUNT_SID, _appSettings.TWILIO_API_KEY, _appSettings.TWILIO_API_SECRET, identity, grants: grants ).ToJwt(); return(new JsonResult(new Dictionary <string, string>() { { "identity", identity }, { "token", token } })); }
public IHttpActionResult GetAccessToken(AccessTokenModel model) { string accountSid = this._manager.GetString("AccountSID"); string apiKeySid = this._manager.GetString("AccountApiKeySID"); string apiKeySecret = this._manager.GetString("ApiKeySecret"); string identity = model.Name; string room = model.Room; var grant = new VideoGrant(); var grants = new HashSet <IGrant> { grant }; var token = new Token(accountSid, apiKeySid, apiKeySecret, identity: identity, grants: grants); return(Ok(token.ToJwt())); }
public Tuple <Token, string> CreateToken() { // Create a video grant for the token var grant = new VideoGrant(); var grants = new HashSet <IGrant> { grant }; var identity = Guid.NewGuid(); // Create an Access Token generator var token = new Token(_apiAccountSid, _apiKey, _apiKeySecret, identity.ToString(), _expiryTime, DateTime.Now, grants); // Serialize the token as a JWT return(new Tuple <Token, string>(token, identity.ToString())); }
public string Generate(string identity, string channelName, string endpointId, string TokenType) { HashSet <IGrant> grants = null; if (TokenType == "Chat") { grants = new HashSet <IGrant> { new ChatGrant { EndpointId = endpointId, ServiceSid = _config["TwilioAccount:ChatServiceSid"], } }; } else if (TokenType == "Voice") { var grant = new VoiceGrant(); grant.OutgoingApplicationSid = _config["TwiloVoiceAppSid"]; // Optional: add to allow incoming calls grant.IncomingAllow = true; grants = new HashSet <IGrant> { { grant } }; } else if (TokenType == "Video") { var grant = new VideoGrant(); grant.Room = channelName; grants = new HashSet <IGrant> { grant }; } var token = new Token( _config["TwilioAccount:AccountSid"], _config["TwilioAccount:ApiKey"], _config["TwilioAccount:ApiSecret"], identity, grants: grants ); return(token.ToJwt()); }
private JsonResult CreateTokenResult(string identity) { var grants = new HashSet <IGrant>(); var videoGrant = new VideoGrant(); grants.Add(videoGrant); if (_twilioAccount.ChatServiceSid != String.Empty) { // Create a "grant" which enables a client to use IPM as a given user, // on a given device. var chatGrant = new ChatGrant() { ServiceSid = _twilioAccount.ChatServiceSid }; grants.Add(chatGrant); } if (_twilioAccount.SyncServiceSid != String.Empty) { var syncGrant = new SyncGrant() { ServiceSid = _twilioAccount.SyncServiceSid }; grants.Add(syncGrant); } var token = new Token( _twilioAccount.AccountSid, _twilioAccount.ApiKey, _twilioAccount.ApiSecret, identity, grants: grants ).ToJwt(); return(new JsonResult(new Dictionary <string, string>() { { "identity", identity }, { "token", token } })); }
public void ShouldCreateVideoGrant() { var token = new AccessToken("AC456", "SK123", "foobar"); var delta = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc); var timestamp = (int)Math.Floor(delta.TotalSeconds); var vg = new VideoGrant(); vg.ConfigurationProfileSid = "CP123"; token.AddGrant(vg); var encoded = token.ToJWT(); Assert.IsNotNull(encoded); Assert.IsNotEmpty(encoded); var decoded = JsonWebToken.Decode(encoded, "foobar"); Assert.IsNotEmpty(decoded); var serializer = new JavaScriptSerializer(); var payload = (Dictionary <string, object>)serializer.DeserializeObject(decoded); Assert.IsNotNull(payload); Assert.AreEqual("SK123", payload["iss"]); Assert.AreEqual("AC456", payload["sub"]); var exp = Convert.ToInt64(payload["exp"]); Assert.AreEqual(timestamp + 3600, exp); var jti = (string)payload["jti"]; Assert.AreEqual("SK123-" + timestamp.ToString(), jti); var grants = (Dictionary <string, object>)payload["grants"]; Assert.AreEqual(1, grants.Count); var decodedVg = (Dictionary <string, object>)grants["video"]; Assert.AreEqual("CP123", decodedVg["configuration_profile_sid"]); }
public string GenerateForVideo(string identity) { //var grants = new HashSet<IGrant>{}; var grant = new VideoGrant(); //grant.Room = RoomName; var grants = new HashSet <IGrant> { grant }; var token = new Token( Configuration.AccountSID, Configuration.ApiKey, Configuration.ApiSecret, identity, grants: grants); return(token.ToJwt()); }
public ActionResult Get(string identity, string roomName) { // Create an Chat grant for this token var grant = new VideoGrant { Room = roomName }; var grants = new HashSet <IGrant> { { grant } }; // Create an Access Token generator var token = new Token( appSettings.TwilioAccountSid, appSettings.TwilioApiKeySid, appSettings.TwilioApiKeySecret, identity, grants: grants); return(Ok(token.ToJwt())); }
private string GenerateCode(string appointmentId) { // Create a Video grant for this token var grant = new VideoGrant { Room = appointmentId }; var grants = new HashSet <IGrant> { grant }; // Create an Access Token generator var token = new Token( _twilioSettings.TwilioAccountSid, _twilioSettings.TwilioApiKey, _twilioSettings.TwilioApiSecret, identity: User.Identity.Name.ToString(), grants: grants); return(token.ToJwt()); }
public Task <string> Generate(string identity) { var grants = new HashSet <IGrant>(); var videoGrant = new VideoGrant(); grants.Add(videoGrant); if (_account.ChatServiceSid != string.Empty) { var chatGrant = new ChatGrant() { ServiceSid = _account.ChatServiceSid, }; grants.Add(chatGrant); } if (_account.SyncServiceSid != string.Empty) { var syncGrant = new SyncGrant() { ServiceSid = _account.SyncServiceSid }; grants.Add(syncGrant); } var token = new Token( _account.AccountSid, _account.ApiKey, _account.ApiSecret, identity, grants: grants ).ToJwt(); return(Task.FromResult(token)); }
public IActionResult Tokenization(string user) { // These values are necessary for any access token //const string twilioAccountSid = "ACe57633cc4cf60308ecd1b3446061cc2a"; const string twilioApiKey = "SK4403ac62d53601fa6dfd2aaef5efcd14"; //live const string twilioAccountSid = "AC42b1d323b12ebcfd750d1de681d47f80"; //const string twilioApiKey = "d3fe58223f08177d7d822a74e2945882"; const string twilioApiSecret = "eDK6QmxGnt1kSlAQe9yvg9lMmIPKeXJC"; // These are specific to Video //const string identity = "user1"; // Create a Video grant for this token var grant = new VideoGrant(); grant.Room = "my-new-room"; var grants = new HashSet <IGrant> { grant }; // Create an Access Token generator var token = new Token( twilioAccountSid, twilioApiKey, twilioApiSecret, identity: user, grants: grants); Console.WriteLine(token.ToJwt()); return(Json(new TokenDTO { token = token.ToJwt() })); }