Access the Azure Static Web Apps ClientPrincipal

Share this post

As part of a recent pull request for the Azure Static Web Apps CLI, I needed to test that the changes did not affect the emulated authentication functionality of the CLI.

To help me test authentication emulation I thought I would create a basic demonstration app.

Azure Function App: Auth Echo

The auth-echo Azure Function app can be found on GitHub.

This git repository includes container development files which means you can easily open and debug the code in a GitHub Codespaces repository.

For this article, we will work with the repository in a GitHub Codespace, accessed via vscode, but you should be fine to clone and open the repository in vscode locally.

Once you codespace is open in vscode, launch the function app by pressing ‘F5’. This will trigger installation of all dependencies, building and then running the app with the Azure Functions emulator. The app will listen on port 7071. This port will also be forwarded by vscode to your localhost.

The list of ports in vscode shows that port 7071 has been forwarded to localhost

Static Web App: SWA Auth Check

The swa-auth-check Static Web App can be found on GitHub.

Clone this repository locally and open in vscode.

Install the SWA CLI.

At a terminal in the project’s root folder, run npm install to download any dependencies.

Once all dependencies are downloaded run the following to launch swa-auth-check using the SWA CLI:

					swa start --api-location http://localhost:7071

In your browser, visit http://localhost:4280.

Using SWA Auth Check

SWA Auth Check can be used to examine the claims accessible to client-side and server-side code when dealing with SWA authentication.

Try signing in and out of the app, using the emulated authentication service provided by SWA CLI, and examine the claims retrieved when clicking the Read /.auth/me and Read /api/authecho buttons.

Share this post

Daniel Watford

Daniel Watford

A Software Consultant with over 20 years experience building solutions to help organisations solve problems and improve their business processes with both bespoke software and off-the-shelf IT.