C# Winforms app querying Sharepoint Online using the CSOM Sharepoint Client Classes.
All good so far but I need to get the permissions for the current user so I can check if they have access to the website and/or subsite. I'm connecting to my 'ClientContext' correctly and am using an AD Service Account which has permission to access all sites.
I've found several examples on the web that all give this example of how to retrieve the permissions for the current user:
User user = cxt.Site.RootWeb.EnsureUser(UserPrincipal.Current.EmailAddress);
// Get all permissions for this user
var permissions = cxt.Site.RootWeb.GetUserEffectivePermissions(user.LoginName);
The line in bold fails with an 'unauthorized access exception'. The current user in this scenario is myself and I have permissions to open and view all sites except 1 test site.
My Context 'cxt' is running under the service account.
So, in effect I understand this as: run the context as the service account and then load a user and check their permissions, but it doesn't work.
Is it possible what I'm trying to do or is there another way? I've seen mentioned that you have to build a Web API to perform the user permission check because it's allowed to run with 'elevated permissions'.
Hope someone can help?