I need to log into a SharePoint tenant using an admin account that uses MFA.
This is the code.
var authManager = new OfficeDevPnP.Core.AuthenticationManager();
var context = authManager.GetWebLoginClientContext(tenantUrl);
// load some stuff
// this will fail with 403 Unauthorized
context.ExecuteQuery();
The login window does pop up for a second, but closes again immediately. I assume that it uses the cookie for my regular user (without SharePoint administration rights). The following requests that need tenant scope obviously do not work.
How can I clear the token cache so I can log in with the correct user? In the PnP PowerShell I had the same problem with -UseWebLogin
, but there I can actually use the ClearTokenCache
parameter and then it works. I have not yet found a similar option here, and PowerShell is not an option.