Skip to content

Commit

Permalink
Merge pull request #1436 from Shin-Aska/feature/aad-integration-conn-…
Browse files Browse the repository at this point in the history
…string

Added support for AAD authentication via connection string
  • Loading branch information
dhensby authored Oct 31, 2022
2 parents 655f439 + 9f81f18 commit 7220582
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 2 deletions.
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':
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

0 comments on commit 7220582

Please sign in to comment.