The code below is based on https://blogs.msdn.microsoft.com/vesku/2016/02/15/connecting-to-sharepoint-online-from-console-application-with-adal-and-pnp-core-component/ and works correctly when used with the NuGet SharePointPnPCoreOnline version 2.19.1710 package.
This would appear to be the last version of the package that works because anything later causes a problem. ctx.ExecuteQuery() throws a “The remote server returned an error: (403) Forbidden.” Exception. A login dialog will appear (post exception) if the console is awaiting input during Console.ReadKey(True). If the Console.ReadKey(True) statement is commented out, no prompt for credentials occurs at all.
Searching the internet, there is no mention of recent usage of GetAzureADNativeApplicationAuthenticatedContext. Anything I've found is going back to the early days. This functionality hasn't been deprecated as far as I can tell. Does anybody know if it is possible to get this working post 2.19.1710?
Sub SharepointOnlineWithAzureADNativeApplicationAuthenticatedContext()
Try
Dim clientId = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
Dim url = "https://MySite.sharepoint.com/S/ICT"
Dim redirectUrl = "https://MyTenant.onmicrosoft.com/Test"
Dim auth = New AuthenticationManager()
Using ctx = auth.GetAzureADNativeApplicationAuthenticatedContext(url, clientId, redirectUrl)
Dim Web = ctx.Web
ctx.Load(Web)
ctx.ExecuteQuery()
Dim title = Web.Title
Console.WriteLine("Title is {0}", title)
End Using
Catch ex As Exception
Console.WriteLine("Fail: {0}", ex.Message)
End Try
Console.WriteLine("Press a key...")
Console.ReadKey(True)
End Sub