Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@crtr0
Last active August 29, 2015 14:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save crtr0/dbb987820f3391a2ab59 to your computer and use it in GitHub Desktop.
Save crtr0/dbb987820f3391a2ab59 to your computer and use it in GitHub Desktop.
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