Sunday, July 21, 2019

Working Mechanism of Provider Hosted Apps in SharePoint


Mechanism of Provider Hosted Apps in SharePoint
 ----------------------------------------------------

The code for provider hosted app lies in remote web. Remote web is a web application that is hosted outside SharePoint server. For on prem installations one needs to set up high trust between SharePoint and remote web using certificates.

·         How should we call the web services for Provider hosted app?
As remote web and SharePoint host site collection lie in different domains you need to use cross domain library (SP.RequestExecutor) to make cross domain calls to SharePoint host site collection using REST APIs.

I’ll start with some briefing on OAuth and the key concepts that we need to understand about OAuth. OAuth is the internet protocol for creating and managing app identity. It is also a cross-platform mechanism for authentication and authorizing apps. The OAuth is also the emerging internet standard which is used by Facebook, Twitter and Google.
OAuth gives the power and flexibility of having app identity in addition to the user identity. Here are the some pointers about App Identity
  • App should be granted permissions independently of user permission
  • App can request specific permission from the user during installation
  • App can be granted more permission than the user (Elevation)
  • App is constrained to what it can do during and after installation
Here are some important concepts around OAuth
1. Content Owner – User who grants permission to content in a site
2. Client App – This is the remote App (running on a Cloud or Hosted environment) that needs permission to Site Content . In our case it is SharePoint 2013 App
3. Content Server – The web server that serves the content to be accessed by App. In our case it is SharePoint 2013 Server (Cloud or On-Premise)
4. Authentication Server – Trusted server that authenticates apps and creates oAuth tokens. In our case it is Azure ACS server or oAuth compatible authentication server
















Let’s see what is happening in each step in the above picture.

Step 1 –> The user accesses the SharePoint 2013 portal and SharePoint 2013 authenticates the user using Claims Authentication
Step 2 –> SharePoint 2013 requests for the Context Token for the user, from Windows Azure ACS (Access Control Services)
Step 3 –> ACS returns Context Token
Step 4 –> SharePoint 2013 passes the Context Token to the user
Step 5 –> User accesses App using Context Token
Step 6 –> Client App pulls Refresh Token from the Context Token and requests ACS for oAuthToken
Step 7 –> ACS server returns OAuth token to the client app
Step 8 –> Client App makes CSOM/REST calls to SharePoint site by passing OAuth Token
Step 9 –> SharePoint 2013 returns site content to App based on the App Permission Manifests
Step 10 –> Client App returns the App Content to the user


Thursday, July 4, 2019

Powershell to Download Pages from SharePoint Pages Library

Powershell to Download Pages from SharePoint Pages Library - SharePoint Onprem.


Run that below Powershell in SharePoint Management studio on SP Onprem server(SP 2010/2013)

Note -
Change the variable and run the powershell to get the output.

--------------------------------------------------------------------------------------------------------------------



$destination ="\\hamal\sOffice365Mig$\Mig\Download_Pages\RL_strategy"
$webUrl ="http://sharepoint.com"
$listUrl ="http://sharepoint.com/circles/RL%20Strategy%20and%20Plans/Forms/AllItems.aspx"
##############################################################


$web = Get-SPWeb -Identity $webUrl
$list = $web.GetList($listUrl)

function ProcessFolder {
    param($folderUrl)
    $folder = $web.GetFolder($folderUrl)
    foreach ($file in $folder.Files) {
        #Ensure destination directory
        $destinationfolder = $destination + "/" + $folder.Url
        if (!(Test-Path -path $destinationfolder))
        {
            $dest = New-Item $destinationfolder -type directory
        }
        #Download file
        $binary = $file.OpenBinary()
        $stream = New-Object System.IO.FileStream($destinationfolder + "/" + $file.Name), Create
        $writer = New-Object System.IO.BinaryWriter($stream)
        $writer.write($binary)
        $writer.Close()
        }
}

#Download root files
ProcessFolder($list.RootFolder.Url)
#Download files in folders
foreach ($folder in $list.Folders) {
    ProcessFolder($folder.Url)
}