Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for AAD authentication via connection string #1436

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
v9.?.? (2022-??-??)
-------------------
[new] Add support for AAD authentication via connection string ((#1436)[https://github.com/tediousjs/node-mssql/pull/1436])

v9.0.1 (2022-08-18)
-------------------
[fix] fix regression in requestTimout option not accepting `0` as a value ([#1421](https://github.com/tediousjs/node-mssql/pull/1421))
Expand Down
26 changes: 25 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -571,12 +571,36 @@ Complete list of pool options can be found [here](https://github.com/vincit/tarn
In addition to configuration object there is an option to pass config as a connection string. Connection strings are supported.

##### Classic Connection String
###### Standard configuration using tedious driver

```
Server=localhost,1433;Database=database;User Id=username;Password=password;Encrypt=true
```
###### Standard configuration using msnodesqlv8 driver
```
Driver=msnodesqlv8;Server=(local)\INSTANCE;Database=database;UID=DOMAIN\username;PWD=password;Encrypt=true
```

##### Azure Active Directory Authentication Connection String

Several types of Azure Authentication are supported:
###### Authentication using Default Azure Credentials
```
Server=*.database.windows.net;Database=database;Authentication=azure-active-directory-default;ClientID=clientid;Encrypt=true
```
###### Authentication using Active Directory Password
```
Server=*.database.windows.net;Database=database;Authentication=azure-active-directory-password;User Id=username;Password=password;ClientID=clientid;TenantID=tenantid;Encrypt=true
```
###### Authentication using Access Token
```
Server=*.database.windows.net;Database=database;Authentication=azure-active-directory-access-token;Token=token;Encrypt=true
```
###### Authentication using Service Principal
```
Server=*.database.windows.net;Database=database;Authentication=azure-active-directory-service-principal-secret;ClientID=clientid;ClientSecret=clientsecret;TenantID=tenantid;Encrypt=true
```

## Drivers

### Tedious
Expand Down Expand Up @@ -2097,4 +2121,4 @@ to create new connections or not
[appveyor-url]: https://ci.appveyor.com/project/tediousjs/node-mssql

[tedious-url]: https://www.npmjs.com/package/tedious
[msnodesqlv8-url]: https://www.npmjs.com/package/msnodesqlv8
[msnodesqlv8-url]: https://www.npmjs.com/package/msnodesqlv8
25 changes: 24 additions & 1 deletion lib/base/connection-pool.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ class ConnectionPool extends EventEmitter {
case 'attachdbfilename':
break
case 'authentication':
Object.assign(config.authentication, {
type: value
})
break
case 'column encryption setting':
break
Expand All @@ -133,6 +136,16 @@ class ConnectionPool extends EventEmitter {
break
case 'context connection':
break
case 'client id':
Shin-Aska marked this conversation as resolved.
Show resolved Hide resolved
Object.assign(config.authentication.options, {
clientId: value
})
break
case 'client secret':
Object.assign(config.authentication.options, {
clientSecret: value
})
break
case 'current language':
Object.assign(config.options, {
language: value
Expand Down Expand Up @@ -222,6 +235,16 @@ class ConnectionPool extends EventEmitter {
break
case 'replication':
break
case 'tenant id':
Object.assign(config.authentication.options, {
tenantId: value
})
break
case 'token':
Object.assign(config.authentication.options, {
token: value
})
break
case 'transaction binding':
Object.assign(config.options, {
enableImplicitTransactions: value.toLowerCase() === 'implicit unbind'
Expand Down Expand Up @@ -278,7 +301,7 @@ class ConnectionPool extends EventEmitter {
break
}
return config
}, { options: {}, pool: {} })
}, { authentication: { options: {} }, options: {}, pool: {} })
}

/**
Expand Down