node.js based authentication library for Azure with type definitions
Перейти к файлу
Ace Eldeib 6bd8f01f61 fix comments, graph -> batch 2018-08-24 15:34:35 -07:00
.vscode changes made after running basic tests for userTokenCreds and applicationTokenCreds 2017-09-08 15:11:54 -07:00
dist/lib add batch, remove graph context, add interactive login token audiences 2018-08-24 15:22:16 -07:00
lib fix comments, graph -> batch 2018-08-24 15:34:35 -07:00
typings/lib revert bad authConstant change 2018-08-24 15:32:54 -07:00
.gitattributes initial commit 2017-09-08 11:25:16 -07:00
.gitignore added typings and a sample for authentication via auth file 2017-09-08 18:42:34 -07:00
.npmignore finalize things 2017-09-17 11:52:21 -07:00
.travis.yml finalize things 2017-09-17 11:52:21 -07:00
Changelog.md finalize things 2017-09-17 11:52:21 -07:00
LICENSE Initial commit 2017-09-06 16:29:08 -07:00
README.md finalize things 2017-09-17 11:52:21 -07:00
package-lock.json Update ms-rest-js and bump to v0.5 2018-08-16 09:12:15 -07:00
package.json Update ms-rest-js and bump to v0.5 2018-08-16 09:12:15 -07:00
tsconfig.json initial commit 2017-09-08 11:25:16 -07:00
tslint.json initial commit 2017-09-08 11:25:16 -07:00

README.md

This library provides different node.js based authentication mechanisms for services in Azure. It also contains rich type definitions thereby providing good typescrit experience. All the authentication methods support callback as well as promise. IF they are called within an async method in your application then you can use the async/await pattern as well.

Example

username/password based login

import * as msRestNodeAuth from "ms-rest-nodeauth";

const username = process.env["AZURE_USERNAME"];
const password = process.env["AZURE_PASSWORD"];

msRestNodeAuth.loginWithUsernamePasswordWithAuthResponse(username, password).then((authres) => {
  console.dir(authres, { depth: null })
}).catch((err) => {
  console.log(err);
});

service-principal/secret based login

import * as msRestNodeAuth from "ms-rest-nodeauth";

const clientId = process.env["CLIENT_ID"];
const secret = process.env["APPLICATION_SECRET"];
const tenantId = process.env["DOMAIN"];

msRestNodeAuth.loginWithServicePrincipalSecretWithAuthResponse(clientId, secret, tenantId).then((authres) => {
  console.dir(authres, { depth: null })
}).catch((err) => {
  console.log(err);
});

interactive/device-code flow login

import * as msRestNodeAuth from "ms-rest-nodeauth";

msRestNodeAuth.interactiveLoginWithAuthResponse().then((authres) => {
  console.dir(authres, { depth: null })
}).catch((err) => {
  console.log(err);
});

service-principal authentication from auth file on disk

import * as msRestNodeAuth from "../lib/msRestNodeAuth";

const options: msRestNodeAuth.LoginWithAuthFileOptions = {
  filePath: "<file path to auth file>",
}
msRestNodeAuth.loginWithAuthFileWithAuthResponse(options).then((authRes) => {
  console.log(authRes);
  console.log(process.env["AZURE_SUBSCRIPTION_ID"]);
}).catch((err) => {
  console.log(err);
});

MSI(Managed Service Identity) based login from a virtual machine created in Azure.

import * as msRestNodeAuth from "../lib/msRestNodeAuth";

msRestNodeAuth.loginWithMSI("your-tenantId").then((msiTokenRes) => {
  console.log(msiTokenRes);
}).catch((err) => {
  console.log(err);
});

Contributing

This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.microsoft.com.

When you submit a pull request, a CLA-bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.