Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Applies to:
External tenants (learn more)
In this quickstart, you use a sample Node Command Line Interface (CLI) application to sign in users in your external tenant. The sample application uses the Microsoft Authentication Library for Node (MSAL Node) to handle authentication.
Prerequisites
- Visual Studio Code or another code editor.
- Node.js.
- An external tenant. To create one, choose from the following methods:
- (Recommended) Use the Microsoft Entra External ID extension to set up an external tenant directly in Visual Studio Code.
- Create a new external tenant in the Microsoft Entra admin center.
- Register a new app in the Microsoft Entra admin center, configured for Accounts in this organizational directory only. Refer to Register an application for more details. Record the following values from the application Overview page for later use:
- Application (client) ID
- Directory (tenant) ID
- Add the following redirect URIs using the Mobile and desktop applications platform configuration. Refer to How to add a redirect URI in your application for more details.
- Custom redirect URIs:
http://localhost
- Custom redirect URIs:
- Associate your app with a user flow in the Microsoft Entra admin center. This user flow can be used across multiple applications. For more information, see Create self-service sign-up user flows for apps in external tenants and Add your application to the user flow.
Enable public client flows
To identify your app as a public client, follow these steps:
Under Manage, select Authentication.
Under Advanced settings, for Allow public client flows, select Yes.
Select Save to save your changes.
Clone or download the sample Node.js CLI application
To obtain the sample application, you can either clone it from GitHub or download it as a .zip file.
To clone the sample, open a command prompt and navigate to where you wish to create the project, and enter the following command:
git clone https://github.com/Azure-Samples/ms-identity-ciam-javascript-tutorial.gitDownload the .zip file. Extract it to a file path where the length of the name is fewer than 260 characters.
Configure the sample Node.js CLI application
To configure the client application (Node.js CLI app) to use your Microsoft Entra app registration details, open the project in your IDE and follow these steps:
Open the App\authConfig.js file.
Find the placeholder:
Enter_the_Application_Id_Hereand replace the existing value with the application ID (clientId) ofnode-cli-appapplication copied from the Microsoft Entra admin center.Enter_the_Tenant_Subdomain_Hereand replace it with the Directory (tenant) subdomain. For example, if your tenant primary domain iscontoso.onmicrosoft.com, usecontoso. If you don't have your tenant name, learn how to read your tenant details
Run and test the sample Node.js CLI application
You can now test the sample Node.js CLI application.
In your terminal, run the following command:
cd 1-Authentication\6-sign-in-node-cli-app\App npm startThe browser opens up automatically and you should see a page similar to the following:
On the sign-in page, type your Email address. If you don't have an account, select No account? Create one, which starts the sign-up flow.
If you choose the sign-up option, after filling in your email, one-time passcode, new password, and more account details, you complete the whole sign-up flow. After completing the sign up flow and signing in, you see a page similar to the following screenshot:
Go back to the terminal and see your authentication information including the ID token claims.