Rayfin

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, and signOut work the same way no matter which supported flow installed the session.

Choose an auth path

SituationUseWhere it runs
A browser app needs Fabric to perform interactive sign-inFabric SSO popup flowAny origin in services.auth.allowedRedirectUris, including http://localhost:5173 during local frontend development.
A Rayfin app is loaded inside the Fabric portal iframeFabric SSO embedded flowThe Fabric portal iframe. The embedded flow requires the app to be loaded by Fabric.
A React app needs shared session state and route guardingReact integrationBrowser UI code, using the same client.auth instance as the SDK client.
Browser or Node.js code already has a delegated Entra tokenDirect Entra token sign-inBrowser 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 iframeExternal embed hostParent 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 refreshSessionsAny frontend code that can access client.auth.
Entity policies need app-defined facts about the user, such as an account or regionDynamic auth claimsA 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:

rayfin/rayfin.yml
services:
  auth:
    enabled: true
    allowedRedirectUris:
      - http://localhost:5173
    fabric:
      enabled: true

Run 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

Changed in 2.0

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-data
src/services/rayfinClient.ts
import { 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:

rayfin/rayfin.yml
services:
  auth:
    enabled: true
    fabric:
      enabled: true
      externalEntraExchange: true

This 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:

src/auth/session.ts
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 initEmbeddedAuth plus ensureSignedInWithFabric.
  • 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 — browserSession options, 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.authClaims function 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.
PromptChoose and wire the right Rayfin auth flow
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.
Something wrong on this page?Report an issueEdit this page

On this page