Skip to main content

Function: generateDatabaseCredential()

Function: generateDatabaseCredential()

function generateDatabaseCredential(workspaceClient: WorkspaceClient, request: GenerateDatabaseCredentialRequest): Promise<DatabaseCredential>;

Generate OAuth credentials for Postgres database connection using the proper Postgres API.

This generates a time-limited OAuth token (expires after 1 hour) that can be used as a password when connecting to Lakebase Postgres databases.

Parameters

ParameterTypeDescription
workspaceClientWorkspaceClientDatabricks workspace client for authentication
requestGenerateDatabaseCredentialRequestRequest parameters including endpoint path and optional UC claims

Returns

Promise<DatabaseCredential>

Database credentials with OAuth token and expiration time

See

https://docs.databricks.com/aws/en/oltp/projects/authentication

Examples

// Use the `name` field from the Databricks CLI output:
// `databricks postgres list-endpoints projects/{project-id}/branches/{branch-id}`
const credential = await generateDatabaseCredential(workspaceClient, {
  endpoint: "projects/{project-id}/branches/{branch-id}/endpoints/{endpoint-identifier}"
});

// Use credential.token as password
const conn = await pg.connect({
  host: "ep-abc123.database.us-east-1.databricks.com",
  user: "[email protected]",
  password: credential.token
});
// Use the `name` field from the Databricks CLI output:
// `databricks postgres list-endpoints projects/{project-id}/branches/{branch-id}`
const credential = await generateDatabaseCredential(workspaceClient, {
  endpoint: "projects/{project-id}/branches/{branch-id}/endpoints/{endpoint-identifier}",
  claims: [{
    permission_set: RequestedClaimsPermissionSet.READ_ONLY,
    resources: [{ table_name: "catalog.schema.users" }]
  }]
});

Databricks Developer Hub

Ready to ship your next agentic app in minutes?

Read docs