This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const LOG_TAG = '[Login]: '; | |
const start = process.hrtime(); | |
const timeTaken = (start) => { | |
if (!start) { | |
return ''; | |
} | |
const precision = 3; // 3 decimal places | |
const elapsed = process.hrtime(start)[1] / 1000000; // divide by a million to get nano to milli | |
return elapsed.toFixed(precision); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
app.get('/passwordless_redirect', function (req, res) { | |
if (req.query.pwlessStart === 'true' && req.query.token) { | |
res.render('passwordless_redirect', { | |
login_hint: req.query.token, | |
pwlessStart: true, | |
state: req.query.state, | |
auth0_domain: process.env.AUTH0_DOMAIN, | |
auth0_frontend_client_id: process.env.AUTH0_PWLESS_CLIENTID, | |
api_audience: process.env.API_AUDIENCE, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function (user, context, callback) { | |
var request = require("request"); | |
console.log('UPDATE NAME', user); | |
const currentName = user.name; | |
const currentEmail = user.email; | |
console.log(currentName,currentEmail); | |
user = user || {}; | |
if(currentName === currentEmail){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// eslint-disable-next-line no-unused-vars | |
'use strict'; | |
const async = require('async'); | |
const request = require('request-promise'); | |
const uuid = require('uuid'); | |
const generateAuth0AccessToken = async (auth0ClientId, auth0ClientSecret) => { | |
//Generate Auth0 access token via Authentication API | |
let accessToken; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> | |
<title>Passwordless Hosted Login</title> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | |
<!--[if IE 8]> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getByEmail (email, callback) { | |
var jwt = require('jsonwebtoken'); | |
// to use Auth0 search API, first we need a management API `access_token` | |
var tools = require('auth0-extension-tools@1.3.1'); | |
tools.managementApi.getClient({domain: configuration.Domain, clientId: configuration.Client_ID, clientSecret: configuration.Client_Secret}) | |
.then(function(client) { | |
var params = { | |
q: 'email:"' + email + '" AND identities.connection:"' + configuration.Connection + '" !app_metadata.migration_complete:true' | |
}; | |
client.users.getAll(params, function (err, users){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function login (username, password, callback){ | |
var jwt = require('jsonwebtoken'); | |
request({ | |
url: 'https://' + configuration.Domain + '/oauth/token', | |
method: 'POST', | |
json: { | |
grant_type: "http://auth0.com/oauth/grant-type/password-realm", | |
realm : configuration.Connection, | |
scope: 'openid profile email', // todo: add name to scope | |
client_id: configuration.Client_ID, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function verify(email, callback) { | |
var request = require('request'); | |
// DEBUG ONLY | |
console.log('@@@ verify - start @@@'); | |
console.log('email: ' + email); | |
var IDP_ENDPOINT = configuration.ENDPOINT_LOCAL + "/api/v1/verify/account/"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function remove (id, callback) { | |
var request = require('request'); | |
// DEBUG ONLY | |
console.log('@@@ remove - start @@@'); | |
console.log('id: ' + id); | |
if (!id) return callback(null); | |
var IDP_ENDPOINT = configuration.ENDPOINT_LOCAL + "/api/v1/remove/account/"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function changePassword (email, newPassword, callback) { | |
var request = require('request'); | |
// DEBUG ONLY | |
console.log('@@@ changePassword - start @@@'); | |
console.log('email: ' + email); | |
console.log('newPassword: ' + newPassword); | |
var API_ENDPOINT = configuration.ENDPOINT_LOCAL + "/api/v1/change_password/account"; |
NewerOlder