Skip to content
This repository was archived by the owner on Nov 4, 2021. It is now read-only.

node.js based authentication library for Azure with type definitions

License

Notifications You must be signed in to change notification settings

developher-net/ms-rest-nodeauth

This branch is 72 commits behind Azure/ms-rest-nodeauth:master.

Folders and files

NameName
Last commit message
Last commit date

Latest commit

f5e6ed5 · Apr 4, 2019

History

71 Commits
Nov 19, 2018
Dec 17, 2018
Sep 5, 2018
Mar 26, 2019
Jan 12, 2019
Sep 8, 2017
Nov 14, 2018
Nov 12, 2018
Sep 6, 2017
Nov 13, 2018
Dec 17, 2018
Apr 4, 2019
Nov 14, 2018
Oct 18, 2018
Nov 12, 2018

Repository files navigation

ms-rest-nodeauth Build Status

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 "@azure/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 "@azure/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 "@azure/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";

const options: msRestNodeAuth.MSIVmOptions = {
  port: 50342;
}

msRestNodeAuth.loginWithVmMSI(options).then((msiTokenRes) => {
  console.log(msiTokenRes);
}).catch((err) => {
  console.log(err);
});

MSI (Managed Service Identity) based login from an AppService or Azure Function created in Azure.

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

const options: msRestNodeAuth.MSIAppServiceOptions = {
  msiEndpoint: "http://127.0.0.1:41741/MSI/token/";
}

msRestNodeAuth.loginWithAppServiceMSI(options).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 [email protected] with any additional questions or comments.

About

node.js based authentication library for Azure with type definitions

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • TypeScript 99.5%
  • JavaScript 0.5%