# Sharepoint Custom Application APP Authentication

---

**❗DEPRECATED: Do not use❗**

Back to [SharePoint Integration Link](SharePoint-Integration.md)

---

**⚠️ Constraint:** On newer Sharepoint (after 2019) Grant App permission as it is disabled by default. To enable Custom Application APP Authentication run the following PowerShell commands:

```
Install-Module -Name Microsoft.Online.SharePoint.PowerShell
$adminUPN="<SharePoint administrator account>"
$orgName="<name of your Office 365 organization>"
$userCredential = Get-Credential -UserName $adminUPN -Message "Type the password."
Connect-SPOService -Url https://$orgName-admin.sharepoint.com -Credential $userCredential
get-spotenant | Select DisableCustomAppAuthentication
set-spotenant -DisableCustomAppAuthentication $false
```

Or

```
$creds = Get-Credential
$orgName="<name of your Office 365 organization>"
Connect-SPOService -Url https://$orgName-admin.sharepoint.com -Credential $creds
get-spotenant | Select DisableCustomAppAuthentication
set-spotenant -DisableCustomAppAuthentication $false
```

**Advantage(Compared with MSGraph API Delegated Permission)**: Stream upload supported. There is no temporarily stored local file during the upload.

**1. Register Add-In**\
Navigate and log in to the SharePoint online site. Got to the Register Add-In page by entering the URL as:

```
https://<sitename>.sharepoint.com/<<site path>>/_layouts/15/appregnew.aspx
```

Click the Generate button.

![App reg new](SharePoint-Integration/app_reg_new.png)

Store the **Client ID** and **Client Secret** and click on **Create** button.

![App reg new success](SharePoint-Integration/app_reg_new_success.png)

**2. Grant Permissions to Add-In**

Navigate to:

```

 https://<sitename>.sharepoint.com/<<site path>>/_layouts/15/appinv.aspx
 
```

This will redirect to the Grant permission page. Enter the **Client ID**(generated earlier), in the **AppId** textbox and click the Lookup button.\
Provide the permission Request xml and click on **Create** button.

Permission Request XML content:

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

![App inv permission](SharePoint-Integration/app_inv_permission.png)\
**SharePoint2 remote item settings:**

**User name** : The created **Client ID**\
**Password** : The created **Client Secret**\
**Site id** : The SharePoint domain name.\
**Site Path**: The path of the SharePoint site. It should start and end with a slash.\
**Drive name**: Each SharePoint site has a Document Library where the site-related files are stored. See [SharePoint: Documents and Libraries Description Link](https://support.microsoft.com/en-us/office/what-is-a-document-library-3b5976dd-65cf-4c9e-bf5a-713c10ca2872) Provide its name\
**Folder**: Relative path of the document library of the SharePoint site.

![Sharepoint 2 vfs](SharePoint-Integration/sharepoint2_vfs.png)
