Skip to content

Instantly share code, notes, and snippets.

@jazlalli
jazlalli / gist:4604200
Last active December 11, 2015 12:58
JWT header
// jwt header
var header = new { typ = "JWT", alg = "RS256" };
// encoding
var headerBytes = Encoding.UTF8.GetBytes(_jsonProvider.Serialize(header));
var headerEncoded = _base64Encoder.ToBase64UrlEncodedString(headerBytes);
@jazlalli
jazlalli / gist:4604269
Last active December 11, 2015 12:58
JWT claimset
// jwt claimset
var issueTime = _dateTimeConverter.ToUnixTimeStamp(date);
var expiryTime = _dateTimeConverter.ToUnixTimeStamp(date.AddMinutes(60));
var claim = new
{
iss = serviceAccountEmail,
scope = "https://www.googleapis.com/auth/bigquery",
aud = "https://accounts.google.com/o/oauth2/token",
iat = issueTime,
@jazlalli
jazlalli / gist:4604395
Created January 23, 2013 10:58
JWT signature
// signature
var signature = headerEncoded + "." + claimEncoded;
var signatureBytes = Encoding.UTF8.GetBytes(signature);
var certificate = new X509Certificate2(privateKey, privateKeyPassword);
// sign signature using SHA256 with RSA
var rsa = (RSACryptoServiceProvider)certificate.PrivateKey;
// As of .NET 3.5 SP1 the CSP instance works with a provider of type PROV_RSA_AES
@jazlalli
jazlalli / gist:4604488
Last active December 11, 2015 12:58
POSTing the JWT
var post = new Dictionary<string, string>
{
{"grant_type", "urn:ietf:params:oauth:grant-type:jwt-bearer"},
{"assertion", jwt }
};
var response = _httpClientProvider.PostAsync(URI, _httpContentProvider.GetFormUrlEncodedContent(post));
var accessToken = _jsonProvider.Deserialize<AccessToken>(response);
@jazlalli
jazlalli / gist:4604498
Created January 23, 2013 11:11
Access token class
public class AccessToken
{
[JsonProperty(PropertyName = "access_token")]
public string Token { get; set; }
[JsonProperty(PropertyName = "token_type")]
public string TokenType { get; set; }
[JsonProperty(PropertyName = "expires_in")]
public int ExpiresIn { get; set; }
@jazlalli
jazlalli / gist:4604622
Created January 23, 2013 11:36
node.js chat server
var app = require('http').createServer(handler),
io = require('socket.io').listen(app),
fs = require('fs');
app.listen(8888);
function handler (req, res) {
fs.readFile(__dirname + req.url, function (err, data) {
if (err) {
res.writeHead(500);
@jazlalli
jazlalli / gist:4604631
Last active July 11, 2016 16:28
node.js chat client
<script src="/jquery/1.4.4/jquery.min.js" ></script>
<script src="/socket.io/socket.io.js" ></script>
<script type="text/javascript">
$(document).ready(function() {
$('#connect-button').click(function() {
$('#form-container').show(300);
var socket = io.connect('<hostname>', {port: 8888});
@jazlalli
jazlalli / gist:4663914
Last active December 11, 2015 21:39
Roman numeral generator - romanNumeralGenerator(inputNumber, outputString) is the main function that recurses to create the roman numeral representation on the integer supplied, albeit, slightly incorrectly. - amendOutput(inputString) corrects the answer to account for the special cases (e.g. IIII -> IV)
var converter = (function () {
'use strict';
var romanNumeralsArray = [
{roman: 'I', number: 1},
{roman: 'V', number: 5},
{roman: 'X', number: 10},
{roman: 'L', number: 50},
{roman: 'C', number: 100},
{roman: 'D', number: 500},
@jazlalli
jazlalli / gist:4757402
Last active December 12, 2015 10:09
using node-sqlserver to connect to a database and execute a stored procedure
var environment = process.env.NODE_ENV || '';
var config = require('../config_' + environment),
sql = require('node-sqlserver'),
visit = {};
visit.log = function (message, callback) {
var visitparams = [],
encodedmsg = unescape(message.data),
msg = JSON.parse(encodedmsg);
@jazlalli
jazlalli / gist:4757499
Last active December 12, 2015 10:09
config object for housing node-sqlserver connection string and its parsed elements
var config_development = {}
config_development.CLOUD_AMQP = 'amqp://127.0.0.1:5672';
config_development.EXCHANGE_NAME = 'DataExchange';
config_development.QUEUE_NAME = 'SqlSubscriberQueue';
config_development.SQL = {};
config_development.SQL.ConnectionString = 'Driver={SQL Server Native Client 10.0};Server=(local);Database=Reporting;Trusted_Connection={Yes}';
var parsesqlconnectionstring = (function () {