Skip to content

Instantly share code, notes, and snippets.

View thameera's full-sized avatar

Thameera Senanayaka thameera

View GitHub Profile
@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 / 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 / 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
@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"
},
/*
* Converts a PBKDF2 hash generated by PBKDF2PasswordEncryptor to PHC format
*/
const digest = 'sha1'
const convert = origHash => {
const buf = Buffer.from(origHash, 'base64')
const keylenBits = parseInt(buf.slice(0, 4).toString('hex'), 16)
const keylen = keylenBits / 8
@thameera
thameera / node-passwordless.js
Last active January 21, 2021 23:14
Auth0 Node SDK Passwordless example
const AuthenticationClient = require('auth0').AuthenticationClient;
const prompts = require('prompts')
const auth0 = new AuthenticationClient({
domain: 'EXAMPLE.auth0.com',
clientId: 'CLIENT_ID',
clientSecret: 'CLIENT_SECRET'
})
@thameera
thameera / totp.js
Last active October 28, 2020 04:05
TOTP generator
const base32 = require('base32.js')
const crypto = require('crypto')
const secret = 'MFA_SECRET_GOES_HERE'
// Example secret: JRKTI3COHQ7HKOL3GBJF2MK6HBMG2S3H
const hotp = (counter) => {
const counterHex = counter.toString(16).padStart(16, '0')
// Calculate digest
@thameera
thameera / rule.js
Last active April 16, 2020 07:10
Update metadata with a single patch call
function(user, context, callback) {
const request = require('request');
const userApiUrl = auth0.baseUrl + '/users';
function updateMetadata(cb) {
console.log('updating');
request.patch({
url: userApiUrl + '/' + user.user_id,
headers: {