Hi @Balaji Mogadali ,
Welcome to the Microsoft Q&A Platform!
To check document-level access for a user in SharePoint using AI Search while leveraging the existing identity of a user, you need to combine SharePoint API capabilities with AI Search.
- Set Up Azure Cognitive Search Index SharePoint documents into Azure Cognitive Search.
- Ensure document metadata includes user/group permissions.
- Use Azure Data Factory or APIs for indexing SharePoint content.
- Use Microsoft Graph API to retrieve the user's identity and permissions.
GET https://graph.microsoft.com/v1.0/me
- Ensure proper Azure AD Authentication.
- Use Azure Cognitive Search SDK in C# to filter results based on the user's identity.
Filter = $"permissions/any(p: p eq '{userPrincipalName}')"
- Use SharePoint REST API or Microsoft Graph API to confirm user permissions for a specific document.
GET /sites/{site-id}/drives/{drive-id}/items/{item-id}/permissions
using System;
using System.Threading.Tasks;
using Azure;
using Azure.Search.Documents;
using Azure.Search.Documents.Models;
class Program
{
static async Task Main(string[] args)
{
string searchServiceName = "<YourSearchServiceName>";
string indexName = "<YourIndexName>";
string apiKey = "<YourAdminApiKey>";
string userPrincipalName = "<UserPrincipalName>"; // User Identity
// Initialize Cognitive Search Client
var searchClient = new SearchClient(
new Uri($"https://{searchServiceName}.search.windows.net"),
indexName,
new AzureKeyCredential(apiKey)
);
// Search Query with User Permissions
var options = new SearchOptions
{
Filter = $"permissions/any(p: p eq '{userPrincipalName}')",
Size = 10
};
var results = await searchClient.SearchAsync<SearchDocument>("*", options);
// Display Accessible Documents
Console.WriteLine("Accessible Documents:");
foreach (var result in results.GetResults())
{
Console.WriteLine(result.Document["name"]);
}
}
}
https://zcusa.951200.xyz/en-us/sharepoint/dev/sp-add-ins/sharepoint-add-ins
https://zcusa.951200.xyz/en-us/graph/overview
https://zcusa.951200.xyz/en-us/azure/search/search-what-is-azure-search
If the answer is helpful, please click Accept Answer and kindly upvote it