mirror of
https://github.com/zitadel/zitadel.git
synced 2025-12-13 01:22:14 +00:00
feat: add @zitadel/node pkg
This commit is contained in:
35
packages/zitadel-node/src/index.ts
Normal file
35
packages/zitadel-node/src/index.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
import { NewAuthorizationBearerInterceptor } from "@zitadel/client2";
|
||||
import {
|
||||
createGrpcWebTransport,
|
||||
GrpcTransportOptions,
|
||||
} from "@connectrpc/connect-node";
|
||||
import { importPKCS8, SignJWT } from "jose";
|
||||
|
||||
/**
|
||||
* Create a server transport with the given token and configuration options.
|
||||
* @param token
|
||||
* @param opts
|
||||
*/
|
||||
export function createServerTransport(
|
||||
token: string,
|
||||
opts: GrpcTransportOptions,
|
||||
) {
|
||||
return createGrpcWebTransport({
|
||||
...opts,
|
||||
interceptors: [
|
||||
...(opts.interceptors || []),
|
||||
NewAuthorizationBearerInterceptor(token),
|
||||
],
|
||||
});
|
||||
}
|
||||
|
||||
export async function newSystemToken() {
|
||||
return await new SignJWT({})
|
||||
.setProtectedHeader({ alg: "RS256" })
|
||||
.setIssuedAt()
|
||||
.setExpirationTime("1h")
|
||||
.setIssuer(process.env.ZITADEL_SYSTEM_API_USERID ?? "")
|
||||
.setSubject(process.env.ZITADEL_SYSTEM_API_USERID ?? "")
|
||||
.setAudience(process.env.ZITADEL_ISSUER ?? "")
|
||||
.sign(await importPKCS8(process.env.ZITADEL_SYSTEM_API_KEY ?? "", "RS256"));
|
||||
}
|
||||
Reference in New Issue
Block a user