Enable B2B scenarios and support custom claims from SWA auth jwt in policies #2809
Replies: 1 comment
-
We briefly discussed the idea of using roles to hold the company and route people. Doing this would require passing the additional user role to the policy for query transformation and/or creating a policy per role with a hardcoded transformation string, requiring reload of a very large config file. So I considered what if the databases were segregated by company rather than the rows being segregated by company. I was thinking this could work with database segregation, ie, programmatically generating a child config for a role so we could end up with:
{
"data-source-files": [
"dab-config-contoso.json",
"dab-config-tailwind.json"
],
"runtime": {
"rest": {
"enabled": true
} }}
{
"data-source": {
"database-type": "cosmosdb_nosql",
"connection-string": "@env('COSMOS_CONNECTION_STRING')",
"database-name": "contoso",
},
"entities": {
"Book": {
"source": { "object": "dbo.Books" },
"permissions": [
{ "role": "contoso", "actions": [ "*" ] }
]}}}
{
"data-source": {
"database-type": "cosmosdb_nosql",
"connection-string": "@env('COSMOS_CONNECTION_STRING')",
"database-name": "tailwind",
},
"entities": {
"Book": {
"source": { "object": "dbo.Books" },
"permissions": [
{ "role": "tailwind", "actions": [ "*" ] }
]}}}
graph TD;
U[User] -->|Authenticated| FE[Front-end];
FE --> |Creates route client| DAB;
DAB --> |Uses route| DB[Customer specific DB];
However, reading some of the docs, there are some barriers to this:
|
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Per the docs Accessing user information in Azure Static Web Apps - Client principal data custom auth providers can provide additional claims.
We're currently looking at this as a route to support Microsoft Entra with exposed additional fields to support a B2B scenario which will involve filtering on a Company claim as well as user ID to determine what item-level records users can interact with. We considered roles but it seems impractical to create new roles and routes with hardcoded filters whenever a new customer is onboarded.
The current SWA auth helper object drops the additional claims portion of the client principal. It would be great it the custom claims became consumable
data-api-builder/src/Core/AuthenticationHelpers/StaticWebAppsAuthentication.cs
Line 28 in 8ea24db
e.g.
enabled a policy like
@item.companyId in @claims.groups
Beta Was this translation helpful? Give feedback.
All reactions