Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const authorizationId = v4();
const values = {
currentAuthorizationId: authorizationId,
currentUserId: credential.userId,
currentGrantId: null,
currentClientId: null
};
// Make sure the user can create new authorizations.
const user = await User.read(tx, credential.userId);
if (
!isSuperset(
await user.access(tx, values),
createV2AuthXScope(
realm,
{
type: "authorization",
authorizationId: "",
grantId: "",
clientId: "",
userId: user.id
},
{
basic: "*",
scopes: "*",
secrets: "*"
}
)
)
) {
const authorizationId = v4();
const values = {
currentAuthorizationId: authorizationId,
currentUserId: credential.userId,
currentGrantId: null,
currentClientId: null
};
// Make sure the user can create new authorizations.
const user = await User.read(tx, credential.userId);
if (
!isSuperset(
await user.access(tx, values),
createV2AuthXScope(
realm,
{
type: "authorization",
authorizationId: "",
grantId: "",
clientId: "",
userId: user.id
},
{
basic: "*",
scopes: "*",
secrets: "*"
}
)
)
) {
throw new AuthenticationError("No such credential exists.");
}
const values = {
currentAuthorizationId: authorizationId,
currentUserId: credential.userId,
currentGrantId: null,
currentClientId: null
};
// Make sure the user can create new authorizations.
const user = await User.read(tx, credential.userId);
if (
!isSuperset(
await user.access(tx, values),
createV2AuthXScope(
realm,
{
type: "authorization",
authorizationId: "",
grantId: "",
clientId: "",
userId: user.id
},
{
basic: "*",
scopes: "*",
secrets: "*"
}
)
)
) {
const tx = await pool.connect();
try {
const values = {
currentAuthorizationId: a.id,
currentUserId: a.userId,
currentGrantId: a.grantId,
currentClientId: (await a.grant(tx))?.clientId ?? null
};
// The user cannot create a credential for this user and authority.
if (
!(await a.can(
tx,
values,
createV2AuthXScope(
realm,
{
type: "credential",
credentialId: "",
authorityId: input.authorityId,
userId: input.userId
},
{
basic: "*",
details: "*"
}
)
))
) {
throw new ForbiddenError(
"You do not have permission to create this credential."
)
))
) {
throw new ForbiddenError(
"You do not have permission to create this credential."
);
}
// The user doesn't have permission to change the credentials of all
// users, so in order to save this credential, she must prove control of
// the account with the OpenID provider.
if (
!(await a.can(
tx,
values,
createV2AuthXScope(
realm,
{
type: "credential",
credentialId: "",
authorityId: input.authorityId,
userId: "*"
},
{
basic: "*",
details: "*"
}
)
)) &&
!input.code
) {
throw new ForbiddenError(
}
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 (
!(await a.can(
tx,
values,
createV2AuthXScope(
realm,
{
type: "authority",
authorityId: ""
},
{
basic: "*",
details: "*"
}
)
))
) {
throw new ForbiddenError(
"You do not have permission to create an authority."
);
}
}
),
createV2AuthXScope(
realm,
{
type: "credential",
authorityId: credential.authorityId,
credentialId: id,
userId: credential.userId
},
{
basic: "w",
details: ""
}
),
createV2AuthXScope(
realm,
{
type: "credential",
authorityId: credential.authorityId,
credentialId: id,
userId: credential.userId
},
{
basic: "w",
details: "w"
}
),
createV2AuthXScope(
realm,
{
type: "credential",
}
),
createV2AuthXScope(
realm,
{
type: "credential",
authorityId: credential.authorityId,
credentialId: id,
userId: credential.userId
},
{
basic: "r",
details: "*"
}
),
createV2AuthXScope(
realm,
{
type: "credential",
authorityId: credential.authorityId,
credentialId: id,
userId: credential.userId
},
{
basic: "w",
details: ""
}
),
createV2AuthXScope(
realm,
{
type: "credential",
}
);
const possibleAdministrationScopes = [
createV2AuthXScope(
realm,
{
type: "authority",
authorityId: id
},
{
basic: "r",
details: ""
}
),
createV2AuthXScope(
realm,
{
type: "authority",
authorityId: id
},
{
basic: "r",
details: "r"
}
),
createV2AuthXScope(
realm,
{
type: "authority",
authorityId: id
},
}
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 (
!(await a.can(
tx,
values,
createV2AuthXScope(
realm,
{
type: "authority",
authorityId: ""
},
{
basic: "*",
details: "*"
}
)
))
) {
throw new ForbiddenError(
"You do not have permission to create an authority."
);
}