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
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.
Static Web App: SWA Auth Check
Clone this repository locally and open in vscode.
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.