Posts

Showing posts with the label MSAL

What is the definition of token?

Image
In MSAL (Microsoft Authentication Library) and general OAuth 2.0/OpenID Connect, a token is a string that represents the authorization granted to a client to access a protected resource. Tokens are issued by an authorization server and are sent to the client in the form of a string. There are two main types of tokens: Access Token: is used to authenticate and authorize the client to access protected resources on the resource server. It contains information about the identity of the client and the authorization granted. Refresh Token: is used to obtain a new access token when the current one expires. It is typically a long-lived token that is stored securely on the client. MSAL uses these tokens to authenticate and authorize the client to access protected resources on the resource server. The client can use the access token to authenticate and authorize requests to the resource server. The client can also use the refresh token to obtain a new access token when the current one expires. W...

C# How to Get SharePoint Online Documents Analytics Using Graph API

Image
In this article we will see How to get SharePoint Online documents analytics using the Microsoft Graph API. To get, you will need to: Register an app in Azure AD to authenticate and authorize API requests. Grant the app the necessary permissions to read the documents and their analytics data. Use the API to get the analytics data for the documents. Below is the example of how you can do this in C#: using Microsoft.Identity.Client; using Microsoft.Graph; using System.Net.Http.Headers; // Replace these with your own values. const string clientId = "your-client-id"; const string clientSecret = "your-client-secret"; const string tenantId = "your-tenant-id"; const string resourceId = "https://graph.microsoft.com"; const string siteId = "your-site-id"; // Acquire an access token. var authContext = new AuthenticationContext("https://login.microsoftonline.com/" + tenantId); var clientCredential = new ClientCredential(clientId, clientS...

C# How to Access SharePoint Online Lists using Graph API using MSAL

Image
In this article, we will see how to invoke SharePoint Online Lists using Graph API using MSAL authentication in C#. To access a SharePoint Online list using the Microsoft Graph API with MSAL (Microsoft Authentication Library) authentication in C#, you will need to follow these steps: Register your application with Azure Active Directory (AAD) and grant it the necessary permissions to access SharePoint Online. This will enable your application to authenticate with AAD and obtain access tokens. Install the Microsoft.Identity.Client NuGet package in your C# application. This will allow you to authenticate users and obtain access tokens using the MSAL library. Use the MSAL library to authenticate the user and obtain an access token. This token will be used to authorize your application to access SharePoint Online. Use the access token to make a request to the Microsoft Graph API to retrieve the data from the SharePoint Online list. Here is an example of how you can use the MSAL library to ...

What is the difference between ADAL and MSAL ?

Image
MSAL (Microsoft Authentication Library) works with the Azure AD V2 endpoint. MSAL will connect client application users to the on-prem AD or cloud environment, will protect API by requesting token for access. ADAL (Active Directory Authentication Library) works with the Azure AD V1 endpoint. The V1 endpoint supports work accounts, but not personal accounts. The V2.0 endpoint is the combination of Microsoft personal account and work account into single authentication system. With MSAL we can also get authentications for Azure AD B2C. Happy PC (Programming / Configuring)

C# How to Call Graph API from Web API using MSAL Authentication

Image
In this article you will see, in C# how to call Graph API from Web API using MSAL Auth using .NET Framework. MSAL auth with Graph API works good on Console app, Azure Func App, etc. But not for Web API, need to handle with Azure Identity.  To make it work on Web API, instead of using Microsoft.Client.Identity we will need to Azure.Identity. Internally Azure.Identity uses the MSAL authentication. So you can use like below. var tenantId = "xxxxx-xxxx-4392-xxxx-xxxxxxxxxx"; var clientId = "xxxxx-xxxx-4203-xxxx-xxxxxxxx"; var clientSecret = "xxxxxzzxxzzzxxzzzzzxxxxxxxx"; var clientSecretCredential = new ClientSecretCredential(tenantId, clientId, clientSecret); GraphServiceClient graphServiceClient = new GraphServiceClient(clientSecretCredential); var users = graphServiceClient.Users.Request()                   .Select(x => x.DisplayName).GetAsync().Result; Output: You will get result like below. Happy PC (Programming / Configuring)