Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

A Node.js console daemon application secured by MSAL Node and calling Microsoft Graph API via OAuth 2.0 client credentials flow

License

NotificationsYou must be signed in to change notification settings

Azure-Samples/ms-identity-javascript-nodejs-console

page_typelanguagesproductsdescriptionurlFragment
sample
javascript
nodejs
ms-graph
microsoft-entra-id
Demonstrates how to use MSAL Node to acquire an access token for a protected resource such as Microsoft Graph in a console daemon application using the application's own identity (client credentials flow)
ms-identity-javascript-nodejs-console

This sample demonstrates how to useMSAL Node to acquire an access token for a protected resource such as Microsoft Graph in a console daemon application using the application's own identity with the (client credentials flow).

Caution

This sample is intended as adaemon application - an application that securely runs on a server. You should not use this sample for anypublic client scenarios. Distributing client secrets with your applications can lead to exfiltration and misuse of the credentials.

Features

This sample demonstrates the followingMSAL Node concepts:

  • Configuration
  • Acquiring an access token
  • Calling a web API

Contents

File/folderDescription
AppCreationScripts/Contains Powershell scripts for automating app registration.
bin/index.jsApplication entry.
bin/auth.jsMain authentication logic resides here.
bin/fetch.jsContains an Axios HTTP client for calling endpoints.
.envEnvironment variables of authentication parameters.

Getting Started

Prerequisites

Setup

  1. Register a new application in theMicrosoft Entra admin center.
    1. For API Permissions, selectUser.Read.All underMicrosoft APIs >Microsoft Graph >Application Permissions.
    2. SelectGrant admin consent for {tenant}.
  2. Clone this repositorygit clone https://github.com/Azure-Samples/ms-identity-javascript-nodejs-console.git
  3. Open the.env file and provide the required configuration values.
    1. Replace the stringEnter_the_Tenant_Info_Here with your tenant ID on Microsoft Entra admin center.
    2. Replace the stringEnter_the_Application_Id_Here with your app/client ID on Microsoft Entra admin center.
    3. Replace the stringEnter_the_Client_Secret_Here with the client secret you created on Microsoft Entra admin center.
    4. Replace the stringEnter_the_Cloud_Instance_Id_Here withhttps://login.microsoftonline.com/ (seenote below).
    5. Replace the stringEnter_the_Graph_Endpoint_Here. withhttps://graph.microsoft.com/ (seenote below).

ℹ️note: This is for multi-tenant applications located on the global Azure cloud. For more information, see:Use MSAL in a national cloud environment

ℹ️note: This is for MS Graph instance located on the global Azure cloud. For more information, see:Use Microsoft Graph in a national cloud environment

  1. On the command line, navigate to the root of the repository, and typenpm install.

ℹ️ Alternative, typenpm install -g. This will install the CLI application globally so that it can be called from anywhere.

Run the sample

  1. On the command line, navigate to the root of the repository and run the sample application withnode . --op getUsers.

ℹ️ If you have installed the sample app globally above, typemsal-node-cli --op getUsers from anywhere in a command line.

Contributing

If you'd like to contribute to this sample, seeCONTRIBUTING.MD.

Code of Conduct

This project has adopted theMicrosoft Open Source Code of Conduct.For more information see theCode of Conduct FAQ orcontactopencode@microsoft.com with any additional questions or comments.

About

A Node.js console daemon application secured by MSAL Node and calling Microsoft Graph API via OAuth 2.0 client credentials flow

Topics

Resources

License

Code of conduct

Contributing

Stars

Watchers

Forks

Contributors10


[8]ページ先頭

©2009-2025 Movatter.jp