1

On old created Office 365 tenants I use to authenticate to SharePoint online inside our C# console application using this code:

static void Main(string[] args)
{
               
    string siteUrl = "https://***.sharepoint.com/sites/CustomerServiceKB/";
    string clientId = "******";
    string clientSecret = "*****";
    using (ClientContext context = new OfficeDevPnP.Core.AuthenticationManager().GetAppOnlyAuthenticatedContext(siteUrl, clientId, clientSecret))
    {
       ...
    }
}

But, as per my knowledge newly created Office 365 tenants has SharePoint app-only permissions disabled.

So will my above code fail to work if the SharePoint app-only permissions is disabled inside our newly created tenant?

Edit

now based on the reply i got from @Asad >> he linked me to this blog >> https://sharepointstew.wordpress.com/2021/07/07/app-only-authentication-in-sharepoint-online-using-latest-azure-sdk/ >> but this blog is using PnP.Framework.AuthenticationManager which is based on this link @ https://www.nuget.org/packages/SharePointPnPCoreOnline is deprecated as well... so how i can authenticate my .net core console application to SharePoint using non-deprecated approach? i feel that i will never get an answer ..

3
  • 1
    Did you register an app in new o365 tenant? Also, if you are not able to use this authentication method, you can check other authentication methods in this documentation. Aug 17, 2021 at 5:46
  • @GaneshSanap my code did not work.. and i think this is because in our tenant the DisableCustomAppAuthentication is set to Yes... i know that i can set it to false but i do not want to modify our tenant settings as we need to keep the setting most secured..
    – John John
    Aug 17, 2021 at 9:03
  • @GaneshSanap can you check my edit please
    – John John
    Aug 26, 2021 at 16:12

1 Answer 1

1

I would advice you to check DisableCustomAppAuthentication property on your tenant. If it's set to True then your code will throw Unauthorised error.

Use below commands to enable authentication using client ID and client Secret.

Set-SPOTenant -DisableCustomAppAuthentication $false

Or alternatively, you can run this PnP commandlet:

Set-PnPTenant -DisableCustomAppAuthentication $false

Refer blog for more details: https://www.koskila.net/literally-breaking-changes-to-app-authentication-on-sharepoint-%F0%9F%98%B5/

15
  • 1
    You have option to use App Registration with Certificates. Have a look at my blog sharepointstew.wordpress.com/2021/07/07/…
    – Asad Refai
    Aug 17, 2021 at 9:47
  • 1
    @johnGu It will work in Console App also. If you see the blog has code for .NetCore Console App as well.
    – Asad Refai
    Aug 17, 2021 at 13:12
  • 1
    Not sure if self signed certificates can't be used on Production environment. If the server admin is happy to create the certificate, then it's fine to use. If you are not having Azure to store certificate. Then store it somewhere is file system. This link has sample code (written in old deprecated Nuget packages) docs.microsoft.com/en-us/sharepoint/dev/solution-guidance/…
    – Asad Refai
    Aug 17, 2021 at 14:18
  • 1
    This should be something else. Creating an App Registration is not deprecated but a recommended approach.
    – Asad Refai
    Aug 17, 2021 at 14:25
  • 1
    I am not using SharePointPnPCoreOnline as it is deprecated. I am using latest cross platform PnP.Framework
    – Asad Refai
    Aug 27, 2021 at 6:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.