PnP Core SDK - ASP.NET Core Sample
This solution demonstrates how the PnP Core SDK can be used in a ASP.NET Core web application
Source code
You can find the sample source code here: /samples/Demo.ASPNetCore
Run the sample
Register and configure an AAD app
In order for the user to authenticate on the App, A new app registration should be created on Azure Portal
In App registrations, click New registration
Enter a name for your new app, make sure Accounts in this organizational directory only is selected. As the Redirect URI, in Web platform enter https://localhost:44336/signin-oidc (The port may vary according to your Visual Studio)
Under Implicit grant section, check ID tokens
Go to API permissions section , click Add a permission
- Select Microsoft Graph > Delegated permissions > select Directory.Read.All
- Select Microsoft Graph > Delegated permissions > select User.Read
- Select Microsoft Graph > Delegated permissions > select Sites.Read.All
- Select Microsoft Graph > Delegated permissions > select Files.Read.All
- Select SharePoint > Delegated permissions > select AllSites.Read
- Select Azure Active Directory Graph > Delegated permissions > select Directory.Read.All
- Select Azure Active Directory Graph > Delegated permissions > select User.Read
Click Grant admin consent for {tenant}
Go to Certificates & Secrets and register a new client secret.
From Overview, -- copy the value of Directory (tenant) ID -- copy the value of Application (client) ID
Configure your application
- Configure the name of your tenant as the value of
AzureAd:Domain
in appsettings.json setting - Configure the Tenant ID of your app as the value of
AzureAd:TenantId
in appsettings.json setting - Configure the Client ID of your app as the value of
AzureAd:ClientId
in appsettings.json setting - Configure the Client Secret of your app as the value of
AzureAd:ClientSecret
in appsettings.json setting - Configure the URL of the target "modern" team site as the value of
PnPCore:Sites:DemoSite:SiteUrl
in appsettings.json setting
Be sure to have a Team in Microsoft Teams backing the modern team site in the above site collection
Execute
Hit F5 in Visual studio to execute the ASP.Net Core app. When trying to access one of the sections, the applications prompts you for signing in.