Section 12 - Deploy the Function Apps
SPARK utilizes function apps to return data from the database for the user logged in. The authentication token is used to ensure only data returned is for the specified user.
Requirements
The Azure Administrator will be required for this step. The user must have:
- Owner role1 for the subscription
- Access to the Azure Portal
Security
The function app will utilize a public endpoint, but requires authentication from the SPARK application registration. The SPFx solution will request a token from the application registration which is used as the authentication to call the function app. The function app’s CORS configuration will also allow incoming requests from the SharePoint environment.
Step 1: Create Function App
- Browse and log into Azure Portal
Use the correct URL for your environment:
Worldwide (Commercial) & GCC
https://portal.azure.comGCC-High and DoD
https://portal.azure.us
- Enter function app in the top search navigation
- Click on Function App
- Click on Create
- Select the App Service option for hosting
- Click on Select
- Set the following properties and click on Next
| Name | Value |
|---|---|
| Resource Group | The resource group created in step 4 |
| Function App name | A unique name for the function app service (Example: sub-spark-fa) |
| Operating System | Windows |
| Runtime stack | PowerShell Core |
| Version | 7.4 |
| Region | Select the same region we have been doing |
| Pricing Plan | Basic B1 |
- Select the storage account created in step 9, and click on Next
- Review the network settings and configure as appropriate for your organization, and click on Next
- Review the monitoring settings and configure as appropriate for your organization
- Click on Next until you are at the Authentication tab
Enabling application insights may incur additional costs.
- Set the Authentication type to Managed Identity
- Select uami-spark-spoactions from the Managed Identity dropdown
- Click on Next until you are at Review + create
- Click on Create to create the function app
Step 2: Configure App Files
- Select App files under the Functions section in the left navigation
- From the file dropdown, select profile.ps1
- Reference the profile.ps1 file, copy the contents and save the changes
- Update the
profile.ps1script and set the default$AzureEnvironmentvalue to the appropriate cloud environment. This should be found around line 35. - From the file dropdown, select requirements.psd1
- Reference the requirements.psd1 file, copy the contents and save the changes
Step 3: Configure CORS
- Select CORS under the API section in the left navigation
- Add the v_spoRootUrl value from the variables spreadsheet to the CORS configuration
- Click on Save
This will allow api requests from the SharePoint environment.
Step 4: Configure Environment Variables
- Select Environment variables under the Settings section in the left navigation
- Add the following variables shown in the table below
- Click on Save
- Click on Apply at the bottom after all variables have been saved
| Name | Value |
|---|---|
| AzureEnvironment | The Azure environment for this tenant. Allowed values: Commercial USGovernment USGovernmentHigh USGovernmentDoD |
| ClientId | The v_clientId value from the variables spreadsheet The client id value of the UAMI |
| SubscriptionId | The v_subscriptionId value from the variables spreadsheet |
| SqlConnectionString | The v_sqlConnectionString value from the variables spreadsheet |
Step 5: Configure Identity
- Select Identity under the Settings section in the left navigation
- Click on the User assigned tab and validate that the uami-spark-spoactions identity is added
- If no identity is shown, click on Add and select the uami-spark-spoactions from the dropdown
- Click on Add
Step 6: Get appreg-spark-spoactions Information
- Refer to the appreg-spark-spoactions application registration
- From the Overview section, annotate the Client Id and Application ID URI values for the next step
Step 7: Configure Authentication
- Select Authentication under the Settings section in the left navigation
- Click Add identity provider
- Select Microsoft from the Identity provider dropdown
- Fill in the following properties
- Click on Add
| Name | Value |
|---|---|
| App Registration Type | Pick an existing app registration in this directory |
| Name or app ID | appreg-spark-spoactions |
| Client secret expiration | Configure based on your organization rules |
| Client Application Requirements | Allow requests from specific client applications |
| Allowed Client Applications | appreg-spark-spoactions Client Id SharePoint Online Web Client Extensibility Id: 08e18876-6177-487e-b8b5-cf950c1e598c Paste each guid as the value in the textbox |
| Identity Requirement | Allow requests from any identity |
| Tenant Requirement | Allow requests only from the issuer tenant |
- After the identity is added, click on Edit
- Set the Client secret setting name to –Remove value
- Set the Allowed Token Audiences value to the appreg-spark-spoactions application id uri
- Click on Save
Step 8: Create Functions
- Select Overview from the left navigation
- Reference the table below and repeat steps 3-5 for each file
- Click on Create under the Functions tab
- Copy and paste the content from the script file
- Click on Save
| Function Name | Authorization Level | File Reference |
|---|---|---|
| fx-spark-getallsites | Anonymous | fx-spark-getallsites |
| fx-spark-getsitecounts | Anonymous | fx-spark-getsitecounts |
| fx-spark-getsitesbyaction | Anonymous | fx-spark-getsitesbyaction |
| fx-spark-getsitesbykeyword | Anonymous | fx-spark-getsitesbykeyword |
| fx-spark-getsparksites | Anonymous | fx-spark-getsparksites |
| fx-spark-updatesparksites | Anonymous | fx-spark-updatesparksites |
Continue to creating the SharePoint Pages