Auth
Choose a Microsoft Entra sign-in path for Rayfin apps: Fabric SSO, direct Entra token exchange, external embed host, sessions, and dynamic claims.
Rayfin Auth gives your app managed Microsoft Entra sign-in, session handling, and token refresh.
After sign-in, client.data.* and client.functions.* calls use the authenticated context from the same client.auth instance.
Why use Rayfin Auth
- No separate identity provider to run — Rayfin Fabric apps use Microsoft Entra ID through Fabric SSO or delegated Entra token exchange.
- Pre-integrated SDK clients — once a session is installed on
client.auth, the client's registered services send the authenticated context automatically. - Per-user data isolation — JWT claims drive row-level security policies declared on your entities, including app-defined dynamic claims. See Permissions.
- One session API —
getSession,onSessionChange,refreshSession, andsignOutwork the same way no matter which supported flow installed the session.
Choose an auth path
| Situation | Use | Where it runs |
|---|---|---|
| A browser app needs Fabric to perform interactive sign-in | Fabric SSO popup flow | Any origin in services.auth.allowedRedirectUris, including http://localhost:5173 during local frontend development. |
| A Rayfin app is loaded inside the Fabric portal iframe | Fabric SSO embedded flow | The Fabric portal iframe. The embedded flow requires the app to be loaded by Fabric. |
| A React app needs shared session state and route guarding | React integration | Browser UI code, using the same client.auth instance as the SDK client. |
| Browser or Node.js code already has a delegated Entra token | Direct Entra token sign-in | Browser or Node.js. Requires Rayfin 1.36 or later and externalEntraExchange: true. New in 1.36 |
| Your own portal embeds a Rayfin app in an iframe | External embed host | Parent portal page plus the embedded Rayfin app. Requires Rayfin 1.36 or later and externalEntraExchange: true. New in 1.36 |
| UI code needs to react to sign-in, sign-out, or refresh | Sessions | Any frontend code that can access client.auth. |
| Entity policies need app-defined facts about the user, such as an account or region | Dynamic auth claims | A udf.authClaims function the backend calls at sign-in and refresh. New in 2.0 |
Microsoft Entra ID is the only supported identity provider for Rayfin Fabric apps. Do not add alternate sign-in UI to a new Rayfin app.
Note
The Fabric SSO popup flow works from a local dev server as long as the origin is listed in allowedRedirectUris, including http://localhost:5173.
Only the embedded iframe flow requires the app to be loaded inside the Fabric portal or by an external embed host.
Enable auth for browser apps
For Fabric SSO, enable the auth service and the Fabric provider in rayfin/rayfin.yml:
services:
auth:
enabled: true
allowedRedirectUris:
- http://localhost:5173
fabric:
enabled: trueRun npm run dev for the development loop.
Scaffolded projects run rayfin dev, which provisions or reuses the managed Fabric backend, applies auth settings, writes RAYFIN_PUBLIC_* values to rayfin/.env, maps them to framework variables such as VITE_FABRIC_ITEM_ID, then starts the frontend.
Use npx rayfin up when you want to deploy static hosting or update a deployed environment without starting the local frontend.
See Redirect URIs for what allowedRedirectUris controls.
Create a client with a browser session
Every sign-in flow installs its session on client.auth, which exists only when you create the client with browserSession() from @microsoft/rayfin-auth:
npm install @microsoft/rayfin-client @microsoft/rayfin-auth @microsoft/rayfin-auth-provider-fabric @microsoft/rayfin-dataimport { RayfinClient } from '@microsoft/rayfin-client';
import { browserSession } from '@microsoft/rayfin-auth';
import { dataService } from '@microsoft/rayfin-data';
import type { AppSchema } from '../../rayfin/data/schema';
export const client = RayfinClient.create({
baseUrl: import.meta.env.VITE_RAYFIN_API_URL,
publishableKey: import.meta.env.VITE_RAYFIN_PUBLISHABLE_KEY,
auth: browserSession({ storage: true }),
services: {
data: dataService<AppSchema>(),
},
});Session options such as storage, persistSession, autoRefreshToken, and multiTabSync are arguments to browserSession(); in Rayfin 1.x they were top-level client options.
A client created with suppliedToken() from @microsoft/rayfin-client has no client.auth — use it only for scripts and servers that already hold a Rayfin token.
See Sessions for every option.
Enable external Entra exchange
Direct Entra token sign-in and the external embed host call Rayfin's external brokered endpoints.
Add externalEntraExchange: true and deploy the setting before using those flows:
services:
auth:
enabled: true
fabric:
enabled: true
externalEntraExchange: trueThis opt-in is not needed for the normal Fabric SSO popup or Fabric iframe flows.
Use sessions after any flow
Every flow installs the same opaque session on client.auth.
Read only the documented fields and subscribe with onSessionChange:
import { client } from '../services/rayfinClient';
const session = client.auth.getSession();
if (session.isAuthenticated && session.user) {
console.log('Signed in as', session.user.email);
}
const unsubscribe = client.auth.onSessionChange((nextSession) => {
console.log('Auth changed:', nextSession?.isAuthenticated ?? false);
});
// Later, for example on component unmount:
unsubscribe();isAuthenticated is true only while the access token is unexpired. Changed in 2.0
See Sessions for refresh, sign-out, and lifecycle details.
Show sign-in errors
ensureSignedInWithFabric() and signInWithEntraToken() reject with an AuthError when sign-in fails.
Catch it and show error.message in your sign-in UI; it is a user-safe description.
initEmbeddedAuth() resolves to null instead of rejecting, so show a sign-in button when it does.
See Handle sign-in errors for the codes.
In this section
- Fabric SSO — enable it, install the provider package, and call
initEmbeddedAuthplusensureSignedInWithFabric. - Direct Entra token sign-in — exchange an existing delegated Entra token for a Rayfin session. New in 1.36
- External embed host — broker sign-in for a Rayfin app embedded in your own portal. New in 1.36
- Sessions —
browserSessionoptions, the opaque session object,onSessionChange, token refresh, sign-out, and disposal. - Dynamic auth claims — mint app-defined claims into the access token with a
udf.authClaimsfunction and filter data on them. New in 2.0 - Delegated access — how Functions, connectors, and entity policies use signed-in identity or app identity.
- React integration — an auth context, a hook, embedded startup, and route guarding.
In my Rayfin 2.0 app, choose the correct Microsoft Entra auth flow and wire it up.
Create the client with RayfinClient.create({ baseUrl, publishableKey, auth: browserSession({ storage: true }), services: { ... } }), importing browserSession from @microsoft/rayfin-auth, so client.auth exists. Install @microsoft/rayfin-auth and @microsoft/rayfin-auth-provider-fabric.
Use Fabric SSO when my browser app needs Fabric to perform interactive sign-in. Keep http://localhost:5173 in services.auth.allowedRedirectUris for local frontend development, await initEmbeddedAuth() at startup (it resolves to null instead of rejecting), and call ensureSignedInWithFabric() from a button click.
If my code already has a delegated Entra access token, use signInWithEntraToken(client.auth, { entraToken }) instead and enable services.auth.fabric.externalEntraExchange: true in rayfin/rayfin.yml. If my own portal embeds the Rayfin app in an iframe, register createEmbedHost() in the parent before mounting the iframe and enable the same externalEntraExchange setting.
Catch every sign-in error and show error.message to the user. Use client.auth.getSession() and client.auth.onSessionChange(...) for UI state. Do not add alternate sign-in flows.Seeding data
Populate @anonymous() Rayfin entities from a Node.js script with a publishable-key-only RayfinClient, and what a script needs before it can write @authenticated() rows.
Fabric SSO
Sign users in with Microsoft Entra ID through Fabric SSO, using the popup flow for browser apps or embedded flow in the Fabric portal.