@azure/postgresql-auth package

인터페이스

ConfigureEntraAuthenticationOptions

Sequelize로 Entra ID 인증 설정 옵션.

EntraTokenProviderOptions

entraTokenProvider에 대한 옵션들.

SequelizeBeforeConnectHook

라이프사이클 훅을 beforeConnect 지원하는 Sequelize와 유사한 인스턴스를 나타내는 구조적 타입입니다. 이렇게 하면 패키지에 sequelize 대한 강한 의존성을 피하면서도 타입 안전성을 유지할 수 있습니다.

함수

configureEntraAuthentication(SequelizeBeforeConnectHook, TokenCredential, ConfigureEntraAuthenticationOptions)

Sequelize 인스턴스를 Entra ID 인증을 사용하도록 설정합니다.

이 함수는 Sequelize 인스턴스에 beforeConnect 훅을 등록하여 새로운 데이터베이스 연결 전에 자동으로 Entra ID 토큰을 획득합니다. 훅은 JWT 토큰 청구upn (또는 appid)에서 사용자 이름을 추출하여 연결 설정에 사용자 이름과 비밀번호를 모두 설정합니다.

예제

import { DefaultAzureCredential } from "@azure/identity";

const { configureEntraAuthentication } = await import("@azure/postgresql-auth");
const { Sequelize } = await import("sequelize");
const sequelize = new Sequelize({
  dialect: "postgres",
  host: process.env.PGHOST,
  port: Number(process.env.PGPORT || 5432),
  database: process.env.PGDATABASE,
});
const credential = new DefaultAzureCredential();
configureEntraAuthentication(sequelize, credential);
await sequelize.authenticate();
entraTokenProvider(TokenCredential, EntraTokenProviderOptions)

PostgreSQL 비밀번호로 사용할 수 있는 Entra ID 접근 토큰을 획득하는 비밀번호 제공자 함수를 생성합니다.

이 함수는 호출 시 Azure Database for PostgreSQL 범위를 사용하여 제공된 <xref:TokenCredential>에서 토큰을 요청하는 콜백을 반환합니다. 반환된 콜백은 , , pg.Pool또는 유사한 PostgreSQL 클라이언트 구성의 pg.Client옵션으로 password 직접 전달될 수 있습니다.

예제

import { DefaultAzureCredential } from "@azure/identity";

const { entraTokenProvider } = await import("@azure/postgresql-auth");
const pg = await import("pg");
const credential = new DefaultAzureCredential();
const pool = new pg.Pool({
  host: process.env.PGHOST,
  port: Number(process.env.PGPORT || 5432),
  database: process.env.PGDATABASE,
  user: process.env.PGUSER,
  password: entraTokenProvider(credential),
  ssl: { rejectUnauthorized: true },
});

함수 세부 정보

configureEntraAuthentication(SequelizeBeforeConnectHook, TokenCredential, ConfigureEntraAuthenticationOptions)

Sequelize 인스턴스를 Entra ID 인증을 사용하도록 설정합니다.

이 함수는 Sequelize 인스턴스에 beforeConnect 훅을 등록하여 새로운 데이터베이스 연결 전에 자동으로 Entra ID 토큰을 획득합니다. 훅은 JWT 토큰 청구upn (또는 appid)에서 사용자 이름을 추출하여 연결 설정에 사용자 이름과 비밀번호를 모두 설정합니다.

예제

import { DefaultAzureCredential } from "@azure/identity";

const { configureEntraAuthentication } = await import("@azure/postgresql-auth");
const { Sequelize } = await import("sequelize");
const sequelize = new Sequelize({
  dialect: "postgres",
  host: process.env.PGHOST,
  port: Number(process.env.PGPORT || 5432),
  database: process.env.PGDATABASE,
});
const credential = new DefaultAzureCredential();
configureEntraAuthentication(sequelize, credential);
await sequelize.authenticate();
function configureEntraAuthentication(sequelizeInstance: SequelizeBeforeConnectHook, credential: TokenCredential, options?: ConfigureEntraAuthenticationOptions)

매개 변수

sequelizeInstance
SequelizeBeforeConnectHook

Sequelize 인스턴스를 구성해야 합니다. 라이프사이클 훅을 beforeConnect 지원해야 합니다.

credential
TokenCredential

토큰을 획득하는 데 사용되는 Azure <xref:TokenCredential>(예: DefaultAzureCredential).

options
ConfigureEntraAuthenticationOptions

인증 동작에 대한 선택적 설정입니다.

entraTokenProvider(TokenCredential, EntraTokenProviderOptions)

PostgreSQL 비밀번호로 사용할 수 있는 Entra ID 접근 토큰을 획득하는 비밀번호 제공자 함수를 생성합니다.

이 함수는 호출 시 Azure Database for PostgreSQL 범위를 사용하여 제공된 <xref:TokenCredential>에서 토큰을 요청하는 콜백을 반환합니다. 반환된 콜백은 , , pg.Pool또는 유사한 PostgreSQL 클라이언트 구성의 pg.Client옵션으로 password 직접 전달될 수 있습니다.

예제

import { DefaultAzureCredential } from "@azure/identity";

const { entraTokenProvider } = await import("@azure/postgresql-auth");
const pg = await import("pg");
const credential = new DefaultAzureCredential();
const pool = new pg.Pool({
  host: process.env.PGHOST,
  port: Number(process.env.PGPORT || 5432),
  database: process.env.PGDATABASE,
  user: process.env.PGUSER,
  password: entraTokenProvider(credential),
  ssl: { rejectUnauthorized: true },
});
function entraTokenProvider(credential: TokenCredential, options?: EntraTokenProviderOptions): () => Promise<string>

매개 변수

credential
TokenCredential

토큰을 획득하는 데 사용되는 Azure <xref:TokenCredential>(예: DefaultAzureCredential).

options
EntraTokenProviderOptions

맞춤형 OAuth 스코프와 같은 선택적 설정도 있습니다.

반품

() => Promise<string>

호출 시 접근 토큰 문자열로 해석되는 약속을 반환하는 함수입니다.