0

What is the equivalent of the Farm Solution command to elevate privileges in the Sharepoint Online (Office 365) environment?
In Farm Solution for Sharepoint on-premise, in server-side languages like C#, we use

SPSecurity.RunWithElevatedPrivileges
or we use the system account token
new SPSite(weburl, SPUserToken.SystemAccount))

BUT what we can use in a Sharepoint-Addin developed for Sharepoint Online (without server side code, so with a client side language like Javascript)? If an equivalent exists.

3
  • I am considering the Sharepoint-hosted add-ins because they don't need a separate server to run code (all the code is in Javascript).
    – Piero
    May 6, 2016 at 8:09
  • If you COULD elevate permissions client-side, then any Browser Extension could listen in and execute whatever they want... WOULD you want that? May 6, 2016 at 13:52
  • Yes sure you would NOT. These are my same thoughts. I'm double checking with you all.
    – Piero
    May 9, 2016 at 13:29

2 Answers 2

0

How bad does it stink that you can’t elevate to the application pool account in Office 365. It used to make things like cross site reads so much easier but from a security perspective totally makes sense it doesn’t exist. There really is no delegated replacement

you can make the process slightly less painless by using the relevant objects within an extension method off a ClientContext object. Here is the extension method:

public static ClientContext BuildImpersonatedClientContext(this ClientContext context, string username, string password)
{
SecureString secureStrPwd = new SecureString();
foreach (char x in password)
{
secureStrPwd.AppendChar(x);
}
SharePointOnlineCredentials credentials = new SharePointOnlineCredentials(username, secureStrPwd);
context.Credentials = credentials;
return context;
}

To use the method, just invoke it as such:

ClientContext impersonatedContext = new ClientContext("MyUrl").BuildImpersonatedClientContext("user", "password");

http://www.sharepointsecurity.com/sharepoint/sharepoint-development/runwithelevatedprivileges-in-sharepoint-online-office-365/

1
  • Thank you. This is a CSOM-C# equivalent and it is suited as a "remote server side code" running on a provider-hosted Add-in. In my question I am considering a Sharepoint hosted - Sharepoint Add-in with no server-side code. So, could we write a Javascript equivalent?
    – Piero
    May 6, 2016 at 8:01
0

For SharePoint Addin, you need to given appropriate permissions rights like tenant, site collection, web etc. In your Addin you need to use app-only context while connecting to SharePoint, in this way you can elevate the privileges.

1
  • Yes but SharePoint hosted add-ins do not support app-only or add-in only permissions.
    – Piero
    May 6, 2016 at 8:08

Your Answer

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

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