How to use math-random - 7 common examples

To help you get started, we’ve selected a few math-random 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 microsoft / botframework-solutions / solutions / testharnesses / typescript / assistant-WebChat / packages / app / src / index.js View on Github external
import * as serviceWorker from './serviceWorker';
import App from './App';

import connectUsingSecret from './redux/actions/connectUsingSecret';
import connectUsingTokenServer from './redux/actions/connectUsingTokenServer';
import enableSpeechUsingSecret from './redux/actions/enableSpeechUsingSecret';
import enableSpeechUsingTokenServer from './redux/actions/enableSpeechUsingTokenServer';
import createStore from './redux/createStore';

const store = createStore();

// TODO: Move it somewhere
const { directLineSecret, speechServicesSubscriptionKey } = store.getState();

if (directLineSecret) {
  store.dispatch(connectUsingSecret(directLineSecret, random().toString(36).substr(2, 10)));
} else {
  store.dispatch(connectUsingTokenServer());
}

if (speechServicesSubscriptionKey) {
  store.dispatch(enableSpeechUsingSecret(speechServicesSubscriptionKey));
} else {
  store.dispatch(enableSpeechUsingTokenServer());
}

ReactDOM.render(
  
    
  ,
  document.getElementById('root')
);
github microsoft / botframework-solutions / solutions / testharnesses / typescript / assistant-WebChat / packages / server / src / index.js View on Github external
server.post('/api/directline/token', async (_, res) => {
    // TODO: We should rate-limit to prevent abuse
    try {
      const userID = `dl_${ random().toString(36).substr(2, 10) }`;
      const tokenRes = await fetch('https://directline.botframework.com/v3/directline/tokens/generate', {
        body: JSON.stringify({
          User: { Id: userID }
        }),
        headers: {
          authorization: `Bearer ${ directLineSecret }`,
          'content-type': 'application/json'
        },
        method: 'POST'
      });

      if (!tokenRes.ok) {
        return res.send(503, { message: 'failed to exchange Direct Line secret', innerStatus: tokenRes.status });
      }

      const { expires_in: expiresIn, token } = JSON.parse(await tokenRes.text());
github microsoft / BotFramework-WebChat / samples / 19.a.single-sign-on-for-enterprise-apps / rest-api / src / index.js View on Github external
require('dotenv').config();

const random = require('math-random');

// Setting default environment variables.
process.env = {
  AAD_OAUTH_AUTHORIZE_URL: 'https://login.microsoftonline.com/organizations/oauth2/v2.0/authorize',
  AAD_OAUTH_ACCESS_TOKEN_URL: 'https://login.microsoftonline.com/organizations/oauth2/v2.0/token',
  AAD_OAUTH_PKCE_SALT: random.toString(36).substr(2),
  AAD_OAUTH_SCOPE: 'User.Read',
  GITHUB_OAUTH_ACCESS_TOKEN_URL: 'https://github.com/login/oauth/access_token',
  GITHUB_OAUTH_AUTHORIZE_URL: 'https://github.com/login/oauth/authorize',
  GITHUB_OAUTH_SCOPE: 'user:email',
  GITHUB_OAUTH_STATE_SALT: random.toString(36).substr(2),
  PORT: '5000',
  STATIC_FILES: 'public',
  ...process.env
};

// Checks for required environment variables.
[
  'AAD_OAUTH_CLIENT_ID',
  'AAD_OAUTH_REDIRECT_URI',
  'DIRECT_LINE_SECRET',
  'GITHUB_OAUTH_CLIENT_ID',
  'GITHUB_OAUTH_CLIENT_SECRET',
  'GITHUB_OAUTH_REDIRECT_URI'
].forEach(name => {
  if (!process.env[name]) {
    throw new Error(`Environment variable ${name} must be set.`);
github microsoft / BotFramework-WebChat / samples / 19.c.single-sign-on-for-teams-apps / web / src / index.js View on Github external
require('dotenv').config();

const random = require('math-random');

// Setting default environment variables.
process.env = {
  OAUTH_AUTHORIZE_URL: 'https://login.microsoftonline.com/organizations/oauth2/v2.0/authorize',
  OAUTH_ACCESS_TOKEN_URL: 'https://login.microsoftonline.com/organizations/oauth2/v2.0/token',
  OAUTH_PKCE_SALT: random.toString(36).substr(2),
  OAUTH_SCOPE: 'User.Read',
  PORT: '5000',
  STATIC_FILES: 'public',
  ...process.env
};

// Checks for required environment variables.
['OAUTH_CLIENT_ID', 'OAUTH_REDIRECT_URI', 'DIRECT_LINE_SECRET'].forEach(name => {
  if (!process.env[name]) {
    throw new Error(`Environment variable ${name} must be set.`);
  }
});

const { join } = require('path');
const restify = require('restify');
github microsoft / botframework-solutions / solutions / testharnesses / typescript / assistant-WebChat / packages / app / src / redux / actions / connectUsingSecret.js View on Github external
export default function (secret, userID = `dl_${ random().toString(36).substr(2, 10) }`) {
  return async dispatch => {
    dispatch({ type: CONNECT_PENDING });

    try {
      const tokenRes = await fetch('https://directline.botframework.com/v3/directline/tokens/generate', {
        body: JSON.stringify({
          User: { Id: userID }
        }),
        headers: {
          authorization: `Bearer ${ secret }`,
          'content-type': 'application/json'
        },
        method: 'POST'
      });

      if (!tokenRes.ok) {
github microsoft / BotFramework-WebChat / packages / core / src / utils / uniqueID.js View on Github external
export default function uniqueID() {
  return (
    Date.now() +
    random()
      .toString(36)
      .substr(2)
  );
}
github jonschlinkert / randomatic / index.js View on Github external
* Copyright (c) 2014-2017, Jon Schlinkert.
 * Released under the MIT License.
 */

'use strict';

var isNumber = require('is-number');
var typeOf = require('kind-of');
var mathRandom = require('math-random');

/**
 * Expose `randomatic`
 */

module.exports = randomatic;
module.exports.isCrypto = !!mathRandom.cryptographic;

/**
 * Available mask characters
 */

var type = {
  lower: 'abcdefghijklmnopqrstuvwxyz',
  upper: 'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
  number: '0123456789',
  special: '~!@#$%^&()_+-={}[];\',.'
};

type.all = type.lower + type.upper + type.number + type.special;

/**
 * Generate random character sequences of a specified `length`,

math-random

math-random is an isomorphic, drop-in replacement for `Math.random` that uses cryptographically secure random number generation, where available

CC0-1.0
Latest version published 4 years ago

Package Health Score

65 / 100
Full package analysis