How to use the auth0.AuthenticationClient 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 votinginfoproject / Metis / authentication / services.js View on Github external
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"]);
github pfernandom / taco-gallery / lib.js View on Github external
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" );
	}
github garden-aid / web-bff / src / authorize.js View on Github external
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)
github auth0 / auth0-deploy-cli / src / context / index.js View on Github external
const errors = [];

  if (!config.AUTH0_DOMAIN) errors.push('AUTH0_DOMAIN');
  if (!config.AUTH0_ACCESS_TOKEN) {
    if (!config.AUTH0_CLIENT_ID) errors.push('AUTH0_CLIENT_ID');
    if (!config.AUTH0_CLIENT_SECRET) errors.push('AUTH0_CLIENT_SECRET');
  }

  if (errors.length > 0) {
    throw new Error(`The following parameters were missing. Please add them to your config.json or as an environment variable. ${JSON.stringify(errors)}`);
  }

  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;
github oughtinc / mosaic / server / lib / schema / auth / userFromAuthToken.ts View on Github external
import { AuthenticationClient } from "auth0";

const { auth0_client_id } = require("../../../config/config.json");

const authClient = new AuthenticationClient({
  domain: "mosaicapp.auth0.com",
  clientId: auth0_client_id,
});

interface UserInfo {
  user_id: string;
  email: string;
  given_name: string;
  family_name: string;
  gender: string;
  picture: string;
  is_admin: boolean;
  is_oracle: boolean;
}

export function userFromAuthToken(
github box / samples / box-node-express-skeleton-app / app / identity-service / identityProvider.js View on Github external
constructor() {
		this.idCache = IdentityTokenCache;
		this.authenticationClient = new AuthenticationClient({
			domain: Auth0Config.domain,
			clientId: Auth0Config.clientId
		});
	}
github auth0-extensions / auth0-delegated-administration-extension / server / routes / users.js View on Github external
api.post('/:id/password-reset', verifyUserAccess('reset:password', scriptManager), (req, res, next) => {
    const client = new auth0.AuthenticationClient({
      domain: config('AUTH0_DOMAIN'),
      clientId: config('AUTH0_CLIENT_ID')
    });

    const user = req.targetUser;
    const data = { email: user.email, connection: req.body.connection };
    return client.requestChangePasswordEmail(data)
      .then(() => res.sendStatus(204))
      .catch(next);
  });
github auth0-extensions / auth0-delegated-administration-extension / server / lib / authenticationApiClient.js View on Github external
module.exports.getForClient = (domain, clientId) =>
  Promise.resolve(new AuthenticationClient({ domain, clientId }));

auth0

SDK for Auth0 API v2

MIT
Latest version published 1 month ago

Package Health Score

89 / 100
Full package analysis