How to use the @authx/scopes.extract function in @authx/scopes

To help you get started, we’ve selected a few @authx/scopes 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 the-control-group / authx / packages / authx / src / util / explanations.ts View on Github external
/* eslint-disable @typescript-eslint/camelcase */
        current_authorization_id: substitutions.currentAuthorizationId,
        current_user_id: substitutions.currentUserId,
        current_grant_id: substitutions.currentGrantId,
        current_client_id: substitutions.currentClientId
        /* eslint-enable @typescript-eslint/camelcase */
      });

      if (injection === null) {
        continue;
      }

      templateScope = injection;
    }

    for (const { query, result, parameters } of extract(
      templateScope,
      scopes
    )) {
      // Apply dynamic substitutions to the description.
      let description = template.description;
      for (const [variableKey, variableValue] of Object.entries(parameters)) {
        const domain = new RegExp(`(\\(${escapeRegExp(variableKey)}\\))`, "g");
        description = description.replace(domain, variableValue);
      }

      explanationsByScope[result] = explanationsByScope[result] || [];
      explanationsByScope[result].push({
        scope: result,
        description: description,

        // TODO: I don't believe these are necessarily correct. However, they
github the-control-group / authx / packages / authx / src / util / humanizeScopes.ts View on Github external
substituteDescriptionMap(realm, variables),
      substituteDescriptionMap(context, variables),
      substituteDescriptionMap(action, variables)
    ];
  });

  const resultScopes: string[] = [];
  const resultText: string[] = [];

  // Create combinations.
  for (const [realm, context, action] of configs) {
    for (const [rk, rv] of Object.entries(realm)) {
      for (const [ck, cv] of Object.entries(context)) {
        for (const [ak, av] of Object.entries(action)) {
          // Test and extract variables from each scope.
          for (const { scope, parameters } of extract(
            `${rk}:${ck}:${ak}`,
            scopes
          )) {
            // Assemble the human readable text.
            let text = `${rv}: ${av.slice(0, 1).toUpperCase()}${av.slice(
              1
            )} ${cv}.`;

            // Apply dynamic substitutions to the text.
            for (const [variableKey, variableValue] of Object.entries(
              parameters
            )) {
              const pattern = new RegExp(
                `(?

@authx/scopes

This is a small collection of utility functions for AuthX scopes. These scopes are human-readable, fully OAuth2-compatible, and support both pattern matching and set algebra.

MIT
Latest version published 4 months ago

Package Health Score

73 / 100
Full package analysis