Skip to content

Instantly share code, notes, and snippets.

View thameera's full-sized avatar

Thameera Senanayaka thameera

View GitHub Profile
@thameera
thameera / action.js
Last active February 3, 2024 00:42
Actions redirect example
/**
* Handler that will be called during the execution of a PostLogin flow.
*
* @param {Event} event - Details about the user and the context in which they are logging in.
* @param {PostLoginAPI} api - Interface whose methods can be used to change the behavior of the login.
*/
exports.onExecutePostLogin = async (event, api) => {
// Craft a signed session token
const token = api.redirect.encodeToken({
secret: 'keyboardcat', // IMPORTANT: Read this from event.secrets
@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 / surfingkeys.txt
Last active March 22, 2023 21:59
SurfingKeys config
// an example to create a new mapping `ctrl-y`
mapkey('<Ctrl-y>', 'Show me the money', function() {
Normal.showPopup('a well-known phrase uttered by characters in the 1996 film Jerry Maguire (Escape to close).');
});
// Map disabling surfing keys hotkey
map('<Ctrl-i>', '<Alt-s>');
// Free up Alt-s for jetzt's use
unmap('<Alt-s>');
@thameera
thameera / tmuxtest.sh
Created April 16, 2013 16:27
Sample bash script to draw a tmux layout
#!/bin/bash
SN="tmuxwork"
tmux has-session -t $SN &>/dev/null
if [ $? != 0 ]
then
tmux new -s $SN -n conf -d
tmux new-window -t $SN:2 -n misc
@thameera
thameera / Socketio-jwt example
Last active May 20, 2022 05:29
Socketio-jwt example
Uses https://www.npmjs.com/package/@thream/socketio-jwt
Template based on the chat example at: https://socket.io/get-started/chat
Run with:
```
node index.js
```
@thameera
thameera / action-api-call.js
Created March 23, 2022 01:23
Calling an external API via an Action
exports.onExecutePostLogin = async (event, api) => {
2 const axios = require('axios')
3 const namespace = 'https://example.com'
4
5 try {
6 const res = await axios.get('https://api.kanye.rest/')
7 api.idToken.setCustomClaim(`${namespace}/quote`, res.data.quote)
8 } catch (e) {
9 console.log('Error calling the API')
10 }
@thameera
thameera / mfa-api-token.js
Created March 21, 2022 06:27
Getting an MFA API token with Auth0 SPA JS SDK
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<script src="https://cdn.auth0.com/js/auth0-spa-js/1.20/auth0-spa-js.production.js"></script>
<title>MFA API Test</title>
<style>
.hidden { display: none; }
@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 / sha256.json
Last active June 9, 2021 00:40
sha256 password hash import example
[
{
"email": "thameera@example.com",
"email_verified": false,
"custom_password_hash": {
"algorithm": "sha256",
"hash": {
"value": "7054f76f832d2d4e244f73b3f3f4c3702cb60a573ed12441c90f159df560fcb5",
"encoding": "hex"
},
@thameera
thameera / audio.service.ts
Last active June 8, 2021 07:22
Using Auth0-angular's auth.isAuthenticated observable in a service
import { Injectable } from '@angular/core';
import { AuthService } from '@auth0/auth0-angular';
@Injectable({
providedIn: 'root',
})
export class AudioService {
isAuthenticated = false