SOLVED

SharePoint Authentication from C# Application

%3CLINGO-SUB%20id%3D%22lingo-sub-488257%22%20slang%3D%22en-US%22%3ESharePoint%20Authentication%20from%20C%23%20Application%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-488257%22%20slang%3D%22en-US%22%3E%3CP%3EI've%20been%20struggling%20a%20bit%20to%20get%20authentication%20working.%20My%20C%23%20application%20is%20a%20COM-based%20Add-In%20for%20a%20product%20called%20Enterprise%20Architect.%20In%20the%20app%2C%20we%20want%20to%20copy%20files%20to%2Ffrom%20SharePoint%2C%20and%20to%20do%20that%2C%20I%20have%20to%20get%20a%20ClientContext%20object%20for%20the%20current%20user.%20I'm%20currently%20using%20AuthenticationManager.GetWebLoginClientContext()%2C%20but%20it%20has%20started%20behaving%20oddly%20-%20it%20has%20always%20popped%20up%20a%20browser%20window%2C%20but%20the%20window%20used%20to%20go%20away%20on%20its%20own%20once%20the%20authentication%20was%20done.%20Now%20that%20window%20is%20getting%20%22stuck%22%20and%20never%20closes%20unless%20I%20close%20it.%20This%20is%20my%20code%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3Eusing%20ODP%20%3D%20OfficeDevPnP.Core%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EODP.AuthenticationManager%20authManager%20%3D%20new%20ODP.AuthenticationManager()%3B%3CBR%20%2F%3Ectx%20%3D%20authManager.GetWebLoginClientContext(ContextUrl)%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIf%20I%20close%20the%20browser%20window%2C%20ctx%20ends%20up%20being%20null.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20have%20also%20created%20a%20test%20harness%20console%20application%20that%20calls%20through%20to%20this%20same%20code%2C%20and%20when%20I%20run%20the%20console%20app%2C%20the%20browser%20form%20does%20in%20fact%20go%20away%20on%20its%20own%2C%20and%20the%20code%20works.%20But%20when%20I%20exercise%20this%20code%20via%20Enterprise%20Architect's%20COM-based%20Add-In%20interface%2C%20which%26nbsp%3B%20calls%20code%20that%20ends%20up%20going%20through%20this%20same%20exact%20code%2C%20the%20browser%20window%20does%20not%20close%20on%20its%20own%20as%20described%20above.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20have%20also%20considered%20switching%20over%20to%20AuthenticationManager.GetAzureADWebApplicationAuthenticatedContext()%2C%20but%20that%20would%20require%20a%20way%20of%20getting%20an%20access%20token.%20I%20have%20found%20lots%20of%20examples%20online%2C%20but%20they%20ALL%20refer%20to%20a%20MicrosoftGraphHelper%20class%20that%20has%20a%20GetAccessTokenForCurrentUser()%20method.%20For%20the%20life%20of%20me%2C%20I%20cannot%20find%20a%20NuGet%20package%20or%20anything%20that%20has%20an%20implementation%20of%20this%20MicrosoftGraphHelper%20class.%20For%20example%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3Eusing%20ODP%20%3D%20OfficeDevPnP.Core%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EODP.AuthenticationManager%20authManager%20%3D%20new%20ODP.AuthenticationManager()%3B%3CBR%20%2F%3Ectx%20%3D%20authManager.GetAzureADWebApplicationAuthenticatedContext(ContextUrl%2C%20(url)%20%3D%26gt%3B%20%7B%20return%20(MicrosoftGraphHelper.GetAccessTokenForCurrentUser(url))%3B%20%7D)%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20never%20would%20have%20expected%20this%20to%20be%20this%20hard%20to%20figure%20out%20-%20I%20have%20burned%20many%20hours%2C%20finding%20many%20false%20trails%20related%20to%20previous%20ways%20of%20interfacing%20with%20SharePoint%2C%20many%20of%20which%20are%20no%20longer%20recommended.%20For%20example%2C%20that%20OfficeDevPnP%20assembly%20import%20-%20it%20was%20quite%20a%20while%20before%20I%20found%20something%20that%20said%20that%20SharePointPnPCoreOnline%20is%20the%20currently%20recommended%20way%20of%20integrating%20to%20SharePoint%2C%20and%20other%20ways%20are%20not%20recommended%20because%20they%20are%20no%20longer%20being%20maintained.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EPerhaps%20the%20best%20course%20of%20action%20would%20be%20for%20someone%20to%20recommend%20a%20good%20tutorial%20for%20basic%20integration%20from%20C%23%20to%20SharePoint%20Online.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHelp!%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-488485%22%20slang%3D%22en-US%22%3ERe%3A%20SharePoint%20Authentication%20from%20C%23%20Application%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-488485%22%20slang%3D%22en-US%22%3E%3CP%3EHere's%20the%20link%20to%20the%20stackoverflow%20post%20that%20talked%20about%20%3CA%20href%3D%22https%3A%2F%2Fwww.nuget.org%2Fpackages%2FSharePointPnPCoreOnline%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3ESharePointPnPCoreOnline%3C%2FA%3E%20being%20the%20recommended%20way%20to%20integrate%20to%20SharePoint%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fstackoverflow.com%2Fquestions%2F52707476%2Fauthentication-to-sharepoint-online-with-csom%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fstackoverflow.com%2Fquestions%2F52707476%2Fauthentication-to-sharepoint-online-with-csom%3C%2FA%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-509229%22%20slang%3D%22en-US%22%3ERe%3A%20SharePoint%20Authentication%20from%20C%23%20Application%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-509229%22%20slang%3D%22en-US%22%3E%3CP%3ESo%20I%20dug%20into%20this%20a%20little%20deeper%2C%20and%20discovered%20that%20it%20is%20happening%20because%20the%20code%20behind%20the%20GetWebLoginClientContext()%20method%20is%20looking%20at%20the%20cookies%2C%20specifically%20for%20cookies%20that%20have%20%22FedAuth%22%20or%20%22EdgeAccessCookie%22%20in%20their%20names.%20If%20those%20cookies%20are%20found%2C%20and%20only%20if%20they%20are%20found%2C%20the%20form%20automatically%20closes.%20I%20created%20my%20own%20implementation%20of%20the%20method%20so%20I%20could%20step%20through%20the%20code%2C%20and%20discovered%20that%20since%20it%20is%20not%20finding%20those%20cookies%2C%20it%20is%20not%20closing%20the%20form.%20So%20the%20real%20issue%20is%20that%20those%20cookies%20are%20not%20present%20in%20the%20HTTP%20Response.%20At%20least%20I've%20got%20a%20better%20lead%20now.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-509639%22%20slang%3D%22en-US%22%3ERe%3A%20SharePoint%20Authentication%20from%20C%23%20Application%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-509639%22%20slang%3D%22en-US%22%3E%3CP%3EMore%20research%20results...%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EUsing%20Fiddler%2C%20I%20can%20see%20that%20the%20FedAuth%20cookie%20DOES%20come%20back%20in%20the%20response%2C%20but%20the%20part%20of%20GetWebLoginClientContext%20that%20retrieves%20the%20cookies%20is%20not%20seeing%20that%20cookie.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ELooking%20into%20how%20the%20cookie%20retrieval%20process%20works%20I%20see%20that%20the%20code%20that%20retrieves%20the%20cookies%20is%20using%20InternetGetCookieEx()%20implemented%20in%20wininet.dll.%20That%20function%20is%20returning%20a%20string%20that%20does%20NOT%20contain%20the%20FedAuth%20cookie.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI'm%20not%20quite%20sure%20where%20to%20go%20with%20this%20next%2C%20unless%20there%20is%20a%20different%20way%20to%20retrieve%20the%20cookies.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-529996%22%20slang%3D%22en-US%22%3ERe%3A%20SharePoint%20Authentication%20from%20C%23%20Application%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-529996%22%20slang%3D%22en-US%22%3E%3CP%3EI%20have%20this%20working%20now%2C%20and%20the%20issue%20seems%20to%20have%20been%20related%20to%20the%20URL%20used%20when%20you%20get%20your%20client%20context%20object.%20Our%20SharePoint%20implementation%20has%20multiple%20levels%20of%20sites%20within%20it.%20We%20have%20separate%20sites%20for%20every%20customer%2C%20and%20then%20a%20top%20level%20site.%20I%20was%20attempting%20to%20get%20a%20file%20from%20a%20library%20under%20a%20customer%20site%2C%20and%20I%20had%20been%20using%20a%20URL%20that%20corresponded%20to%20the%20customer%20site.%20Once%20I%20changed%20the%20code%20to%20use%20the%20top%20level%20site%20(literally%20just%20the%20domain%20name)%20for%20the%20client%20context%2C%20the%20popup%20browser%20started%20getting%20the%20FedAuth%20cookie%20and%20things%20started%20working.%20So%20either%20I%20don't%20properly%20understand%20how%20our%20SharePoint%20is%20implemented%2C%20or%20the%20authentication%20method%20is%20extremely%20sensitive%20to%20the%20URL%20you%20use%20to%20get%20the%20cookies.%20The%20absolute%20URL%20to%20the%20file%20I%20was%20attempting%20to%20copy%20down%20looks%20something%20like%20this%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fmycompany.sharepoint.com%2Fcustomers%2Ftheclientname%2F797%2520Project%2520Name%2FIn%2520Process%2520Templates%2Fstandard.xml%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fmycompany.sharepoint.com%2Fcustomers%2Ftheclientname%2F797%2520Project%2520Name%2FIn%2520Process%2520Templates%2Fstandard.xml%3C%2FA%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThis%20URL%20is%20a%20valid%20site%3A%3C%2FP%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fmycompany.sharepoint.com%2Fcustomers%2Ftheclientname%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fmycompany.sharepoint.com%2Fcustomers%2Ftheclientname%3C%2FA%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EBut%20when%20I%20used%20that%20URL%20with%20AuthenticationManager.GetWebLoginClientContext()%2C%20it%20failed.%20Switching%20it%20to%20use%3A%3C%2FP%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fmycompany.sharepoint.com%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fmycompany.sharepoint.com%3C%2FA%3E%3C%2FP%3E%3CP%3Eto%20get%20the%20client%20context%20fixed%20the%20problem.%20Now%2C%20if%20permissions%20were%20different%20at%20these%20different%20levels%2C%20I%20suspect%20this%20would%20have%20failed%20-%20it%20would%20have%20gotten%20a%20valid%20client%20context%2C%20but%20suspect%20I%20could%20still%20have%20gotten%20a%20permissions%20error%20when%20trying%20to%20use%20OpenBinaryStream()%20on%20my%20file%20object.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThis%20was%20a%20frustrating%20journey%2C%20and%20I%20was%20disappointed%20to%20not%20get%20any%20feedback%20from%20anyone%20else.%20Apparently%20my%20limited%20understanding%20of%20SharePoint%20and%20how%20to%20integrate%20to%20it%20is%20not%20as%20common%20as%20I%20thought%20it%20might%20be.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1444023%22%20slang%3D%22en-US%22%3ERe%3A%20SharePoint%20Authentication%20from%20C%23%20Application%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1444023%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F328614%22%20target%3D%22_blank%22%3E%40dougb628%3C%2FA%3E%26nbsp%3BI'm%20glad%20you%20continued%20to%20add%20comments%20here%20as%20I%20was%20having%20the%20same%20issues.%26nbsp%3B%20Someone%20reported%20this%20as%20a%20bug%20in%20December%202019%2C%20however%20it%20is%20not%20fixed%20yet%2C%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2Fpnp%2FPnP-Sites-Core%2Fissues%2F2508%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fgithub.com%2Fpnp%2FPnP-Sites-Core%2Fissues%2F2508%3C%2FA%3E.%26nbsp%3B%3C%2FP%3E%3CP%20data-unlink%3D%22true%22%3E%26nbsp%3B%3C%2FP%3E%3CP%20data-unlink%3D%22true%22%3EThough%20we%20all%20are%20seeing%20the%20same%20behavior%2C%20the%20underlying%20causes%26nbsp%3Bare%20different.%26nbsp%3B%20The%20reporter%20of%20the%20bug%20found%20the%20error%20when%20using%20a%20SharePoint%20Add%20in%20and%20his%20work%20around%20was%20to%20add%20another%20cookie%20to%20the%20list%20of%20cookies%20it%20attempted%20to%20find.%26nbsp%3B%20Your%20issue%20was%20that%20it%20wasn't%20providing%20a%20cookie%20that%20was%20in%20fact%20there.%26nbsp%3B%20My%20issue%20is%20that%20it%20freezes%20on%20the%20browser.Navigated%20call.%20I%20get%20pop-up%20browser%20window%2C%20but%20when%20debugging%20it%20never%20drops%20into%20the%20code%20under%20browser.Navigated.%26nbsp%3B%20I%20have%20no%20fix%20at%20the%20moment.%26nbsp%3B%20This%20behavior%20is%20intermittent%2C%20it%20will%20work%20once%20and%20then%20not%20work%20again%20until%20my%20app%20is%20closed%20and%20reopened.%26nbsp%3B%20No%20exception%20occur%20and%20even%20when%20I%20step%20into%20the%20browser.Navigated%20call%2C%20it%20actually%20looks%20like%20it%20just%20skips%20over%20the%20call%20and%20goes%20to%20the%20next%20line.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1444338%22%20slang%3D%22en-US%22%3ERe%3A%20SharePoint%20Authentication%20from%20C%23%20Application%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1444338%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F690499%22%20target%3D%22_blank%22%3E%40kirstenray%3C%2FA%3EI%20hope%20this%20gets%20resolved%20soon%2C%20but%20I%20actually%20haven't%20really%20done%20much%20with%20this%20once%20I%20got%20it%20working%20by%20just%20using%20the%20domain%20name.%20In%20our%20case%2C%20all%20of%20the%20users%20of%20this%20C%23%20application%20have%20essentially%20the%20exact%20same%20access%20all%20over%20our%20SharePoint%2C%20so%20I%20think%20that%20is%20why%20it%20started%20working%20for%20me.%20Frankly%2C%20I%20still%20don't%20know%20that%20much%20about%20integrating%20to%20SharePoint%2C%20and%20I%20think%20it's%20pretty%20crazy%20that%20you%20have%20to%20launch%20a%20browser%20to%20authenticate.%20Granted%2C%20it%20is%20a%20web%20application%2C%20but%20the%20authentication%20from%20the%20OS%20is%20much%20more%20streamlined.%20I%20can%20open%20a%20Windows%20File%20Explorer%20window%2C%20and%20type%20in%20a%20SharePoint%20address%20in%20the%20address%20bar%2C%20and%20it%20authenticates%20completely%20transparently%2C%20probably%20using%20Kerberos%20or%20something%20-%20I%20don't%20know.%20Why%20can't%20my%20C%23%20application%20authenticate%20in%20a%20similar%20manner%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E
Highlighted
Occasional Contributor

I've been struggling a bit to get authentication working. My C# application is a COM-based Add-In for a product called Enterprise Architect. In the app, we want to copy files to/from SharePoint, and to do that, I have to get a ClientContext object for the current user. I'm currently using AuthenticationManager.GetWebLoginClientContext(), but it has started behaving oddly - it has always popped up a browser window, but the window used to go away on its own once the authentication was done. Now that window is getting "stuck" and never closes unless I close it. This is my code:

 

using ODP = OfficeDevPnP.Core;

 

ODP.AuthenticationManager authManager = new ODP.AuthenticationManager();
ctx = authManager.GetWebLoginClientContext(ContextUrl);

 

If I close the browser window, ctx ends up being null.

 

I have also created a test harness console application that calls through to this same code, and when I run the console app, the browser form does in fact go away on its own, and the code works. But when I exercise this code via Enterprise Architect's COM-based Add-In interface, which  calls code that ends up going through this same exact code, the browser window does not close on its own as described above.

 

I have also considered switching over to AuthenticationManager.GetAzureADWebApplicationAuthenticatedContext(), but that would require a way of getting an access token. I have found lots of examples online, but they ALL refer to a MicrosoftGraphHelper class that has a GetAccessTokenForCurrentUser() method. For the life of me, I cannot find a NuGet package or anything that has an implementation of this MicrosoftGraphHelper class. For example:

 

using ODP = OfficeDevPnP.Core;

 

ODP.AuthenticationManager authManager = new ODP.AuthenticationManager();
ctx = authManager.GetAzureADWebApplicationAuthenticatedContext(ContextUrl, (url) => { return (MicrosoftGraphHelper.GetAccessTokenForCurrentUser(url)); });

 

I never would have expected this to be this hard to figure out - I have burned many hours, finding many false trails related to previous ways of interfacing with SharePoint, many of which are no longer recommended. For example, that OfficeDevPnP assembly import - it was quite a while before I found something that said that SharePointPnPCoreOnline is the currently recommended way of integrating to SharePoint, and other ways are not recommended because they are no longer being maintained.

 

Perhaps the best course of action would be for someone to recommend a good tutorial for basic integration from C# to SharePoint Online.

 

Help!

6 Replies
Highlighted

Here's the link to the stackoverflow post that talked about SharePointPnPCoreOnline being the recommended way to integrate to SharePoint:

 

https://stackoverflow.com/questions/52707476/authentication-to-sharepoint-online-with-csom

Highlighted

So I dug into this a little deeper, and discovered that it is happening because the code behind the GetWebLoginClientContext() method is looking at the cookies, specifically for cookies that have "FedAuth" or "EdgeAccessCookie" in their names. If those cookies are found, and only if they are found, the form automatically closes. I created my own implementation of the method so I could step through the code, and discovered that since it is not finding those cookies, it is not closing the form. So the real issue is that those cookies are not present in the HTTP Response. At least I've got a better lead now.

Highlighted

More research results...

 

Using Fiddler, I can see that the FedAuth cookie DOES come back in the response, but the part of GetWebLoginClientContext that retrieves the cookies is not seeing that cookie.

 

Looking into how the cookie retrieval process works I see that the code that retrieves the cookies is using InternetGetCookieEx() implemented in wininet.dll. That function is returning a string that does NOT contain the FedAuth cookie.

 

I'm not quite sure where to go with this next, unless there is a different way to retrieve the cookies.

Highlighted
Solution

I have this working now, and the issue seems to have been related to the URL used when you get your client context object. Our SharePoint implementation has multiple levels of sites within it. We have separate sites for every customer, and then a top level site. I was attempting to get a file from a library under a customer site, and I had been using a URL that corresponded to the customer site. Once I changed the code to use the top level site (literally just the domain name) for the client context, the popup browser started getting the FedAuth cookie and things started working. So either I don't properly understand how our SharePoint is implemented, or the authentication method is extremely sensitive to the URL you use to get the cookies. The absolute URL to the file I was attempting to copy down looks something like this:

 

https://mycompany.sharepoint.com/customers/theclientname/797%20Project%20Name/In%20Process%20Templat...

 

This URL is a valid site:

https://mycompany.sharepoint.com/customers/theclientname

 

But when I used that URL with AuthenticationManager.GetWebLoginClientContext(), it failed. Switching it to use:

https://mycompany.sharepoint.com

to get the client context fixed the problem. Now, if permissions were different at these different levels, I suspect this would have failed - it would have gotten a valid client context, but suspect I could still have gotten a permissions error when trying to use OpenBinaryStream() on my file object.

 

This was a frustrating journey, and I was disappointed to not get any feedback from anyone else. Apparently my limited understanding of SharePoint and how to integrate to it is not as common as I thought it might be.

Highlighted

@dougb628 I'm glad you continued to add comments here as I was having the same issues.  Someone reported this as a bug in December 2019, however it is not fixed yet, https://github.com/pnp/PnP-Sites-Core/issues/2508

 

Though we all are seeing the same behavior, the underlying causes are different.  The reporter of the bug found the error when using a SharePoint Add in and his work around was to add another cookie to the list of cookies it attempted to find.  Your issue was that it wasn't providing a cookie that was in fact there.  My issue is that it freezes on the browser.Navigated call. I get pop-up browser window, but when debugging it never drops into the code under browser.Navigated.  I have no fix at the moment.  This behavior is intermittent, it will work once and then not work again until my app is closed and reopened.  No exception occur and even when I step into the browser.Navigated call, it actually looks like it just skips over the call and goes to the next line.

Highlighted

@kirstenrayI hope this gets resolved soon, but I actually haven't really done much with this once I got it working by just using the domain name. In our case, all of the users of this C# application have essentially the exact same access all over our SharePoint, so I think that is why it started working for me. Frankly, I still don't know that much about integrating to SharePoint, and I think it's pretty crazy that you have to launch a browser to authenticate. Granted, it is a web application, but the authentication from the OS is much more streamlined. I can open a Windows File Explorer window, and type in a SharePoint address in the address bar, and it authenticates completely transparently, probably using Kerberos or something - I don't know. Why can't my C# application authenticate in a similar manner?