Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
var token = '[MANAGEMENT_API_TOKEN]'
var ManagementClient = require('auth0').ManagementClient;
var client_id = '[CLIENT_ID]'
// load nysdot users
var users = require('./users_20160525.json')
for (var i = 0; i < users.length; i++) {
console.log(users[i].email + '\t\t\t\t' + users[i].autogenerated)
}
var management = new ManagementClient({
token: token,
domain: 'conveyal.eu.auth0.com'
});
var updateOldUser = (user, datatools) => {
if ('permissions' in datatools) {
console.log(user.email)
var metadata = {
datatools: {}
}
metadata.datatools[client_id] = datatools
management
.users
.updateAppMetadata({ id: user.user_id }, metadata)
.then(user => {
console.log(user)
).then((accessToken) => {
// connect to auth0 ManagementClient
const auth0Management = new auth0.ManagementClient({
token: accessToken,
domain: AUTH0_DOMAIN
})
const clientToUpdateId = {
client_id: AUTH0_CLIENT_ID
}
auth0Management.getClient(clientToUpdateId, (err, client) => {
if (err) {
console.log('auth0Management.getClient err', err)
}
// get current list and remove everything but localhost
const callbackUrls = client.callbacks.filter((url) => {
return url.match(/http\:\/\/localhost/)
}).concat(netlifyCallbackUrls)
// pull duplicates out of array
client_id: this.clientId,
client_secret: this.clientSecret,
audience: `https://${this.domain}/api/v2/`,
});
let token = JSON.parse(res.text).access_token;
if (!token) {
throw new Error('did not receive a token from Auth0 /oauth/token endpoint');
}
// parse the token just enough to figure out when it expires
let decoded = jwt.decode(token);
let expires = decoded.exp;
// create a new
this._managementApi = new auth0.ManagementClient({
domain: this.domain,
token: token,
});
this._managementApiExp = expires;
return this._managementApi;
}
const Router = require('koa-router');
const axios = require('axios');
const port = parseInt(process.env.PORT, 10) || 3000;
const jwt = require('jsonwebtoken');
const jwks = require('jwks-rsa');
const ManagementClient = require('auth0').ManagementClient;
const { format } = require('libphonenumber-js');
const dev = process.env.NODE_ENV !== 'production';
const app = next({ dev });
const handle = app.getRequestHandler();
// Authorization Boilerplate
const auth0config = require('./config.json');
const auth0 = new ManagementClient({
domain: auth0config.AUTH0_CLIENT_DOMAIN,
clientId: process.env.AUTH0_MANAGEMENT_CLIENT_ID,
clientSecret: process.env.AUTH0_MANAGEMENT_CLIENT_SECRET,
scope: 'read:users_app_metadata update:users_app_metadata create:users_app_metadata'
});
// This automatically fetches the authorization configuration from the auth0 tenant
const client = jwks({
jwksUri: auth0config.AUTH0_JWKS_URI
});
const verifyJwt = async (ctx, kid, token) => {
const key = await promisify(client.getSigningKey)(kid);
let signingKey = key.publicKey || key.rsaPublicKey;
let accessKey = jwt.verify(token, signingKey);
ctx.state.user = {
constructor(config) {
// Ensure that the configuration has Auth0 credentials
const auth0Config = config.get('auth0')
if (!auth0Config || !auth0Config.domain || !auth0Config.managementClientId || !auth0Config.managementClientSecret) {
throw Error('Auth0 Management Client credentials are not present')
}
this._config = config
this._management = new ManagementClient({
domain: auth0Config.domain,
clientId: auth0Config.managementClientId,
clientSecret: auth0Config.managementClientSecret
})
}
rateLimit: true,
jwksRequestsPerMinute: 5,
jwksUri: "https://" + config.auth0.domain + "/.well-known/jwks.json"
}),
// Validate the audience and the issuer.
aud: config.auth0.audience,
iss: "https://" + config.auth0.domain + "/",
algorithms: ['RS256']
});
function checkAuth(scope_array) {
return jwtAuthz(scope_array);
}
var authClient = new AuthenticationClient({
domain: config.auth0.domain,
clientId: config.auth0.clientID,
clientSecret: config.auth0.secret
});
function getUserFromRequest(req) {
return {"user_metadata":
{"givenName": req.user["https://dashboard.votinginfoproject.org/givenName"]},
"app_metadata":
{"fipsCodes": req.user["https://dashboard.votinginfoproject.org/fipsCodes"],
"roles": req.user["https://dashboard.votinginfoproject.org/roles"]}};
};
function getUserFipsCodes(req) {
var user = getUserFromRequest(req);
return Object.keys(user["app_metadata"]["fipsCodes"]);
var AWS = require('aws-sdk');
if ( process.env.AWS_REGION ) {
AWS.config.update( { region: process.env.AWS_REGION } );
}
var AuthenticationClient = require('auth0').AuthenticationClient;
if ( typeof process.env.AUTH0_DOMAIN === "undefined" || ! process.env.AUTH0_DOMAIN.match( /\.auth0\.com$/ ) ) {
throw new Error( "Expected AUTHO_DOMAIN environment variable to be set in .env file. See https://manage.auth0.com/#/applications" )
}
if ( typeof process.env.AUTH0_CLIENTID === "undefined" || process.env.AUTH0_CLIENTID.length === 0 ) {
throw new Error( "Expected AUTH0_CLIENTID environment variable to be set in .env file. See https://manage.auth0.com/#/applications" )
}
var auth0 = new AuthenticationClient( {
domain : process.env.AUTH0_DOMAIN,
clientId : process.env.AUTH0_CLIENTID
} );
// extract and return the Bearer Token from the Lambda event parameters
var getToken = function( params ) {
var token;
if ( ! params.type || params.type !== 'TOKEN' ) {
throw new Error( "Expected 'event.type' parameter to have value TOKEN" );
}
var tokenString = params.authorizationToken;
if ( !tokenString ) {
throw new Error( "Expected 'event.authorizationToken' parameter to be set" );
}
const utils = require('./auth/utils');
const auth0 = require('./auth/auth0');
const AuthenticationClient = require('auth0').AuthenticationClient;
const authClient = new AuthenticationClient({
domain: process.env.AUTH0_DOMAIN,
clientId: process.env.AUTH0_CLIENT_ID,
});
module.exports.handler = (event, context, cb) => {
console.log('Received event', event);
const token = utils.getToken(event.authorizationToken);
if (!token) {
return cb('Missing token from event');
}
const authInfo = utils.getAuthInfo(event.methodArn);
return auth0.authorize(token, authClient, authInfo)
const getManagementClient = () => {
if (!auth0) {
auth0 = new ManagementClient({
domain: DOMAIN,
clientId: MANAGEMENT_CLIENT_ID,
clientSecret: MANAGEMENT_CLIENT_SECRET,
audience: MANAGEMENT_CLIENT_AUDIENCE || `https://${DOMAIN}/api/v2/`,
scope: MANAGEMENT_SCOPES
});
}
return Promise.resolve(auth0);
};
import { ManagementClient } from 'auth0';
import { config } from 'config';
const management = new ManagementClient({
domain: config.get('auth0').domain,
clientId: config.get('auth0').client,
clientSecret: config.get('auth0').secret
});
function getUser(req, res, next) {
const { userId } = req.query;
management.getUser({ id: userId, fields: 'user_metadata' }, (error, user) => {
if (error) {
return next('Error getting latest user ' + error);
}
res.status(200).send({ result: user });
});
}
module.exports = (app) => {