This flow lets you try out the Auth0 Device Flow using a CLI.
Update the parameters AUTH0_DOMAIN, CLIENT_ID, and AUDIENCE at the top of the file first.
Run node index.js to try the flow.
| 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 | |
| ``` | |
| 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 } |
| <!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; } |
| /** | |
| * 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 |
| import { Injectable } from '@angular/core'; | |
| import { AuthService } from '@auth0/auth0-angular'; | |
| @Injectable({ | |
| providedIn: 'root', | |
| }) | |
| export class AudioService { | |
| isAuthenticated = false |
| [ | |
| { | |
| "email": "[email protected]", | |
| "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 |
| const AuthenticationClient = require('auth0').AuthenticationClient; | |
| const prompts = require('prompts') | |
| const auth0 = new AuthenticationClient({ | |
| domain: 'EXAMPLE.auth0.com', | |
| clientId: 'CLIENT_ID', | |
| clientSecret: 'CLIENT_SECRET' | |
| }) | |
| 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 |