Nestjs + TypeORM Mssql connection with managed identity or passwordless connection

418 views Asked by At

How to connect to mssql database using managed identity with TypeORM ? Currently, I'm creating the connection as below:

createTypeOrmOptions(): TypeOrmModuleOptions {
    return {
    name: 'default',
    type: 'mssql',
    host: this.configService.get<string>("DATABASE_HOST"),
    port: Number(this.configService.get<number>("DATABASE_PORT")) ,
    username: this.configService.get<string>("DATABASE_USERNAME"),
    password: this.configService.get<string>("DATABASE_PASSWORD"),
    database: this.configService.get<string>("DATABASE_DB"),
    synchronize: false,
    logging: true, 
    ...}}

I'm looking something similar to this https://learn.microsoft.com/en-us/azure/azure-sql/database/connect-query-nodejs?view=azuresql-mi&tabs=macos Use Azure App Service Managed Identity to connect to the SQL database

const config = {
    server: process.env["db_server"],
    port: process.env["db_port"],
    database: process.env["db_database"],
    authentication: {
    type: 'azure-active-directory-msi-app-service'
    },
    options: {
    encrypt: true
    }
    }

Or is there a way to pass the database connection object while intializing Repositories ? Thankyou for your time!

0

There are 0 answers