-
Notifications
You must be signed in to change notification settings - Fork 148
Cannot lock down API when emulating auth locally - Blazor stack #390
Copy link
Copy link
Open
Labels
os: unixIssues happened on a Unix-like environmentIssues happened on a Unix-like environmentpriority: low (P2)Low priorityLow priorityruntime: dotnetIssues related to the .NET runtime (API)Issues related to the .NET runtime (API)scope: authIssues related to the authentication emulatorIssues related to the authentication emulatorscope: mshaIssues happened a the ./src/msha levelIssues happened a the ./src/msha levelscope: rules engineSpecific issues related to src/msha/routes-engine/**Specific issues related to src/msha/routes-engine/**status: investigatingThe team is investigating the issuesThe team is investigating the issuesstatus: regression bugThis is a regression bug. NOTE: regression bugs need to have more coverage tests.This is a regression bug. NOTE: regression bugs need to have more coverage tests.status: release-blockerIssues blocking a major releaseIssues blocking a major releasetype: bugSomething isn't workingSomething isn't working
Milestone
Description
Metadata
Metadata
Assignees
Labels
os: unixIssues happened on a Unix-like environmentIssues happened on a Unix-like environmentpriority: low (P2)Low priorityLow priorityruntime: dotnetIssues related to the .NET runtime (API)Issues related to the .NET runtime (API)scope: authIssues related to the authentication emulatorIssues related to the authentication emulatorscope: mshaIssues happened a the ./src/msha levelIssues happened a the ./src/msha levelscope: rules engineSpecific issues related to src/msha/routes-engine/**Specific issues related to src/msha/routes-engine/**status: investigatingThe team is investigating the issuesThe team is investigating the issuesstatus: regression bugThis is a regression bug. NOTE: regression bugs need to have more coverage tests.This is a regression bug. NOTE: regression bugs need to have more coverage tests.status: release-blockerIssues blocking a major releaseIssues blocking a major releasetype: bugSomething isn't workingSomething isn't working
Type
Fields
No fields configured for issues without a type.
Are you accessing the CLI from the default port
:4280?:4280Describe the bug
I cannot get API authentication working when running locally. It's possible I'm missing something in my setup, but I've read and searched documentation and haven't hit upon a solution. I'm running blazor wasm client side with a C# function api. Running the emulator and I can login and see the proper roles listed when I go to .auth/me. Client side authentication using Microsoft.Azure.Function.Authentication.WebAssembly package works fine. Pages properly authenticate using the
Authorizeattribute and views seem to properly respond to the authenticated state. The problem comes when trying to lock down the API.My first attempt was to put the AllowedRoles in a route.
This doesn't seem to do anything in the emulator. I can still see the calls being successfully made from the client side even when I'm not logged in.
I then moved on in my exploration and went to inspect what headers I'm getting in my api function. And I do not see any auth information. I made a test function to simply spit out all the headers and the
x-ms-client-principalheader is not present even when I make the call from an authenticated state.Note that this all works perfectly fine when I'm actually running on Azure in a real static web app.
What am I missing? I really love the concept of being able to develop all of this locally, but trying to set this up has been kind of frustrating.
To Reproduce
Steps to reproduce the behavior:
swa start http://localhost:5000 --run "dotnet run --project Client/Client.csproj" --api-location Apiawait Http.GetFromJsonAsync<WeatherForecast[]>("/api/WeatherForecast") ?? new WeatherForecast[]{};Expected behavior
I would expect to be able to get/create the ClaimsPrincipal using the information found here: (https://docs.microsoft.com/en-us/azure/static-web-apps/user-information?tabs=csharp#api-functions)
Screenshots
If applicable, add screenshots to help explain your problem.
Desktop (please complete the following information):
Running SWA CLI version 0.8.2