USMC6072
USMC6072

Reputation: 668

Connect to Sharepoint Online with Pnp Framework

I can't authenticate with Sharepoint online from my c# app. I've spent a couple days reading online and trying code. I keep getting a 403 Forbidden error. Here's what I've done so far to configure the environment:

I created my code based on this article https://michaelmaillot.github.io/articles/20210125-azure-function-authentication-with-pnpframework/. Scroll down to "Setup connection with a certificate (optional)" The only difference is, I'm not getting my cert from Azure Keyvault.

            try
            {
                var authManager = new AuthenticationManager(clientId, certLoc, "MyPassword", "<Tenant Name>.onmicrosoft.com");
                using (var cc = authManager.GetContext(siteUrl))
                {
                    cc.Load(cc.Web, p => p.Title);
                    cc.ExecuteQuery();
                    Console.WriteLine(cc.Web.Title);
                };
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

at the step cc.ExecuteQuery(); it get a 401 error response.

I found code to test my cert password and I am using the correct one.

I thought it was something not registered with AAD. Reading online talks about add the app to AAD that is separate from Registering the app. I don't have direct access to an AAD admin (company is too big) so I submitted a request for my app to be added as an SPN which I got a reply "SPN already exists".

I'm missing something in my configuration. I appreciate any ideas.

Upvotes: 1

Views: 1966

Answers (0)

Related Questions