browser based authentication library for Azure
Перейти к файлу
microsoft-github-policy-service[bot] cf5a3da914
Auto merge mandatory file pr
This pr is auto merged as it contains a mandatory file and is opened for more than 10 days.
2022-11-28 19:35:28 +00:00
.scripts Remove trailing whitespace 2018-12-17 13:47:06 -08:00
doc Retire outdated app-creation doc (#37) 2021-01-21 09:30:22 -08:00
lib remove callback param since it is not needed 2020-04-22 01:09:48 -07:00
samples Update samples/react-app/README.md 2022-05-02 22:12:18 -05:00
test Update test harness 2018-09-21 12:33:16 -07:00
testserver Update test harness 2018-09-21 12:33:16 -07:00
.gitattributes Init with stubs and config 2018-09-20 15:50:17 -07:00
.gitignore Improve sourcemaps to point at the original typescript source code 2018-11-14 15:42:27 -08:00
Changelog.md Retire outdated app-creation doc (#37) 2021-01-21 09:30:22 -08:00
LICENSE Initial commit 2018-09-20 15:47:46 -07:00
README.md Copy over instructions to main readme as well 2021-05-14 14:33:58 -07:00
SECURITY.md Microsoft mandatory file 2022-07-28 16:47:38 +00:00
azure-pipelines.yml Add package.json version check 2018-12-17 13:40:28 -08:00
index.html Update test harness 2018-09-21 12:33:16 -07:00
package.json Retire outdated app-creation doc (#37) 2021-01-21 09:30:22 -08:00
rollup.config.js Improve sourcemaps to point at the original typescript source code 2018-11-14 15:42:27 -08:00
tsconfig.es.json Init with stubs and config 2018-09-20 15:50:17 -07:00
tsconfig.json Update tsconfig.json 2018-09-20 15:50:17 -07:00
tslint.json Init with stubs and config 2018-09-20 15:50:17 -07:00
webpack.testconfig.ts Init with stubs and config 2018-09-20 15:50:17 -07:00

README.md

ms-rest-browserauth Build Status

Provides browser-based authentication for Azure resources. Designed for use with libraries in azure-sdk-for-js.

Requirements

  • node.js version > 6.x

Getting Started

Before using this library, you need to register your application in the Microsoft identity platform and set the right permissions.

  • Register a single page application in the Microsoft identity platform
  • Configure the app registration with a redirect URI to specify where the Microsoft identity platform should redirect the client along with any security tokens.
  • Ensure that your application has the right permission for the APIs it intends to use.
    • In your app registration in the Azure portal, go to API Permissions
    • Click on Add a permission
    • Select the API you want to use
    • Check the box for user_impersonation permission
  • Keep in mind that the account administrator may need to grant admin consent for the Default Directory.

Below is a basic sample that accesses the Azure Service Management APIs to list the available subscriptions. See the samples for more detailed usage.

<!DOCTYPE html>
<html lang="en">
  <head>
    <title>ms-rest-browserauth sample</title>
    <script src="node_modules/@azure/ms-rest-js/dist/msRest.browser.js"></script>
    <script src="node_modules/@azure/ms-rest-azure-js/dist/msRestAzure.js"></script>
    <script src="node_modules/@azure/ms-rest-browserauth/dist/msAuth.js"></script>
  </head>
  <body></body>
  <script>
    const authManager = new msAuth.AuthManager({
      clientId: "<client id for your Azure AD app>",
      tenant: "<optional tenant for your organization>",
    });
    authManager.finalizeLogin().then((res) => {
      if (!res.isLoggedIn) {
        // Usually, this will cause redirects to the Azure AD login page.
        // In practice, you may wish to call this method in the onClick for a login button on the page.
        authManager.login();
      }

      // These credentials can be passed to any of the Client classes provided in azure-sdk-for-js to authenticate
      const credentials = res.creds;
      console.log("Available subscriptions: ", res.availableSubscriptions);
    });
  </script>
</html>

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.