How to use the amplify-category-auth.externalAuthEnable function in amplify-category-auth

To help you get started, we’ve selected a few amplify-category-auth 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 aws-amplify / amplify-cli / packages / amplify-category-predictions / provider-utils / awscloudformation / prediction-category-walkthroughs / identify-walkthrough.js View on Github external
const s3Resource = {
    resourceName: answers.resourceName,
  };
  const storageRequirements = { authSelections: 'identityPoolAndUserPool', allowUnauthenticatedIdentities };
  answers.adminTriggerFunction = await addTrigger(context, s3Resource, options, predictionsResourceName);
  answers.triggerFunction = 'NONE';

  // getting requirement satisfaction map
  const satisfiedRequirements = await checkRequirements(storageRequirements, context, storageCategory, answers.resourceName);
  // checking to see if any requirements are unsatisfied
  const foundUnmetRequirements = Object.values(satisfiedRequirements).includes(false);

  // if requirements are unsatisfied, trigger auth
  if (foundUnmetRequirements) {
    try {
      await externalAuthEnable(context, storageCategory, answers.resourceName, storageRequirements);
    } catch (e) {
      context.print.error(e);
      throw e;
    }
  }

  Object.assign(defaultValues, answers);
  const resource = defaultValues.resourceName;
  const resourceDirPath = path.join(projectBackendDirPath, storageCategory, resource);
  delete defaultValues.resourceName;
  delete defaultValues.storageAccess;
  fs.ensureDirSync(resourceDirPath);
  const parametersFilePath = path.join(resourceDirPath, parametersFileName);
  const jsonString = JSON.stringify(defaultValues, null, 4);
  fs.writeFileSync(parametersFilePath, jsonString, 'utf8');
github aws-amplify / amplify-cli / packages / amplify-category-predictions / provider-utils / awscloudformation / prediction-category-walkthroughs / convert-walkthrough.js View on Github external
async function enableGuestAuth(context, resourceName, allowUnauthenticatedIdentities) {
  const { checkRequirements, externalAuthEnable } = require('amplify-category-auth');
  // enable allowUnauthenticatedIdentities
  const identifyRequirements = { authSelections: 'identityPoolAndUserPool', allowUnauthenticatedIdentities };
  // getting requirement satisfaction map
  const satisfiedRequirements = await checkRequirements(identifyRequirements, context, 'predictions', resourceName);
  // checking to see if any requirements are unsatisfied
  const foundUnmetRequirements = Object.values(satisfiedRequirements).includes(false);

  // if requirements are unsatisfied, trigger auth
  if (foundUnmetRequirements) {
    try {
      await externalAuthEnable(context, 'predictions', resourceName, identifyRequirements);
    } catch (e) {
      context.print.error(e);
      throw e;
    }
  }
}
github aws-amplify / amplify-cli / packages / amplify-category-api / provider-utils / awscloudformation / service-walkthroughs / apigw-walkthrough.js View on Github external
if (answer.privacy === 'protected') {
        privacy.auth = await askReadWrite('Authenticated', context, authPrivacy);
        privacy.unauth = await askReadWrite('Guest', context, unauthPrivacy);
        allowUnauthenticatedIdentities = true;
        const apiRequirements = { authSelections: 'identityPoolAndUserPool', allowUnauthenticatedIdentities };
        // getting requirement satisfaction map
        const satisfiedRequirements = await checkRequirements(apiRequirements, context, 'api', answers.resourceName);
        // checking to see if any requirements are unsatisfied
        const foundUnmetRequirements = Object.values(satisfiedRequirements).includes(false);

        // if requirements are unsatisfied, trigger auth

        if (foundUnmetRequirements) {
          try {
            await externalAuthEnable(context, 'api', answers.resourceName, apiRequirements);
          } catch (e) {
            context.print.error(e);
            throw e;
          }
        }
      }
    }

    if (permissionSelected === 'Both' || permissionSelected === 'Individual Groups') {
      // Enable Auth if not enabled

      const apiRequirements = { authSelections: 'identityPoolAndUserPool' };
      // getting requirement satisfaction map
      const satisfiedRequirements = await checkRequirements(apiRequirements, context, 'api', answers.resourceName);
      // checking to see if any requirements are unsatisfied
      const foundUnmetRequirements = Object.values(satisfiedRequirements).includes(false);
github aws-amplify / amplify-cli / packages / amplify-category-predictions / provider-utils / awscloudformation / prediction-category-walkthroughs / identify-walkthrough.js View on Github external
async function enableGuestAuth(context, resourceName, allowUnauthenticatedIdentities) {
  const { checkRequirements, externalAuthEnable } = require('amplify-category-auth');
  // enable allowUnauthenticatedIdentities
  const identifyRequirements = { authSelections: 'identityPoolAndUserPool', allowUnauthenticatedIdentities };
  // getting requirement satisfaction map
  const satisfiedRequirements = await checkRequirements(identifyRequirements, context, 'predictions', resourceName);
  // checking to see if any requirements are unsatisfied
  const foundUnmetRequirements = Object.values(satisfiedRequirements).includes(false);

  // if requirements are unsatisfied, trigger auth
  if (foundUnmetRequirements) {
    try {
      await externalAuthEnable(context, 'predictions', resourceName, identifyRequirements);
    } catch (e) {
      context.print.error(e);
      throw e;
    }
  }
}
github aws-amplify / amplify-cli / packages / amplify-category-predictions / provider-utils / awscloudformation / prediction-category-walkthroughs / infer-walkthrough.js View on Github external
async function enableGuestAuth(context, resourceName, allowUnauthenticatedIdentities) {
  const { checkRequirements, externalAuthEnable } = require('amplify-category-auth');
  // enable allowUnauthenticatedIdentities
  const identifyRequirements = { authSelections: 'identityPoolAndUserPool', allowUnauthenticatedIdentities };
  // getting requirement satisfaction map
  const satisfiedRequirements = await checkRequirements(identifyRequirements, context, 'predictions', resourceName);
  // checking to see if any requirements are unsatisfied
  const foundUnmetRequirements = Object.values(satisfiedRequirements).includes(false);

  // if requirements are unsatisfied, trigger auth
  if (foundUnmetRequirements) {
    try {
      await externalAuthEnable(context, 'predictions', resourceName, identifyRequirements);
    } catch (e) {
      context.print.error(e);
      throw e;
    }
  }
}
github aws-amplify / amplify-cli / packages / amplify-category-storage / provider-utils / awscloudformation / service-walkthroughs / s3-walkthrough.js View on Github external
}
    }
  }

  const storageRequirements = { authSelections: 'identityPoolAndUserPool', allowUnauthenticatedIdentities };

  // getting requirement satisfaction map
  const satisfiedRequirements = await checkRequirements(storageRequirements, context, 'storage', answers.resourceName);
  // checking to see if any requirements are unsatisfied
  const foundUnmetRequirements = Object.values(satisfiedRequirements).includes(false);

  // if requirements are unsatisfied, trigger auth

  if (foundUnmetRequirements) {
    try {
      await externalAuthEnable(context, category, answers.resourceName, storageRequirements);
    } catch (e) {
      context.print.error(e);
      throw e;
    }
  }

  Object.assign(defaultValues, answers);
  const resource = defaultValues.resourceName;
  const resourceDirPath = path.join(projectBackendDirPath, category, resource);
  fs.ensureDirSync(resourceDirPath);
  let props = { ...defaultValues };

  if (!parameters.resourceName) {
    if (options) {
      props = { ...defaultValues, ...options };
    }
github aws-amplify / amplify-cli / packages / amplify-category-api / provider-utils / awscloudformation / service-walkthroughs / apigw-walkthrough.js View on Github external
}

    if (permissionSelected === 'Both' || permissionSelected === 'Individual Groups') {
      // Enable Auth if not enabled

      const apiRequirements = { authSelections: 'identityPoolAndUserPool' };
      // getting requirement satisfaction map
      const satisfiedRequirements = await checkRequirements(apiRequirements, context, 'api', answers.resourceName);
      // checking to see if any requirements are unsatisfied
      const foundUnmetRequirements = Object.values(satisfiedRequirements).includes(false);

      // if requirements are unsatisfied, trigger auth

      if (foundUnmetRequirements) {
        try {
          await externalAuthEnable(context, 'api', answers.resourceName, apiRequirements);
        } catch (e) {
          context.print.error(e);
          throw e;
        }
      }

      // Get Auth resource name
      const authResourceName = await getAuthResourceName(context);
      answers.authResourceName = authResourceName;

      let defaultSelectedGroups = [];

      if (currentPath && currentPath.privacy && currentPath.privacy.userPoolGroups) {
        defaultSelectedGroups = Object.keys(currentPath.privacy.userPoolGroups);
      }
github aws-amplify / amplify-cli / packages / amplify-category-analytics / provider-utils / awscloudformation / service-walkthroughs / pinpoint-walkthrough.js View on Github external
allowUnauthenticatedIdentities: true,
    };
    // getting requirement satisfaction map
    const satisfiedRequirements = await checkRequirements(apiRequirements, context, 'api', answers.resourceName);
    // checking to see if any requirements are unsatisfied
    const foundUnmetRequirements = Object.values(satisfiedRequirements).includes(false);

    if (foundUnmetRequirements) {
      context.print.warning('Adding analytics would add the Auth category to the project if not already added.');
      if (
        await amplify.confirmPrompt.run(
          'Apps need authorization to send analytics events. Do you want to allow guests and unauthenticated users to send analytics events? (we recommend you allow this when getting started)'
        )
      ) {
        try {
          await externalAuthEnable(context, 'api', answers.resourceName, apiRequirements);
        } catch (e) {
          context.print.error(e);
          throw e;
        }
      } else {
        try {
          context.print.warning(
            'Authorize only authenticated users to send analytics events. Use "amplify update auth" to modify this behavior.'
          );
          apiRequirements.allowUnauthenticatedIdentities = false;
          await externalAuthEnable(context, 'api', answers.resourceName, apiRequirements);
        } catch (e) {
          context.print.error(e);
          throw e;
        }
      }
github aws-amplify / amplify-cli / packages / amplify-category-xr / lib / auth-helper.js View on Github external
async function ensureAuth(context) {
  const xrRequirements = { authSelections: 'identityPoolOnly', allowUnauthenticatedIdentities: true };
  const satisfiedRequirements = await checkRequirements(xrRequirements, context);
  const foundUnmetRequirements = Object.values(satisfiedRequirements).includes(false);

  if (foundUnmetRequirements) {
    context.print.warning('Adding XR to your project requires the Auth category.');
    try {
      await externalAuthEnable(context, constants.CategoryName, constants.ServiceName, xrRequirements);
    } catch (e) {
      context.print.error(e);
      throw e;
    }
  }
}
github aws-amplify / amplify-cli / packages / amplify-category-interactions / provider-utils / awscloudformation / auth-helper.js View on Github external
async function ensureAuth(context) {
  const interactionsRequirements = { authSelections: 'identityPoolOnly', allowUnauthenticatedIdentities: true };
  const satisfiedRequirements = await checkRequirements(interactionsRequirements, context);
  const foundUnmetRequirements = Object.values(satisfiedRequirements).includes(false);

  if (foundUnmetRequirements) {
    context.print.warning(`Adding ${CategoryName} would also add the Auth category to the project if not already added.`);
    try {
      await externalAuthEnable(context, CategoryName, '', interactionsRequirements);
    } catch (e) {
      context.print.error(e);
      throw e;
    }
  }
}

amplify-category-auth

amplify-cli authentication plugin

Apache-2.0
Latest version published 3 years ago

Package Health Score

69 / 100
Full package analysis