I've been going round in circles the last 3 days since MFA got enabled and the console application that used username/password to authenticate and add/deleted files/folders to various SharePoint sites stopped working.
I need the console application to operate with no interaction, so the popup MFA authenticator App window is no use. I tried using an App Password, this either is or is going to be depreciated and equally I didn't seem to have the option for it in my Azure AD / Entra ID. I tried a Client Secret but this is going to be depreciated also I couldn't get it to work. Various forums, guides and documentation online refers to old nuget packages that are no longer available and the successor packaged don't always include the same methods. So my final option seemed to be the Self-signed Certificate route.
From the previous attempts above; I had registered an App in Azure AD / Entra ID, so I now followed powershell commands to create a self-signed certificate .cer and .pfx and add this to the registered App.
I have the following code:
Dim appId As String = "{actual-removed}"
Dim authManager = New AuthenticationManager(appId, "C:\Users\...\testApp.pfx", "password", "company.onmicrosoft.com")
Using cc = authManager.GetContext("https://company.sharepoint.com/sites/test")
cc.Load(cc.Web)
cc.ExecuteQuery()
Debug.WriteLine(cc.Web.Title)
End Using
I get the following error message:
An unhandled exception of type 'System.Net.WebException' occurred in Microsoft.SharePoint.Client.Runtime.dll The remote server returned an error: (401) Unauthorized.
I thought the app/client ID and a certificate satisfied the MFA requirement.
Please can someone help me, is there an obvious settings I'm missing in Azure AD / Entra ID? Or is there something extra I need to add to my code?
Any help would be greatly appreciated, I'm losing my mind.
Thank you in advance.