Skip to content

Understand identity and access in Cratis Arc

Cratis Arc separates identity enrichment from operation authorization and tenant isolation. Use identity details to give the UI context about the signed-in user, authorization to decide which commands and queries that user may run, and tenant membership checks plus tenant-aware storage to control whose data those operations use.

The boundaries below apply across backends, but authentication middleware, role metadata, and tenant enforcement are host-specific. API names and configuration links in the prose use C#; the example tabs also show JVM and TypeScript forms. For those hosts, continue with JVM security or TypeScript identity and authorization. Go has separate identity and authorization guides. Check the HTTP contract and each backend’s capability reference for status-code and enforcement differences.

Who is the user — identity, enriched once

Section titled “Who is the user — identity, enriched once”

Authentication establishes who the caller is. In C#, that identity is represented by a ClaimsPrincipal, the server-side user object containing claims such as an id, a name, and roles. Identity enrichment adds application details, such as a display name or preferences, so the UI can show information relevant to that user.

In C#, implement IProvideIdentityDetails<TDetails> to supply those details. Arc passes an IdentityProviderContext containing the user’s id, name, and claims, rather than the raw token. In this illustrative MongoDB fragment, the provider looks up a library member by that id. It assumes application-owned Member and LibraryIdentity types and the identity/provider imports:

public class LibraryIdentityProvider(IMongoCollection<Member> members)
: IProvideIdentityDetails<LibraryIdentity>
{
public async Task<IdentityDetails> Provide(IdentityProviderContext context)
{
// Look the user up in your own data, keyed by the provider's id.
var member = await members.Find(m => m.Subject == context.Id.Value).FirstOrDefaultAsync();
if (member is null)
return new IdentityDetails(false, LibraryIdentity.None); // /.cratis/me rejects this result
var identity = new LibraryIdentity(member.Id, member.Role, member.Name);
return new IdentityDetails(true, identity);
}
}

View C# snippet source on GitHub

no

yes

Authenticated principal → identity context

IProvideIdentityDetails.Provide()

IsUserAuthorized?

/.cratis/me returns 403

IdentityDetails — your domain identity

/.cratis/me response

Frontend — typed identity

If the member is missing, the provider returns IdentityDetails with IsUserAuthorized: false, and /.cratis/me responds with 403. That decision applies to the identity-details response. Command and query authorization evaluates the principal and operation declarations independently, so rejecting identity enrichment does not block the user’s operations. Enforce restrictions such as blocked accounts or expired subscriptions on those operations too.

When the provider accepts the member, /.cratis/me returns the details for the frontend to consume through a generated identity type. Use the identity provider flow and identity contracts to implement the backend, then read identity in React to use those details in the UI.

What can they do — authorize commands and queries

Section titled “What can they do — authorize commands and queries”

Authorization decides whether the caller may run an operation before its command or query logic executes. In this MongoDB excerpt, registering an author requires the Librarian role, while reading the public catalog allows anonymous callers. The excerpt uses the tutorial’s domain types and provider setup plus Cratis.Arc.Authorization imports. LibraryRole names the application’s roles for nameof, as recommended by the ARC0011 role-name analyzer:

public enum LibraryRole { Librarian } // the application's role names, in one place
[Roles(nameof(LibraryRole.Librarian))] // only a Librarian may register an author
[Command]
public record RegisterAuthor(AuthorId Id, AuthorName Name)
{
public Task Handle(IMongoCollection<Author> authors) =>
authors.InsertOneAsync(new Author(Id, Name));
}
[ReadModel]
public record Author(AuthorId Id, AuthorName Name)
{
[AllowAnonymous] // the public catalog is open to everyone
public static ISubject<IEnumerable<Author>> AllAuthors(IMongoCollection<Author> c) => c.Observe();
}

View C# snippet source on GitHub

In C#, [Authorize] requires an authenticated user. [Roles("Librarian", "Admin")] also requires authentication and accepts at least one of the listed roles. [AllowAnonymous] permits callers without signing in. The role name must match a role in the authenticated principal; declaring an enum member does not assign that role to anyone.

For queries, a class-level declaration covers methods without their own declaration. A method-level declaration replaces the class-level requirements. Use this deliberately when making a query public or giving it a different role requirement.

Authentication can stop an HTTP request with 401 before Arc runs. If Arc’s command or query pipeline rejects authorization, the HTTP response is 403, and the generated command/query result reports isAuthorized: false so the UI can respond.

Some rules depend on the data being accessed: a user may edit their own profile but not another user’s. Check that relationship on the server against the trusted principal and the target record, using an authorization extension or an explicit operation guard. An ordinary validation rejection is a different result from an authorization rejection. Continue with authorization attributes, policies, and inheritance rules to choose the right check.

A tenant is a customer or organization whose data your application keeps separate from others in the same deployment. A user may have permission to register authors without having permission to register them for every tenant. Operation authorization and tenant membership answer different questions.

A host selects a tenant id through a resolver, which reads a configured source such as a claim or header. A header resolver reads the supplied value; authenticating the caller first does not prove that the caller belongs to the tenant they selected. On C#, register an application-owned ITenantMembership check to verify that relationship during request tenant resolution, or enforce membership at a trusted ingress (a proxy or gateway) before the request reaches the app. Arc does not automatically enforce membership without a registered check. The tenant membership guide explains registration and the check’s scope.

Storage isolation is a separate responsibility. Tenant-aware database routing, partitions, or application query filters must keep an allowed operation within the selected tenant’s data. Resolving a tenant id does not add filters to every query or make every store tenant-aware. Verify both boundaries: a caller cannot select a tenant they do not belong to, and an allowed request cannot read or change another tenant’s data.

Choose how requests select a tenant with tenant resolvers, then use tenant context to read the selected id in application services. For MongoDB, database resolvers route storage by tenant. The tenancy overview connects these choices.

If a trusted ingress supplies the caller’s identity, follow Microsoft Identity headers to configure the x-ms-client-principal header family. These headers carry unsigned assertions, not bearer tokens validated by Arc. The ingress must replace spoofable headers and prevent direct backend access. The host must opt in with TrustForwardedIdentityHeaders before Arc trusts them. For local-only fixtures, see Generate a principal.