Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return args.credentials.map(async input => {
// Validate `id`.
if (typeof input.id === "string" && !validateIdFormat(input.id)) {
throw new ValidationError("The provided `id` is an invalid ID.");
}
// Validate `authorityId`.
if (!validateIdFormat(input.authorityId)) {
throw new ValidationError(
"The provided `authorityId` is an invalid ID."
);
}
// 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."
);
}
// 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
};
return args.credentials.map(async input => {
// Validate `id`.
if (typeof input.id === "string" && !validateIdFormat(input.id)) {
throw new ValidationError("The provided `id` is an invalid ID.");
}
// Validate `authorityId`.
if (!validateIdFormat(input.authorityId)) {
throw new ValidationError(
"The provided `authorityId` is an invalid ID."
);
}
// 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."
);
}
return args.credentials.map(async input => {
// Validate `id`.
if (typeof input.id === "string" && !validateIdFormat(input.id)) {
throw new ValidationError("The provided `id` is an invalid ID.");
}
// Validate `authorityId`.
if (!validateIdFormat(input.authorityId)) {
throw new ValidationError(
"The provided `authorityId` is an invalid ID."
);
}
// 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) {
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."
);
}
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."
);
}
return args.authorities.map(async input => {
// Validate `id`.
if (!validateIdFormat(input.id)) {
throw new ValidationError("The provided `id` is an invalid ID.");
}
const tx = await pool.connect();
try {
await tx.query("BEGIN DEFERRABLE");
const before = await Authority.read(tx, input.id, authorityMap, {
forUpdate: true
});
if (!(before instanceof EmailAuthority)) {
throw new NotFoundError(
"The authority uses a strategy other than email."
);
}
// 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
};
// 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
};
if (
throw new NotFoundError(
"The authority uses a strategy other than openid."
);
}
if (!input.code && !input.subject) {
throw new ValidationError(
"Either a `code` or `subject` must be provided."
);
}
if (
typeof input.code === "string" &&
typeof input.subject === "string"
) {
throw new ValidationError(
"Only one of `code` or `subject` may be provided."
);
}
let subject = input.subject;
// Exchange the authorization code for an ID token.
if (!subject && input.code) {
const requestBody = new FormData();
requestBody.append("grant_type", "authorization_code");
requestBody.append("client_id", authority.details.clientId);
requestBody.append("client_secret", authority.details.clientSecret);
requestBody.append("code", input.code);
requestBody.append(
"redirect_uri",
`${base}?authorityId=${input.authorityId}`