Introduction
The Microsoft Authentication Library (MSAL) serves as a crucial tool for implementing secure authentication in Vanilla JavaScript Single Page Applications (SPAs). Specifically designed for obtaining JWT (JSON Web Token) Access Tokens and ID Tokens, MSAL facilitates seamless integration with Microsoft identity services. By leveraging MSAL in your SPA, you empower your application to handle authentication processes effectively, ensuring the secure retrieval of Access Tokens for API access and ID Tokens for user identity verification. This summary highlights the significance of MSAL in enhancing the authentication capabilities of Vanilla JS SPAs, contributing to a robust and secure user experience.
You can find the code solution of this article here MSAL-Vanilla-JS-APP
Microsoft Authentication Library (MSAL)
The Microsoft Authentication Library, commonly abbreviated as MSAL, is a set of client libraries and tools provided by Microsoft to simplify and streamline the implementation of authentication and authorization in applications. MSAL is designed to work with various programming languages and platforms, including JavaScript, .NET, Python, and more.
Specifically, MSAL facilitates the integration of applications with Microsoft identity services, such as Azure Active Directory (Azure AD) and Microsoft Accounts. It enables developers to handle authentication processes seamlessly, allowing users to sign in securely and obtain access tokens and ID tokens, which are essential for accessing protected resources and verifying user identity.
MSAL supports various authentication protocols, including OAuth 2.0 and OpenID Connect, and it provides a consistent and standardized approach to managing tokens and interacting with identity providers. Whether building web applications, mobile apps, or other types of software, developers can leverage MSAL to enhance security and user authentication experiences.
JWT access token & ID token
Access Token and ID Token are both components of the OAuth 2.0 and OpenID Connect authentication frameworks, and they serve distinct purposes in the authentication and authorization process.
Access token
- Definition: An Access Token is a credential that represents the authorization granted to a client (an application or user) to access a specific resource or perform a particular action.
- Purpose: Access Tokens are used to authenticate the client when making requests to access protected resources on a resource server (such as an API). They convey the permissions granted and are typically time-limited.
- Example use case: In a Single Page Application (SPA), an Access Token might be obtained during the authentication process and then included in API requests to allow access to the user's data.
ID token
- Definition: An ID Token is a JSON Web Token (JWT) that contains claims about the identity of the authenticated user.
- Purpose: ID Tokens provide information about the user, such as their unique identifier, name, and email. They are often used to verify the user's identity on the client side without the need to make additional requests to an identity provider.
- Example use case: In a web application, an ID Token may be used to display the user's name and profile picture on the user interface after authentication, providing a personalized experience.
In summary, Access Tokens are primarily concerned with authorization and resource access, while ID Tokens focus on providing information about the authenticated user. Both tokens play integral roles in securing authentication processes and enabling secure interactions between clients and resource servers.
App registration in Microsoft Entra ID



Provide the details and add the URI here but you can also add the URI after the app registration process.

Go to the Overview of the app and copy the application (Client) ID.

Now go to the Authentication.

Add a platform select a Single-page application and provide the URI with localhost.



















Join the conversation! Your thoughts help the community grow.