Deprecated: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /www/collab365_296/public/wp-includes/functions.php on line 7025

Deprecated: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated in /www/collab365_296/public/wp-includes/functions.php on line 2162

Deprecated: Hook imagify_allow_picture_tags_for_webp is deprecated since version 2.2! Use imagify_allow_picture_tags_for_nextgen instead. in /www/collab365_296/public/wp-includes/functions.php on line 5758
Office 365 - SharePoint 2013 - Autoinstall an app at the time of creating a subsite - LoadAndInstallApp - Collab365
Deprecated: strstr(): Passing null to parameter #1 ($haystack) of type string is deprecated in /www/collab365_296/public/wp-includes/functions.php on line 1145

Deprecated: stripos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /www/collab365_296/public/wp-includes/functions.php on line 1152

Deprecated: stripos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /www/collab365_296/public/wp-includes/functions.php on line 1155

Deprecated: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /www/collab365_296/public/wp-includes/functions.php on line 1162

Deprecated: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /www/collab365_296/public/wp-includes/functions.php on line 1165

Deprecated: strstr(): Passing null to parameter #1 ($haystack) of type string is deprecated in /www/collab365_296/public/wp-includes/functions.php on line 1145

Deprecated: stripos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /www/collab365_296/public/wp-includes/functions.php on line 1152

Deprecated: stripos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /www/collab365_296/public/wp-includes/functions.php on line 1155

Deprecated: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /www/collab365_296/public/wp-includes/functions.php on line 1162

Deprecated: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /www/collab365_296/public/wp-includes/functions.php on line 1165

Warning: Undefined array key "url" in /www/collab365_296/public/wp-content/plugins/thrive-visual-editor/thrive-dashboard/inc/smart-site/classes/class-tvd-smart-shortcodes.php on line 85

2014-03-08

I was looking into the option of auto deploying an custom developed app at the time of creating a site in O365 / SP2013 environment.

Scenario:

1. Custom app (MVC – Azure hosted) – Need to deploy it automatically so that it can customise the site created using a site template. (i.e. attaches the remote event receiver to a list, site permission configuration, view changes etc).

2. Register and Deploy the app on the azure site using the Client Id and Client Secret. More details can be found at Chris O Brien’s blog – “Deploying SP2013 provider-hosted apps/Remote Event Receivers to Azure Websites (for Office 365 apps)”. It helped me lot in setting up my app and debugging as well.

Available API’s:  After a quick search, found the SPWeb.LoadAndInstallApp method – which is fine in my case as I have the .app for our custom developed app.

What happens when we click an installed app: SharePoint uses the appredirect.aspx page to call the app with the right access token, so that the app can validate and allows the user to access the app. We can also use the appredirect page as “https://SharePointServerName/_layouts/15/appredirect.aspx?client_id=<the app client Id>&redirect_uri=URL you want to redirect to” and more details can be found here.

Step1:

In my custom app, created a view to install the app (.app – published as a part of the app web project).

The above code initiates the deployment and redirects back to the site (SPHostUrl). This endpoint can be invoked using the appredirect page mechanism with the Apps Client Id.

Step2:  After creating the site, call the subsite page containing the below JS to install the app.

Javascript:

var url = String.format(
"{0}/_layouts/15/appredirect.aspx?client_id={1}&redirect_uri=https://***.azurewebsites.net/<<controller>>/<<view method containing the code to install the app>>?{{StandardTokens}}",
<<subsite url>>, "<<client id>>");

window.location.href = url;

The above javascript calls the appredirect.aspx page which then calls the app site as below,

https://***.azurewebsites.net/home?SPHostUrl=<<subsiteurl>>&SPLanguage=en-US&SPClientTag=1&SPProductNumber=**&SPAppWebUrl=<<weburl>>

 Note: The above can be extended to check for the successful installation of the app and display an error message accordingly.

SPWeb.LoadAndInstallWeb equivalent REST / Javascript CSOM is also available here.

 

(Visited 169 times, 1 visits today)

About the author 

Balamurugan Kailasam

Summit Bundle

Get 200+ hours of Microsoft 365 Training for 27$!

Master Office 365, Power Platform & SharePoint & Teams With 200+ Hours Of Training Videos and 108 Ebooks in the Collab365 Academy. This offer is insane and is only available for a limited period.