How to use the @authx/authx.Role.write function in @authx/authx

To help you get started, we’ve selected a few @authx/authx 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 / tools / src / lib / bootstrap.ts View on Github external
]),
    tx.query("INSERT INTO authx.credential (id) VALUES ($1)", [
      credential.data.id
    ]),
    tx.query("INSERT INTO authx.role (id) VALUES ($1)", [role.data.id]),
    tx.query("INSERT INTO authx.authorization (id) VALUES ($1)", [
      authorization.data.id
    ])
  ]);

  // insert the records
  await Promise.all([
    User.write(tx, user.data, user.metadata),
    PasswordAuthority.write(tx, authority.data, authority.metadata),
    PasswordCredential.write(tx, credential.data, credential.metadata),
    Role.write(tx, role.data, role.metadata),
    Authorization.write(tx, authorization.data, authorization.metadata)
  ]);
}
github the-control-group / authx / packages / strategy-password / src / server / graphql / mutation / createPasswordAuthorities.ts View on Github external
for (const { roleId, scopes } of input.administration) {
            const role = await Role.read(tx, roleId, { forUpdate: true });

            if (
              !role.isAccessibleBy(realm, a, tx, {
                basic: "w",
                scopes: "w",
                users: ""
              })
            ) {
              throw new ForbiddenError(
                `You do not have permission to modify the scopes of role ${roleId}.`
              );
            }

            await Role.write(
              tx,
              {
                ...role,
                scopes: simplify([
                  ...role.scopes,
                  ...possibleAdministrationScopes.filter(possible =>
                    isSuperset(scopes, possible)
                  )
                ])
              },
              {
                recordId: v4(),
                createdByAuthorizationId: a.id,
                createdAt: new Date()
              }
            );
github the-control-group / authx / packages / tools / src / lib / fixture / role.ts View on Github external
insert: (tx: PoolClient) =>
      Role.write(
        tx,
        {
          id: "08e2b39e-ba9f-4de2-8dca-aef460793566",
          enabled: true,
          name: "HR",
          description: "The best; the worst.",
          userIds: ["306eabbb-cc2b-4f88-be19-4bb6ec98e5c3"],
          scopes: ["authx:user.*:**"]
        },
        {
          recordId: "f94c5316-ce81-46e6-932a-0ac2c8fc886b",
          createdByAuthorizationId: "f0e54748-c7bb-4724-ad8b-7dabb66aafa9",
          createdAt: new Date("2019-03-06T21:07:59.814Z")
        }
      )
  }
github the-control-group / authx / packages / strategy-email / src / server / graphql / mutation / createEmailAuthorities.ts View on Github external
for (const { roleId, scopes } of input.administration) {
            const role = await Role.read(tx, roleId, { forUpdate: true });

            if (
              !role.isAccessibleBy(realm, a, tx, {
                basic: "w",
                scopes: "w",
                users: ""
              })
            ) {
              throw new ForbiddenError(
                `You do not have permission to modify the scopes of role ${roleId}.`
              );
            }

            await Role.write(
              tx,
              {
                ...role,
                scopes: simplify([
                  ...role.scopes,
                  ...possibleAdministrationScopes.filter(possible =>
                    isSuperset(scopes, possible)
                  )
                ])
              },
              {
                recordId: v4(),
                createdByAuthorizationId: a.id,
                createdAt: new Date()
              }
            );
github the-control-group / authx / packages / strategy-password / src / server / graphql / mutation / createPasswordCredentials.ts View on Github external
for (const { roleId, scopes } of input.administration) {
            const role = await Role.read(tx, roleId, { forUpdate: true });

            if (
              !role.isAccessibleBy(realm, a, tx, {
                basic: "w",
                scopes: "w",
                users: ""
              })
            ) {
              throw new ForbiddenError(
                `You do not have permission to modify the scopes of role ${roleId}.`
              );
            }

            await Role.write(
              tx,
              {
                ...role,
                scopes: simplify([
                  ...role.scopes,
                  ...possibleAdministrationScopes.filter(possible =>
                    isSuperset(scopes, possible)
                  )
                ])
              },
              {
                recordId: v4(),
                createdByAuthorizationId: a.id,
                createdAt: new Date()
              }
            );
github the-control-group / authx / packages / strategy-email / src / server / graphql / mutation / createEmailCredentials.ts View on Github external
for (const { roleId, scopes } of input.administration) {
          const role = await Role.read(tx, roleId, { forUpdate: true });

          if (
            !role.isAccessibleBy(realm, a, tx, {
              basic: "w",
              scopes: "w",
              users: ""
            })
          ) {
            throw new ForbiddenError(
              `You do not have permission to modify the scopes of role ${roleId}.`
            );
          }

          await Role.write(
            tx,
            {
              ...role,
              scopes: simplify([
                ...role.scopes,
                ...possibleAdministrationScopes.filter(possible =>
                  isSuperset(scopes, possible)
                )
              ])
            },
            {
              recordId: v4(),
              createdByAuthorizationId: a.id,
              createdAt: new Date()
            }
          );
github the-control-group / authx / packages / strategy-openid / src / server / graphql / mutation / createOpenIdAuthorities.ts View on Github external
for (const { roleId, scopes } of input.administration) {
            const role = await Role.read(tx, roleId, { forUpdate: true });

            if (
              !role.isAccessibleBy(realm, a, tx, {
                basic: "w",
                scopes: "w",
                users: ""
              })
            ) {
              throw new ForbiddenError(
                `You do not have permission to modify the scopes of role ${roleId}.`
              );
            }

            await Role.write(
              tx,
              {
                ...role,
                scopes: simplify([
                  ...role.scopes,
                  ...possibleAdministrationScopes.filter(possible =>
                    isSuperset(scopes, possible)
                  )
                ])
              },
              {
                recordId: v4(),
                createdByAuthorizationId: a.id,
                createdAt: new Date()
              }
            );
github the-control-group / authx / packages / strategy-openid / src / server / graphql / mutation / createOpenIdCredentials.ts View on Github external
for (const { roleId, scopes } of input.administration) {
          const role = await Role.read(tx, roleId, { forUpdate: true });

          if (
            !role.isAccessibleBy(realm, a, tx, {
              basic: "w",
              scopes: "w",
              users: ""
            })
          ) {
            throw new ForbiddenError(
              `You do not have permission to modify the scopes of role ${roleId}.`
            );
          }

          await Role.write(
            tx,
            {
              ...role,
              scopes: simplify([
                ...role.scopes,
                ...possibleAdministrationScopes.filter(possible =>
                  isSuperset(scopes, possible)
                )
              ])
            },
            {
              recordId: v4(),
              createdByAuthorizationId: a.id,
              createdAt: new Date()
            }
          );
github the-control-group / authx / packages / strategy-openid / src / server / graphql / mutation / authenticateOpenId.ts View on Github external
await roles.map(role =>
            Role.write(
              tx,
              {
                ...role,
                userIds: [...role.userIds, user.id]
              },
              {
                recordId: v4(),
                createdByAuthorizationId: authorizationId,
                createdAt: new Date()
              }
            )
          );