How to use the auth0.ManagementClient function in auth0

To help you get started, we’ve selected a few auth0 examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ibi-group / datatools-ui / scripts / updateAppMetadata.js View on Github external
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)
github serverless / forms-service / frontend / scripts / prebuild.js View on Github external
).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
github taskcluster / taskcluster / services / login / src / handlers / mozilla-auth0.js View on Github external
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;
  }
github RootBank / dinosure / server.js View on Github external
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 = {
github ItalyPaleAle / hereditas / cli / lib / Auth0Management.js View on Github external
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
        })
    }
github olymp / olymp / packages / auth0 / lambda.es6 View on Github external
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);
};
github rrecuero / fstack-ethdapp-template / backend / api / user.js View on Github external
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) => {
github auth0 / node-auth0 / examples / custom-signup / server.js View on Github external
var Auth0 = require('auth0').ManagementClient;
var dotenv    = require('dotenv');
var express   = require('express');
var logger = require('morgan');
var bodyParser = require('body-parser');
var extend = require('xtend');
var app       = express();

dotenv.load();

app.use(logger('combined'));

app.use('/', express.static(__dirname + '/'));

var api = new Auth0({
  domain:    process.env.AUTH0_DOMAIN,
  token:     process.env.AUTH0_TOKEN
});

var CONNECTION = 'Username-Password-Authentication';

app.use(bodyParser.json());
app.use(function (req, res, next) {
  res.header("Access-Control-Allow-Origin", "*");
  res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
  next();
});

app.post('/signup', function (req, res) {
  var data = extend(req.body, {connection: CONNECTION, email_verified: false});
  api.createUser(data, function (err) {
github auth0 / auth0-deploy-cli / src / context / index.js View on Github external
}

  let accessToken = config.AUTH0_ACCESS_TOKEN;

  if (!accessToken) {
    const authClient = new AuthenticationClient({
      domain: config.AUTH0_DOMAIN,
      clientId: config.AUTH0_CLIENT_ID,
      clientSecret: config.AUTH0_CLIENT_SECRET
    });

    const clientCredentials = await authClient.clientCredentialsGrant({ audience: `https://${config.AUTH0_DOMAIN}/api/v2/` });
    accessToken = clientCredentials.access_token;
  }

  const mgmtClient = new ManagementClient({
    domain: config.AUTH0_DOMAIN,
    token: accessToken,
    retry: { maxRetries: config.AUTH0_API_MAX_RETRIES || 10 }
  });

  const inputFile = config.AUTH0_INPUT_FILE;

  const ensureObject = (key, value) => {
    if (typeof value === 'string') {
      try {
        return JSON.parse(value);
      } catch (e) {
        log.debug(`Cannot convert config.${key} to an object. Error: ${e.message}`);
        return value;
      }
    }

auth0

SDK for Auth0 API v2

MIT
Latest version published 13 days ago

Package Health Score

89 / 100
Full package analysis