Skip to content

Instantly share code, notes, and snippets.

View thameera's full-sized avatar

Thameera Senanayaka thameera

View GitHub Profile
@thameera
thameera / count.js
Last active January 1, 2020 01:57
Breakdown of connections usage
const fs = require('fs')
const FILENAME = 'tham.json'
const lines = fs.readFileSync(FILENAME, 'utf8').split('\n').filter(x => !!x)
const connections = {}
lines.map(l => JSON.parse(l)).forEach(user => {
user.identities.forEach(id => {
const conn = id.connection
if (connections[conn]) {
@thameera
thameera / idp-init-ready.js
Last active June 23, 2019 06:18
Perform checkSession to retrieve JWT access tokens during an IdP-initiated login
const validateResults = (err, authResult) => {
if (err) {
// handle error
} else {
const at = authResult.accessToken;
// A naïve check to verify if we received a JWT access token
if (!at || !at.startsWith('eyJ')) {
@thameera
thameera / rule.js
Created May 7, 2019 03:48
Auth0 - add default role to users via rule
async function (user, context, callback) {
// Ensure every user has the user role
if (context.authorization.roles.length === 0) {
console.log(`No roles for the user ${user.user_id}. Assigning default role`);
try {
const request = require('request-promise');
await request.post(`${auth0.baseUrl}/users/${user.user_id}/roles`, {
body: {
"roles": ["rol_6KcsnzJ7Bd4YZeG1"]
@thameera
thameera / calcFSThumbprints.js
Last active June 9, 2021 00:45
Calculate thumbprints from an ADFS metadata file
const xpath = require('xpath')
const dom = require('xmldom').DOMParser
const crypto = require('crypto')
const fs = require('fs')
const calcThumbprint = function (cert) {
const shasum = crypto.createHash('sha1')
const der = new Buffer(cert, 'base64').toString('binary')
shasum.update(der, 'binary')
return shasum.digest('hex')
@thameera
thameera / ad_user_group_rule.js
Created January 26, 2019 02:49
Filter AD users based on their groups
function(user, context, callback) {
var _ = require('lodash');
var groupsAllowed = ['group1', 'group2', 'group3'];
var userHasAccess = _.intersection(user.groups, groupsAllowed) > 0;
if (!userHasAccess) {
return callback(new UnauthorizedError('Access denied.'));
}
@thameera
thameera / wp-special-link-rule.js
Last active September 13, 2018 09:14
Create and link DB users for social logins
@thameera
thameera / Windows10-Setup.ps1
Last active July 21, 2018 13:21 — forked from NickCraver/Windows10-Setup.ps1
(In Progress) PowerShell Script I use to customize my machines in the same way for privacy, search, UI, etc.
##################
# Privacy Settings
##################
# Privacy: Let apps use my advertising ID: Disable
Set-ItemProperty -Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\AdvertisingInfo -Name Enabled -Type DWord -Value 0
# To Restore:
#Set-ItemProperty -Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\AdvertisingInfo -Name Enabled -Type DWord -Value 1
# Privacy: SmartScreen Filter for Store Apps: Disable
Set-ItemProperty -Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\AppHost -Name EnableWebContentEvaluation -Type DWord -Value 0
@thameera
thameera / req.md
Last active February 5, 2018 17:08
Create/update Auth0 pre-registration hook
PUT /api/webtask/TENANT_NAME/HOOK_NAME HTTP/1.1
Host: sandbox.it.auth0.com
Authorization: Bearer YOUR_WEBTASK_TOKEN
Content-Type: application/json

{
    "code": "module.exports = function (user, context, cb) { /* YOUR CODE HERE */ }",
    "meta": {
 "wt-compiler": "auth0-ext-compilers/pre-user-registration",
@thameera
thameera / delete.js
Last active November 15, 2023 11:58
Bulk delete Auth0 users
#!/usr/bin/env node
/*
* Install dependencies with:
* npm install request request-promise-native bottleneck
*
* Replace YOUR_TENANT_NAME, MGMT_TOKEN, and FILENAME
* The input file (FILENAME) should contain a list of user ids to delete, separated by newlines
*/
@thameera
thameera / post-reg-hook.js
Last active August 4, 2020 07:29
Post-user registration hook to add user_id to app_metadata
module.exports = function (user, context, cb) {
var request = require('request@2.56.0');
var tenant_url = 'https://example.au.auth0.com'; // Change this to your Auth0 domain
request.post({
url: tenant_url + '/oauth/token',
json: { 'client_id': context.webtask.secrets.client_id, 'client_secret': context.webtask.secrets.client_secret, 'audience':tenant_url+'/api/v2/', 'grant_type':'client_credentials'}
}, function(err, response, body) {
if (err) {