Sharepoint - App Only Authentication

Larissa Lima 0 Reputation points
2023-03-30T20:35:54.5433333+00:00

Hey, guys. I'm making a code to get a pptx file from Sharepoint. I'm using app-only, I gave the api rights but nothing works. Has anyone dealt with this?

User's image

Microsoft 365 and Office | SharePoint | For business | Windows
Developer technologies | C#
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. RaytheonXie_MSFT 40,471 Reputation points Microsoft External Staff
    2023-03-31T02:59:11.5466667+00:00

    Hi @Larissa Lima,

    Per my test, I can access my site by following code

    string siteUrl = "https://contoso.sharepoint.com/sites/demo";
    using (var cc = new AuthenticationManager().GetACSAppOnlyContext(siteUrl, "[Your Client ID]", "[Your Client Secret]"))
    {
        cc.Load(cc.Web, p => p.Title);
        cc.ExecuteQuery();
        Console.WriteLine(cc.Web.Title);
    };
    
    

    Here is the test result

    User's image

    To grant permissions, I used the followig xml and get the full control of the site

    
    <AppPermissionRequests AllowAppOnlyPolicy="true">
      <AppPermissionRequest Scope="http://sharepoint/content/sitecollection" Right="FullControl" />
    </AppPermissionRequests>
    
    

    Here is the document for more details

    https://learn.microsoft.com/en-us/sharepoint/dev/solution-guidance/security-apponly-azureacs


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.