Skip to content

Commit

Permalink
Merge pull request #1355 from tediousjs/arthur/azure-ad-password-clie…
Browse files Browse the repository at this point in the history
…nt-id

feat: allow specifying the `clientId` when using `azure-active-directory-password` auth
  • Loading branch information
arthurschreiber committed Jan 23, 2022
2 parents 56a666f + 95e98a1 commit 70e77e1
Showing 1 changed file with 32 additions and 3 deletions.
35 changes: 32 additions & 3 deletions src/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,11 +247,17 @@ interface AzureActiveDirectoryPasswordAuthentication {
* A user need to provide `userName` asscoiate to their account.
*/
userName: string;

/**
* A user need to provide `password` asscoiate to their account.
*/
password: string;

/**
* A client id to use.
*/
clientId: string;

/**
* Optional parameter for specific Azure tenant ID
*/
Expand Down Expand Up @@ -1085,12 +1091,19 @@ class Connection extends EventEmitter {
throw new TypeError('The "config.authentication.options.password" property must be of type string.');
}

if (options.clientId !== undefined && typeof options.clientId !== 'string') {
throw new TypeError('The "config.authentication.options.clientId" property must be of type string.');
} else if (options.clientId === undefined) {
emitAzureADPasswordClientIdDeprecationWarning();
}

authentication = {
type: 'azure-active-directory-password',
options: {
userName: options.userName,
password: options.password,
domain: options.domain,
domain: options.domain ?? 'common',
clientId: options.clientId ?? '7f98cb04-cd1e-40df-9140-3bf7e2cea4db'
}
};
} else if (type === 'azure-active-directory-access-token') {
Expand Down Expand Up @@ -3085,6 +3098,22 @@ class Connection extends EventEmitter {
}
}

let azureADPasswordClientIdDeprecationWarningEmitted = false;
function emitAzureADPasswordClientIdDeprecationWarning() {
if (azureADPasswordClientIdDeprecationWarningEmitted) {
return;
}

azureADPasswordClientIdDeprecationWarningEmitted = true;

process.emitWarning(
'When using the `azure-active-directory-password` authentication method, please provide a value for the `clientId` option. ' +
'This option will be required in a future release.',
'DeprecationWarning',
Connection.prototype.on
);
}

export default Connection;
module.exports = Connection;

Expand Down Expand Up @@ -3403,8 +3432,8 @@ Connection.prototype.STATE = {

if (authentication.type === 'azure-active-directory-password') {
const credentials = new UsernamePasswordCredential(
authentication.options.domain ?? 'common', // tenantId
'7f98cb04-cd1e-40df-9140-3bf7e2cea4db', // clientId
authentication.options.domain,
authentication.options.clientId,
authentication.options.userName,
authentication.options.password
);
Expand Down

0 comments on commit 70e77e1

Please sign in to comment.