mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-07 17:27:40 +00:00
More on the account
This commit is contained in:
@@ -3,7 +3,6 @@ import { z } from "zod";
|
|||||||
|
|
||||||
import {
|
import {
|
||||||
CreateAcmeAccountResponseSchema,
|
CreateAcmeAccountResponseSchema,
|
||||||
CreateAcmeAccountSchema,
|
|
||||||
CreateAcmeOrderResponseSchema,
|
CreateAcmeOrderResponseSchema,
|
||||||
CreateAcmeOrderSchema,
|
CreateAcmeOrderSchema,
|
||||||
DeactivateAcmeAccountResponseSchema,
|
DeactivateAcmeAccountResponseSchema,
|
||||||
@@ -24,10 +23,10 @@ import {
|
|||||||
RespondToAcmeChallengeResponseSchema,
|
RespondToAcmeChallengeResponseSchema,
|
||||||
RespondToAcmeChallengeSchema
|
RespondToAcmeChallengeSchema
|
||||||
} from "@app/ee/services/pki-acme/pki-acme-schemas";
|
} from "@app/ee/services/pki-acme/pki-acme-schemas";
|
||||||
|
import { TCreateAcmeAccountPayload, TRawJwsPayload } from "@app/ee/services/pki-acme/pki-acme-types";
|
||||||
import { ApiDocsTags } from "@app/lib/api-docs";
|
import { ApiDocsTags } from "@app/lib/api-docs";
|
||||||
import { getConfig } from "@app/lib/config/env";
|
import { getConfig } from "@app/lib/config/env";
|
||||||
import { readLimit, writeLimit } from "@app/server/config/rateLimiter";
|
import { readLimit, writeLimit } from "@app/server/config/rateLimiter";
|
||||||
import { TRawJwsPayload } from "@app/ee/services/pki-acme/pki-acme-types";
|
|
||||||
|
|
||||||
export const registerPkiAcmeRouter = async (server: FastifyZodProvider) => {
|
export const registerPkiAcmeRouter = async (server: FastifyZodProvider) => {
|
||||||
const appCfg = getConfig();
|
const appCfg = getConfig();
|
||||||
@@ -112,28 +111,25 @@ export const registerPkiAcmeRouter = async (server: FastifyZodProvider) => {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
handler: async (req, res) => {
|
handler: async (req, res) => {
|
||||||
// TODO: check nonce here
|
const { payload, jwk } = await server.services.pkiAcme.validateCreateAcmeAccountJwsPayload(
|
||||||
const { payload, protectedHeader, jwk } = await server.services.pkiAcme.validateCreateAcmeAccountJwsPayload(
|
|
||||||
req.body as TRawJwsPayload
|
req.body as TRawJwsPayload
|
||||||
);
|
);
|
||||||
|
const { status, body, headers } = await server.services.pkiAcme.createAcmeAccount(
|
||||||
const account = await server.services.pkiAcme.createAcmeAccount(
|
|
||||||
req.params.profileId,
|
req.params.profileId,
|
||||||
jwk,
|
jwk,
|
||||||
payload as TCreateAcmeAccountPayload
|
payload as TCreateAcmeAccountPayload
|
||||||
);
|
);
|
||||||
// TODO: deal with existing account case here
|
// TODO: DRY
|
||||||
res.code(201);
|
res.code(status);
|
||||||
res.header(
|
for (const [key, value] of Object.entries(headers)) {
|
||||||
"Location",
|
res.header(key, value);
|
||||||
`${appCfg.SITE_URL}/api/v1/pki/acme/profiles/${req.params.profileId}/accounts/${account.accountUrl}`
|
}
|
||||||
);
|
|
||||||
|
|
||||||
// TODO: DRY
|
// TODO: DRY
|
||||||
const nonce = await server.services.pkiAcme.getAcmeNewNonce(req.params.profileId);
|
const nonce = await server.services.pkiAcme.getAcmeNewNonce(req.params.profileId);
|
||||||
res.header("Replay-Nonce", nonce);
|
res.header("Replay-Nonce", nonce);
|
||||||
res.header("Cache-Control", "no-store");
|
res.header("Cache-Control", "no-store");
|
||||||
return account;
|
return body;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
|
|
||||||
import { JWK } from "jose";
|
|
||||||
import {
|
import {
|
||||||
CreateAcmeAccountBodySchema,
|
CreateAcmeAccountBodySchema,
|
||||||
CreateAcmeAccountResponseSchema,
|
CreateAcmeAccountResponseSchema,
|
||||||
@@ -46,7 +45,7 @@ export type TJwsPayloadWithJwk = TJwsPayload & {
|
|||||||
export type TAcmeResponse<TPayload> = {
|
export type TAcmeResponse<TPayload> = {
|
||||||
status: number;
|
status: number;
|
||||||
headers: Record<string, string>;
|
headers: Record<string, string>;
|
||||||
payload: TPayload;
|
body: TPayload;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type TPkiAcmeServiceFactory = {
|
export type TPkiAcmeServiceFactory = {
|
||||||
|
|||||||
Reference in New Issue
Block a user