How to use the @authx/scopes.isValidScopeLiteral 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 / strategy-password / src / server / graphql / mutation / createPasswordCredentials.ts View on Github external
// Validate `userId`.
      if (!validateIdFormat(input.userId)) {
        throw new ValidationError("The provided `userId` is an invalid ID.");
      }

      // Validate `administration`.
      for (const { roleId, scopes } of input.administration) {
        if (!validateIdFormat(roleId)) {
          throw new ValidationError(
            "The provided `administration` list contains a `roleId` that is an invalid ID."
          );
        }

        for (const scope of scopes) {
          if (!isValidScopeLiteral(scope)) {
            throw new ValidationError(
              "The provided `administration` list contains a `scopes` list with an invalid scope."
            );
          }
        }
      }

      const tx = await pool.connect();
      try {
        const values = {
          currentAuthorizationId: a.id,
          currentUserId: a.userId,
          currentGrantId: a.grantId,
          currentClientId: (await a.grant(tx))?.clientId ?? null
        };
github the-control-group / authx / packages / strategy-openid / src / server / graphql / mutation / createOpenIdAuthorities.ts View on Github external
return args.authorities.map(async input => {
      // Validate `id`.
      if (typeof input.id === "string" && !validateIdFormat(input.id)) {
        throw new ValidationError("The provided `id` is an invalid ID.");
      }

      // Validate `administration`.
      for (const { roleId, scopes } of input.administration) {
        if (!validateIdFormat(roleId)) {
          throw new ValidationError(
            "The provided `administration` list contains a `roleId` that is an invalid ID."
          );
        }

        for (const scope of scopes) {
          if (!isValidScopeLiteral(scope)) {
            throw new ValidationError(
              "The provided `administration` list contains a `scopes` list with an invalid scope."
            );
          }
        }
      }

      const tx = await pool.connect();
      try {
        const values = {
          currentAuthorizationId: a.id,
          currentUserId: a.userId,
          currentGrantId: a.grantId,
          currentClientId: (await a.grant(tx))?.clientId ?? null
        };
github the-control-group / authx / packages / strategy-email / src / server / graphql / mutation / createEmailAuthorities.ts View on Github external
return args.authorities.map(async input => {
      // Validate `id`.
      if (typeof input.id === "string" && !validateIdFormat(input.id)) {
        throw new ValidationError("The provided `id` is an invalid ID.");
      }

      // Validate `administration`.
      for (const { roleId, scopes } of input.administration) {
        if (!validateIdFormat(roleId)) {
          throw new ValidationError(
            "The provided `administration` list contains a `roleId` that is an invalid ID."
          );
        }

        for (const scope of scopes) {
          if (!isValidScopeLiteral(scope)) {
            throw new ValidationError(
              "The provided `administration` list contains a `scopes` list with an invalid scope."
            );
          }
        }
      }

      const tx = await pool.connect();
      try {
        const values = {
          currentAuthorizationId: a.id,
          currentUserId: a.userId,
          currentGrantId: a.grantId,
          currentClientId: (await a.grant(tx))?.clientId ?? null
        };
github the-control-group / authx / packages / strategy-password / src / server / graphql / mutation / createPasswordAuthorities.ts View on Github external
return args.authorities.map(async input => {
      // Validate `id`.
      if (typeof input.id === "string" && !validateIdFormat(input.id)) {
        throw new ValidationError("The provided `id` is an invalid ID.");
      }

      // Validate `administration`.
      for (const { roleId, scopes } of input.administration) {
        if (!validateIdFormat(roleId)) {
          throw new ValidationError(
            "The provided `administration` list contains a `roleId` that is an invalid ID."
          );
        }

        for (const scope of scopes) {
          if (!isValidScopeLiteral(scope)) {
            throw new ValidationError(
              "The provided `administration` list contains a `scopes` list with an invalid scope."
            );
          }
        }
      }

      const tx = await pool.connect();
      try {
        const values = {
          currentAuthorizationId: a.id,
          currentUserId: a.userId,
          currentGrantId: a.grantId,
          currentClientId: (await a.grant(tx))?.clientId ?? null
        };
github the-control-group / authx / packages / strategy-openid / src / server / graphql / mutation / createOpenIdCredentials.ts View on Github external
// Validate `userId`.
      if (!validateIdFormat(input.userId)) {
        throw new ValidationError("The provided `userId` is an invalid ID.");
      }

      // Validate `administration`.
      for (const { roleId, scopes } of input.administration) {
        if (!validateIdFormat(roleId)) {
          throw new ValidationError(
            "The provided `administration` list contains a `roleId` that is an invalid ID."
          );
        }

        for (const scope of scopes) {
          if (!isValidScopeLiteral(scope)) {
            throw new ValidationError(
              "The provided `administration` list contains a `scopes` list with an invalid scope."
            );
          }
        }
      }

      const tx = await pool.connect();
      try {
        await tx.query("BEGIN DEFERRABLE");

        const values = {
          currentAuthorizationId: a.id,
          currentUserId: a.userId,
          currentGrantId: a.grantId,
          currentClientId: (await a.grant(tx))?.clientId ?? null
github the-control-group / authx / packages / strategy-email / src / server / graphql / mutation / createEmailCredentials.ts View on Github external
// Validate `userId`.
      if (!validateIdFormat(input.userId)) {
        throw new ValidationError("The provided `userId` is an invalid ID.");
      }

      // Validate `administration`.
      for (const { roleId, scopes } of input.administration) {
        if (!validateIdFormat(roleId)) {
          throw new ValidationError(
            "The provided `administration` list contains a `roleId` that is an invalid ID."
          );
        }

        for (const scope of scopes) {
          if (!isValidScopeLiteral(scope)) {
            throw new ValidationError(
              "The provided `administration` list contains a `scopes` list with an invalid scope."
            );
          }
        }
      }

      const tx = await pool.connect();
      try {
        await tx.query("BEGIN DEFERRABLE");

        const values = {
          currentAuthorizationId: a.id,
          currentUserId: a.userId,
          currentGrantId: a.grantId,
          currentClientId: (await a.grant(tx))?.clientId ?? null
github the-control-group / authx / packages / authx / src / graphql / GraphQLScope.ts View on Github external
parseLiteral(
    valueNode: ValueNode,
    variables?: null | { [key: string]: any }
  ) {
    const string = GraphQLString.parseLiteral(valueNode, variables);
    if (!isValidScopeLiteral(string)) {
      throw new GraphQLError(`Scope cannot represent value: ${string}`);
    }

    return string;
  }
});
github the-control-group / authx / packages / authx / src / graphql / GraphQLScope.ts View on Github external
parseValue: (value: unknown) => {
    const string = GraphQLString.parseValue(value);
    if (!isValidScopeLiteral(string)) {
      throw new GraphQLError(`Scope cannot represent value: ${string}`);
    }

    return string;
  },
  parseLiteral(
github the-control-group / authx / packages / authx / src / graphql / GraphQLScope.ts View on Github external
serialize: (value: unknown) => {
    const string: string = GraphQLString.serialize(value);
    if (!isValidScopeLiteral(string)) {
      throw new GraphQLError(`Scope cannot represent value: ${string}`);
    }

    return string;
  },
  parseValue: (value: unknown) => {

@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