Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return resolve(
left(
ResponseErrorForbiddenAnonymousUser
)
);
}
const userId = errorOrUserId.value;
const subscriptionId = errorOrSubscriptionId.value;
// to correctly process the request, we must associate the correct
// authorizations to the user that made the request; to do so, we
// need to extract the groups associated to the authenticated user
// from the x-user-groups header, generated by the Azure API Management
// proxy.
const errorOrGroupsHeader = NonEmptyString.decode(
request.header("x-user-groups")
);
// extract the groups from the header
const maybeGroups = errorOrGroupsHeader.map(getGroupsFromHeader);
if (isLeft(maybeGroups) || maybeGroups.value.size === 0) {
// the user as no valid authorization groups assigned
return resolve(
left<
| IResponseErrorForbiddenNotAuthorized
| IResponseErrorForbiddenAnonymousUser
| IResponseErrorForbiddenNoAuthorizationGroups,
IAzureApiAuthorization
>(ResponseErrorForbiddenNoAuthorizationGroups)
);
new Promise(resolve => {
// get Azure userId and subscriptionId from the headers
// these headers get added by the Azure API Manager gateway
const errorOrUserId = NonEmptyString.decode(request.header("x-user-id"));
const errorOrSubscriptionId = NonEmptyString.decode(
request.header("x-subscription-id")
);
if (isLeft(errorOrUserId) || isLeft(errorOrSubscriptionId)) {
// we cannot proceed unless we cannot associate the request to a
// valid user and a subscription
return resolve(
left(
ResponseErrorForbiddenAnonymousUser
)
);
}
const userId = errorOrUserId.value;
new Promise(resolve => {
// get Azure userId and subscriptionId from the headers
// these headers get added by the Azure API Manager gateway
const errorOrUserId = NonEmptyString.decode(request.header("x-user-id"));
const errorOrSubscriptionId = NonEmptyString.decode(
request.header("x-subscription-id")
);
if (isLeft(errorOrUserId) || isLeft(errorOrSubscriptionId)) {
// we cannot proceed unless we cannot associate the request to a
// valid user and a subscription
return resolve(
left(
ResponseErrorForbiddenAnonymousUser
)
);
}
const userId = errorOrUserId.value;
const subscriptionId = errorOrSubscriptionId.value;
return async request => {
const errorOrUserEmail = EmailString.decode(
request.header(HEADER_USER_EMAIL)
);
if (isLeft(errorOrUserEmail)) {
return left, IAzureUserAttributes>(
ResponseErrorInternal(
`Missing, empty or invalid ${HEADER_USER_EMAIL} header`
)
);
}
const userEmail = errorOrUserEmail.value;
const errorOrUserSubscriptionId = NonEmptyString.decode(
request.header(HEADER_USER_SUBSCRIPTION_KEY)
);
if (isLeft(errorOrUserSubscriptionId)) {
return left, IAzureUserAttributes>(
ResponseErrorInternal(
`Missing or empty ${HEADER_USER_SUBSCRIPTION_KEY} header`
)
);
}
const subscriptionId = errorOrUserSubscriptionId.value;
// serviceId equals subscriptionId
const errorOrMaybeService = await serviceModel.findOneByServiceId(
subscriptionId
export function makeSenderServiceId(
recipientFiscalCode: FiscalCode,
serviceId: ServiceId
): NonEmptyString {
return NonEmptyString.decode(
`${recipientFiscalCode}:${serviceId}`
).getOrElseL(() => {
throw new Error("Invalid sender service id");
});
}
export function getRequiredStringEnv(k: string): NonEmptyString {
const maybeValue = NonEmptyString.decode(process.env[k]);
if (isLeft(maybeValue)) {
throw new Error(`${k} must be defined and non-empty`);
}
return maybeValue.value;
}