Skip to content

Commit

Permalink
Adding Samples
Browse files Browse the repository at this point in the history
  • Loading branch information
sameerag committed Jul 9, 2021
1 parent be3f7bd commit 835e740
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/msal-common/src/client/UsernamePasswordClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,18 @@ export class UsernamePasswordClient extends BaseClient {
parameterBuilder.addLibraryInfo(this.config.libraryInfo);

parameterBuilder.addThrottling();

if (this.serverTelemetryManager) {
parameterBuilder.addServerTelemetry(this.serverTelemetryManager);
}

const correlationId = request.correlationId || this.config.cryptoInterface.createNewGuid();
parameterBuilder.addCorrelationId(correlationId);

if (this.config.clientCredentials.clientSecret) {
parameterBuilder.addClientSecret(this.config.clientCredentials.clientSecret);
}

if (!StringUtils.isEmptyObj(request.claims) || this.config.authOptions.clientCapabilities && this.config.authOptions.clientCapabilities.length > 0) {
parameterBuilder.addClaims(request.claims, this.config.authOptions.clientCapabilities);
}
Expand Down
1 change: 1 addition & 0 deletions samples/msal-node-samples/username-password-cca/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package-lock=false
31 changes: 31 additions & 0 deletions samples/msal-node-samples/username-password-cca/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License.
*/

var msal = require("@azure/msal-node");

const msalConfig = {
auth: {
clientId: "", // Enter your client_id here
authority: "", // Enter your authority here
clientSecret: "" // Enter your client_secret here
}
};

const cca = new msal.ConfidentialClientApplication(msalConfig);

const usernamePasswordRequest = {
scopes: ["user.read"],
username: "", // Add your username here
password: "", // Add your password here
};

cca.acquireTokenByUsernamePassword(usernamePasswordRequest).then((response) => {
console.log("acquired token by password grant in confidential clients");
}).catch((error) => {
console.log(error);
});



18 changes: 18 additions & 0 deletions samples/msal-node-samples/username-password-cca/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "msal-node-username-password-cca",
"version": "1.0.0",
"description": "Command line app that uses Oauth password grant flow to get a token from Azure AD",
"main": "index.js",
"private": true,
"scripts": {
"start": "node index.js",
"build:package": "cd ../../lib/msal-common && npm run build && cd ../msal-node && npm run build",
"start:build": "npm run build:package && npm start",
"install:local": "npm install ../../../lib/msal-node"
},
"author": "Microsoft",
"license": "MIT",
"dependencies": {
"@azure/msal-node": "file:../../../lib/msal-node"
}
}

0 comments on commit 835e740

Please sign in to comment.