Implement getting auth

This commit is contained in:
Fang-Pen Lin
2025-10-30 16:59:21 -07:00
parent 1d19fb4788
commit e2799b934a
2 changed files with 16 additions and 14 deletions

View File

@@ -17,7 +17,7 @@ export const pkiAcmeAuthDALFactory = (db: TDbClient) => {
.select(
selectAllTableCols(TableName.PkiAcmeAuth),
db.ref("id").withSchema(TableName.PkiAcmeChallenge).as("challengeId"),
db.ref("token").withSchema(TableName.PkiAcmeChallenge).as("challengeToken"),
db.ref("type").withSchema(TableName.PkiAcmeChallenge).as("challengeType"),
db.ref("status").withSchema(TableName.PkiAcmeChallenge).as("challengeStatus")
)
.where(`${TableName.PkiAcmeAuth}.accountId`, accountId)
@@ -34,9 +34,9 @@ export const pkiAcmeAuthDALFactory = (db: TDbClient) => {
{
key: "challengeId",
label: "challenges" as const,
mapper: ({ challengeId, challengeToken, challengeStatus }) => ({
mapper: ({ challengeId, challengeType, challengeStatus }) => ({
id: challengeId,
token: challengeToken,
type: challengeType,
status: challengeStatus
})
}

View File

@@ -49,12 +49,13 @@ import {
TRawJwsPayload,
TRespondToAcmeChallengeResponse
} from "./pki-acme-types";
import { TPkiAcmeChallenges } from "@app/db/schemas";
type TPkiAcmeServiceFactoryDep = {
certificateProfileDAL: Pick<TCertificateProfileDALFactory, "findById">;
acmeAccountDAL: Pick<TPkiAcmeAccountDALFactory, "findByProjectIdAndAccountId" | "findByPublicKey" | "create">;
acmeOrderDAL: Pick<TPkiAcmeOrderDALFactory, "create" | "transaction" | "findByAccountAndOrderIdWithAuthorizations">;
acmeAuthDAL: Pick<TPkiAcmeAuthDALFactory, "create" | "findById">;
acmeAuthDAL: Pick<TPkiAcmeAuthDALFactory, "create" | "findByAccountIdAndAuthIdWithChallenges">;
acmeOrderAuthDAL: Pick<TPkiAcmeOrderAuthDALFactory, "insertMany">;
};
@@ -514,8 +515,8 @@ export const pkiAcmeServiceFactory = ({
accountId: string;
authzId: string;
}): Promise<TAcmeResponse<TGetAcmeAuthorizationResponse>> => {
const auth = await acmeAuthDAL.findById(authzId);
if (!auth || auth.accountId !== accountId) {
const auth = await acmeAuthDAL.findByAccountIdAndAuthIdWithChallenges(accountId, authzId);
if (!auth) {
throw new NotFoundError({ message: "ACME authorization not found" });
}
return {
@@ -527,15 +528,16 @@ export const pkiAcmeServiceFactory = ({
type: auth.identifierType,
value: auth.identifierValue
},
challenges: [
// TODO: fixme
{
type: "http-01",
url: buildUrl(`/api/v1/pki/acme/profiles/${profileId}/authorizations/${authzId}/challenges/http-01`),
status: "pending",
challenges: auth.challenges.map((challenge: TPkiAcmeChallenges) => {
return {
type: challenge.type,
url: buildUrl(
`/api/v1/pki/acme/profiles/${profileId}/authorizations/${authzId}/challenges/${challenge.id}`
),
status: challenge.status,
token: auth.token
}
]
};
})
},
headers: {
Location: buildUrl(`/api/v1/pki/acme/profiles/${profileId}/authorizations/${authzId}`)