Files

Azure SDK samples for Electron (TypeScript)

This sample application shows how to use the TypeScript client libraries for Azure in some common scenarios.

In this sample, we build a simple Electron application and integrating with various Azure services.

  • Integration with Azure Service Bus to support a single instance publishing and receiving Service Bus messages.
  • Integration with Azure Storage Blob for persisting notes.

Prerequisites

The samples are compatible with LTS versions of Node.js.

Before running the samples in Node, they must be compiled to JavaScript using the TypeScript compiler. For more information on TypeScript, see the TypeScript documentation.

You need an Azure subscription and the following resources created to run this sample:

  • An Azure Service Bus namespace and queue. Please refer to the ServiceBus documentation for additional information on Service Bus.
  • An Azure Storage Blob container. Please refer to the Storage Blob documentation for additional information on Azure Storage Blob. This file will be fetched from Azure Storage Blob and displayed on the screen.
  • Finally, you'll need a way to authenticate the application with Azure. Please refer to the @azure/identity package for information on authentication. The instructions below will walk you through the necessary steps.

To quickly create the needed resources in Azure and to receive the necessary environment variables for them, you can deploy our sample template by clicking:

The above template will create the necessary resources for you and the output tab will contain the exact environment variables that you'll need as soon as deployment succeeds. When the deployment is finished, head over to the "outputs" tab and copy the outputs to a local file - you'll need them in the next step.

Register a new application in AAD and assign the "Azure Service Bus Data Owner" and "Azure Storage Blob Data Contributor" role to it.

Authentication will still need to be set-up manually using the following instructions:

For Electron we also need to configure platform settings correctly, and we will use msal:// as the custom scheme. To set that up in your app registration:

  1. Click on Authentication in the app registration side bar
  2. Select "Add a platform"
  3. Select "Mobile and Desktop Application"
  4. In the "Custom redirect URIs" field please enter: msal://redirect
  5. Click "Configure"

In your app registration, you will also need to add a permission for the Microsoft.ServiceBus and Azure Storage apps. When adding permission for Microsoft.ServiceBus and Azure Storage, the type should be delegated permissions and the permission should be user_impersonation.

Finally, as mentioned in the header you'll need to make sure your application has the "Azure Service Bus Data Owner" and the "Azure Storage Blob Data Contributor" roles assigned to it. Please refer to the Service Bus Role Assignment and Azure Storage Role Assignment for up-to-date instructions on how to configure those.

Running the sample

Once the above steps are completed you'll want to ensure Electron has the necessary constants defined. To do this, open src/constants.ts and provide the necessary values to configre the application. Only empty strings need to be replaced with actual values.

Install the various packages as well as the TypeScript compiler using:

npm install

Run the sample app:

npm start

A new electron window will open containing a single Log In button. Once you login you'll be able to send and receive Service Bus messages as well as fetch and display a text file from Azure Blob Storage.

Next Steps

Take a look at our API Documentation for more information about the APIs that are avaiable.