You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/solution-guidance/security-apponly-azuread.md
+63Lines changed: 63 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -1,10 +1,12 @@
1
1
# Granting access via Azure AD App-Only
2
+
2
3
When using SharePoint Online you can define applications in Azure AD and these applications can be granted permissions to SharePoint, but also to all the other services in Office 365. This model is the preferred model in case you’re using SharePoint Online, if you’re using SharePoint on-premises you have to use the SharePoint Only model via based Azure ACS as described in [here](security-apponly-azureacs.md).
3
4
4
5
> [!IMPORTANT]
5
6
> Azure Access Control (ACS), a service of Azure Active Directory (Azure AD), has been retired on November 7, 2018. This retirement does not impact the SharePoint Add-in model, which uses the `https://accounts.accesscontrol.windows.net` hostname (which is not impacted by this retirement). For more information, see [Impact of Azure Access Control retirement for SharePoint Add-ins](https://dev.office.com/blogs/impact-of-azure-access-control-deprecation-for-sharepoint-add-ins).
6
7
7
8
## Setting up an Azure AD app for app-only access
9
+
8
10
In Azure AD when doing app-only you typically use a certificate to request access: anyone having the certificate and its private key can use the app and the permissions granted to the app. Below steps walk you through the setup of this model.
9
11
10
12
You are now ready to configure the Azure AD Application for invoking SharePoint Online with an App Only access token. To do that, you have to create and configure a self-signed X.509 certificate, which will be used to authenticate your Application against Azure AD, while requesting the App Only access token. First you must create the self-signed X.509 Certificate, which can be created using the makecert.exe tool that is available in the Windows SDK or through a provided PowerShell script which does not have a dependency to makecert. Using the PowerShell script is the preferred method and is explained in this chapter.
@@ -208,6 +210,7 @@ In this sample the Sites.FullControl.All application permission require admin co
208
210

209
211
210
212
## Using this principal with PnP PowerShell
213
+
211
214
If you want to use this AAD App Only principal with [PnP PowerShell](https://github.com/SharePoint/PnP-PowerShell), after you have installed the PnP PowerShell module, you can connect to your SharePoint Online environment using:
212
215
213
216
```powershell
@@ -217,6 +220,7 @@ Connect-PnPOnline -ClientId <$application client id as copied over from the AAD
217
220
You can now perform operations through PnP PowerShell against your SharePoint Online environment using this certificate App Only trust.
218
221
219
222
## Using this principal in your application using the SharePoint PnP Sites Core library
223
+
220
224
In a first step, you add the SharePointPnPCoreOnline library nuget package: https://www.nuget.org/packages/SharePointPnPCoreOnline. Once that’s done you can use below code construct:
221
225
222
226
```csharp
@@ -241,6 +245,7 @@ namespace AzureADCertAuth
241
245
}
242
246
```
243
247
## Using this principal in your Powershell script using the PnP Sites core library
248
+
244
249
When making use of Azure Automation Runbooks, first add the certificate (.pfx) using the Certificates option (under Shared Resources), then use the Get-AutomationCertificate cmdlet to retrieve the certificate to be used in the script.
## Using this principal in your application and make use of the Azure KeyVault to store the certificate and retrieve it using an Azure Function
286
+
287
+
Add a [Managed Identity](https://docs.microsoft.com/en-us/azure/app-service/overview-managed-identity
288
+
) to the Azure Function and give this identity access (GET permission on Secrets) to the [KeyVault](https://docs.microsoft.com/en-us/azure/app-service/app-service-key-vault-references).
289
+
290
+
Below there is a slightly different call to the same GetAzureADAppOnlyAuthenticatedContext method where we pass an actual certificate instead of a path to the certificate. An extra function is added to retrieve to certificate from the KeyVault using the managed identity of the Azure Function, this retrieval is seamless and transparent since the 'magic' happens in the AzureServiceTokenProvider.
291
+
292
+
```csharp
293
+
staticvoidMain(string[] args)
294
+
{
295
+
using (varcc=newAuthenticationManager().GetAzureADAppOnlyAuthenticatedContext(
// 1. Create a KeyVault and upload the certificate
312
+
// 2. Give the Function App the permission to GET certificates via Access Policies in the KeyVault
313
+
// 3. Call an explicit access token request to the management resource to https://vault.azure.net and use the URL of our Keyvault in the GetSecretMethod
314
+
if (keyVaultClient==null)
315
+
{
316
+
// this token provider gets the appid/secret from the azure function identity
317
+
// and thus makes the call on behalf of that appid/secret
// The system cannot find the file specified.at System.Security.Cryptography.NCryptNative.ImportKey(SafeNCryptProviderHandle provider, Byte[] keyBlob, String format) at System.Security.Cryptography.CngKey.Import(Byte[] keyBlob, CngKeyBlobFormat format, CngProvider provider)
333
+
//
334
+
// Please see https://stackoverflow.com/questions/31685278/create-a-self-signed-certificate-in-net-using-an-azure-web-application-asp-ne
335
+
// Add the following Application setting to the AF "WEBSITE_LOAD_USER_PROFILE = 1"
336
+
}
337
+
338
+
339
+
```
340
+
280
341
## Using this principal with the Pnp Modernization Scanner
342
+
281
343
Now you have created the Azure Active Directory Application Registration, proceed with [following the steps here](https://docs.microsoft.com/en-us/sharepoint/dev/transform/modernize-scanner) to use this principal with the tool.
282
344
283
345
## FAQ
346
+
284
347
### Can I use other means besides certificates for realizing app-only access for my Azure AD app?
285
348
No, all other options are blocked by SharePoint Online and will result in an Access Denied message.
0 commit comments