web-app-starter icon indicating copy to clipboard operation
web-app-starter copied to clipboard

Forbidden exception when Client requests Todos

Open craig-blowfield opened this issue 1 year ago • 1 comments

Hi,

After following the setup instructions I am getting the following error from the Client when navigating to the Todo page after successfully authenticating

image

The bearer token is present.

On the API side I get the following log statement

image

Client Setup

App permissions look like this

image

My Client .env looks like this

VITE_PORT=3002
API_URL=http://localhost:5198
VITE_AZURE_CLIENT_ID={AppClientID}
VITE_AZURE_AUTHORITY=https://login.microsoftonline.com/{TenantID}
VITE_TODO_API_ENDPOINT_URL=http://localhost:3002
VITE_TODO_API_SCOPES_READ=["api://{ApiClientId}/ToDoList.Read"]
VITE_TODO_API_SCOPES_WRITE=["api://{ApiClientId}/ToDoList.ReadWrite"]

API setup

App reg expose permissions looks like this

image

And role looks like this

image

I have set API ClientID secrets to {ApiClientId} and and TenantID secret to {TenantID}

And the API launchSettings.json looks like this

{
  "$schema": "http://json.schemastore.org/launchsettings.json",
  "iisSettings": {
    "windowsAuthentication": false,
    "anonymousAuthentication": true,
    "iisExpress": {
      "applicationUrl": "http://localhost:42790",
      "sslPort": 44335
    }
  },
  "profiles": {
    "https": {
      "commandName": "Project",
      "dotnetRunMessages": true,
      "launchBrowser": true,
      "launchUrl": "swagger",
      "applicationUrl": "https://localhost:7253;http://localhost:5198",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    },
    "IIS Express": {
      "commandName": "IISExpress",
      "launchBrowser": true,
      "launchUrl": "swagger",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    }
  }
}

Maybe I have missed a setup.

Any help would be really appreciated

craig-blowfield avatar Jul 26 '24 12:07 craig-blowfield

Just debugged and the PermissionFilter is returning ForbidResult due to hasValidPermissions being false as my user claims does have the required permissions

image

Should me (user) have both valid permissions and scopes?

craig-blowfield avatar Jul 26 '24 13:07 craig-blowfield