Last active
August 29, 2015 14:21
-
-
Save crtr0/dbb987820f3391a2ab59 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using JWT; | |
namespace HelloWorld | |
{ | |
class Hello | |
{ | |
static void Main() | |
{ | |
var payload = new | |
{ | |
iss = "ACxxx", | |
exp = ConvertToUnixTimestamp(DateTime.UtcNow.AddSeconds(3600)), | |
version = "v1", | |
friendly_name = "WKxxx", | |
account_sid = "ACxxx", | |
workspace_sid = "WSxxx", | |
worker_sid = "WKxxx", | |
channel = "WKxxx", | |
policies = new Dictionary<string, Object>[] | |
{ | |
new Dictionary<string, Object> { | |
{ "url", "https://event-bridge.twilio.com/v1/wschannels/ACxxx/WKxxx"}, | |
{ "method", "GET"}, | |
{ "allow", true} | |
}, | |
new Dictionary<string, Object> { | |
{ "url", "https://event-bridge.twilio.com/v1/wschannels/ACxxx/WKxxx"}, | |
{ "method", "POST"}, | |
{ "allow", true} | |
}, | |
new Dictionary<string, Object> { | |
{ "url", "https://taskrouter.twilio.com/v1/Workspaces/WSxxx/Workers/WKxxx"}, | |
{ "method", "GET"}, | |
{ "allow", true} | |
}, | |
new Dictionary<string, Object> { | |
{ "url", "https://taskrouter.twilio.com/v1/Workspaces/WSxxx/Workers/WKxxx"}, | |
{ "method", "POST"}, | |
{ "allow", true}, | |
{ "query_filter", new {}}, | |
{ "post_filter", new { | |
ActivitySid = new { | |
required = true | |
} | |
}} | |
}, | |
new Dictionary<string, Object> { | |
{ "url", "https://taskrouter.twilio.com/v1/Workspaces/WSxxx/Tasks/**"}, | |
{ "method", "GET"}, | |
{ "allow", true} | |
}, | |
new Dictionary<string, Object> { | |
{ "url", "https://taskrouter.twilio.com/v1/Workspaces/WSxxx/Tasks/**"}, | |
{ "method", "POST"}, | |
{ "allow", true} | |
} | |
} | |
}; | |
Console.WriteLine(JsonWebToken.Encode(payload, "authToken", JwtHashAlgorithm.HS256)); | |
} | |
static int ConvertToUnixTimestamp(DateTime date) | |
{ | |
DateTime origin = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc); | |
TimeSpan diff = date - origin; | |
return (int)Math.Floor(diff.TotalSeconds); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment