Skip to content

Instantly share code, notes, and snippets.

@visualjeff
visualjeff / gist:ca00c48f3bfc95f6551302d47cb45040
Created August 9, 2018 22:04
Generating a good nonce in the browser to prevent replay (in Javascript SPA's)
const crypto = crypto.subtle;
async function sha256(message) {
const msgBuffer = new TextEncoder('utf-8').encode(message); // encode as UTF-8
const hashBuffer = await crypto.subtle.digest('SHA-256', msgBuffer); // hash the message
const hashArray = Array.from(new Uint8Array(hashBuffer)); // convert ArrayBuffer to Array
const hashHex = hashArray.map(b => ('00' + b.toString(16)).slice(-2)).join(''); // convert bytes to hex string
return hashHex;
}
let randomNumber = window.crypto.getRandomValues(new Uint32Array(1)); //Generate randomNumber and store in local storage.
@visualjeff
visualjeff / gist:dc8edfde6433b1634a989ac39454ecc1
Created July 30, 2018 20:04
pure Javascript JWT Validation
<!doctype html>
<html class="no-js" lang="en">
<head>
<!-- Written by: jgilber (a.k.a., visualjeff on github) -->
<meta charset="utf-8" />
<meta http-equiv="x-ua-compatible" content="ie=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>JWT Token Validator</title>
@visualjeff
visualjeff / gist:9c4aa07fa68e0a1863ca7cf78f376ba2
Last active June 14, 2018 03:30
Basic detokenization script for a VSTS Release "Bash Task". Intended for inline execution. Uses handlebars syntax. Tested on Linux and Windows. Assumes Node V7.6+ is installed. Also assumes files are prefixed with B2C_1A_ and end with an extension of .xml.
npm install handlebars form-data node-fetch
s="'use strict';
const fs = require('fs');
const path = require('path');
const handlebars = require('handlebars');
const source = process.env.source || '.';
const target = process.env.target || '.';
const tokens = {
@visualjeff
visualjeff / gist:da9449988516a18fd8a1d789aa589ac7
Created April 8, 2018 03:46
Promise.all usage with node-fetch sample code.
#!/usr/bin/env node
'use stict';
const fetch = require('node-fetch');
const urls = ['http://jsonplaceholder.typicode.com/posts/1',
'http://jsonplaceholder.typicode.com/posts/2',
'http://jsonplaceholder.typicode.com/posts/3',
'http://jsonplaceholder.typicode.com/posts/a',
'http://jsonplaceholder.typicode.com/posts/5'
@visualjeff
visualjeff / gist:48e87da311c681c2cbfcaf9dd5e16910
Created October 4, 2017 22:07
Enable remote syslog on Ubuntu
Edit /etc/rsyslog.conf
sudo vim /etc/rsyslog.conf
Uncomment as needed:
# provides UDP syslog reception
#module(load="imudp") <== Uncomment
#input(type="imudp" port="514") <== Uncomment
@visualjeff
visualjeff / gist:aecae12750463a82b73964643bd094cf
Last active August 1, 2017 22:27
HTML for Charley and Alex
<!doctype html>
<html class="no-js" lang="en">
<head>
<meta charset="utf-8" />
<meta http-equiv="x-ua-compatible" content="ie=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>AAD JWT decode and validation utilities</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js" crossorigin="anonymous"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/foundation/6.4.1/css/foundation.min.css" crossorigin="anonymous" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/foundation/6.4.1/js/foundation.min.js" crossorigin="anonymous"></script>
@visualjeff
visualjeff / DataDockerfile
Created April 13, 2017 05:53
How to Dockerize your new scimgateway project
# To build: docker build --force-rm=true -t scimgateway-data:latest .
# To run: docker run -d --name scimgateway-data -t scimgateway-data:latest
FROM busybox:latest
MAINTAINER Jeffrey Gilbert
RUN mkdir -p /home/scimgateway/config
VOLUME /home/scimgateway/config
CMD ["echo", "Data container for scimgateway created and will now shutdown. No need to run again."]
@visualjeff
visualjeff / gist:ff85ff0516cad4ec48571c464a082be7
Created April 5, 2017 05:50
Running Visual Studio Code on Ubuntu or Debian Virtual Image and dealing with a blank screen
As a workaround, edited file /usr/share/applications/code.desktop
Replacing
Exec=/usr/share/code/code --unity-launch %U
with
Exec=/usr/share/code/code --disable-gpu --unity-launch %U
@visualjeff
visualjeff / passport-mock.js
Created March 20, 2017 17:02 — forked from mweibel/passport-mock.js
Mock passport.js with an own strategy
/**
* Author: Michael Weibel <[email protected]>
* License: MIT
*/
var passport = require('passport')
, StrategyMock = require('./strategy-mock');
module.exports = function(app, options) {
// create your verify function on your own -- should do similar things as
@visualjeff
visualjeff / gist:f6de98d08cce7f7eb14972d1d636c16e
Created October 14, 2016 17:05
Automated testing example for Node.js Hapi apps using Lab
Node.js testing:
1. Use the package lab (also code and sinon).
npm install lab --save-dev
npm install code --save-dev // assertion library
npm install sinon --save-dev
2. Add the following test script to your package.json