reifyui 0.13.7 → 0.13.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "reifyui",
3
- "version": "0.13.7",
3
+ "version": "0.13.8",
4
4
  "description": "The open-source rendering & interaction layer for agentic applications. Stream and render any agent's output as polished, application-native UI — model-agnostic, framework-agnostic, design-system-native. The foundation for building generative-UI and agent products.",
5
5
  "keywords": [
6
6
  "react",
@@ -6,9 +6,10 @@
6
6
  // (configureAuth must have run at boot).
7
7
  import { useState } from 'react';
8
8
  import {
9
- login, register, googleSignIn, requestPasswordReset, switchOrg,
9
+ login, register, googleSignIn, microsoftSignIn, requestPasswordReset, switchOrg,
10
10
  } from './client.js';
11
11
  import { GoogleButton, GOOGLE_ENABLED } from './GoogleButton.jsx';
12
+ import { MicrosoftButton, MICROSOFT_ENABLED } from './MicrosoftButton.jsx';
12
13
 
13
14
  export function AuthForm({ onDone, subtitle, brand = null, productName = '' }) {
14
15
  const [mode, setMode] = useState('signin'); // signin | register | forgot
@@ -54,6 +55,18 @@ export function AuthForm({ onDone, subtitle, brand = null, productName = '' }) {
54
55
  }
55
56
  }
56
57
 
58
+ async function onMicrosoft(credential) {
59
+ setErr('');
60
+ setBusy(true);
61
+ try {
62
+ await afterAuth(await microsoftSignIn(credential));
63
+ } catch (ex) {
64
+ setErr(ex instanceof Error ? ex.message : 'Microsoft sign in failed.');
65
+ } finally {
66
+ setBusy(false);
67
+ }
68
+ }
69
+
57
70
  async function onGoogle(credential) {
58
71
  setErr('');
59
72
  setBusy(true);
@@ -172,7 +185,9 @@ export function AuthForm({ onDone, subtitle, brand = null, productName = '' }) {
172
185
  {busy ? 'Please wait...' : mode === 'register' ? 'Create account' : 'Sign in'}
173
186
  </button>
174
187
 
175
- {GOOGLE_ENABLED && <GoogleButton onCredential={onGoogle} onError={setErr} />}
188
+ {(GOOGLE_ENABLED || MICROSOFT_ENABLED) && <div className="auth-or"><span>or</span></div>}
189
+ {GOOGLE_ENABLED && <GoogleButton onCredential={onGoogle} onError={setErr} divider={false} />}
190
+ {MICROSOFT_ENABLED && <MicrosoftButton onCredential={onMicrosoft} onError={setErr} disabled={busy} />}
176
191
 
177
192
  <p className="auth-switch">
178
193
  {mode === 'register' ? 'Already have an account?' : `New to ${productName || 'the product'}?`}{' '}
@@ -11,7 +11,7 @@ import { useEffect, useRef, useState } from 'react';
11
11
 
12
12
  const CLIENT_ID = '247853836408-ojk91u8901hdlbkevid4fohmrfdot17l.apps.googleusercontent.com';
13
13
 
14
- export function GoogleButton({ onCredential, onError }) {
14
+ export function GoogleButton({ onCredential, onError, divider = true }) {
15
15
  const ref = useRef(null);
16
16
  const [failed, setFailed] = useState(false);
17
17
  // Keep the latest callbacks in a ref so the GIS button mounts exactly once
@@ -71,7 +71,7 @@ export function GoogleButton({ onCredential, onError }) {
71
71
  if (!CLIENT_ID || failed) return null;
72
72
  return (
73
73
  <>
74
- <div className="auth-or"><span>or</span></div>
74
+ {divider && <div className="auth-or"><span>or</span></div>}
75
75
  <div ref={ref} className="auth-gwrap" />
76
76
  </>
77
77
  );
@@ -0,0 +1,128 @@
1
+ // Sign in with Microsoft (work and school accounts), the platform's
2
+ // multi-tenant Entra application. Like GoogleButton, it only obtains an
3
+ // OpenID Connect id token and hands it to the caller, which exchanges it for
4
+ // a session at the engine's /v1/auth/microsoft.
5
+ //
6
+ // The token comes back in a popup, to <this origin>/auth/microsoft. That
7
+ // address must be one of the application's registered SPA return addresses
8
+ // (one per product host) and should serve a blank page: this window reads the
9
+ // popup the moment it is back on our origin, before anything could run in it.
10
+ // The client id is PUBLIC (it is in every authorize URL).
11
+ import { useRef, useState } from 'react';
12
+
13
+ const CLIENT_ID = 'cb5c1b6e-aca8-48dd-9da9-31320de30b73';
14
+ const AUTHORIZE = 'https://login.microsoftonline.com/organizations/oauth2/v2.0/authorize';
15
+ const RETURN_PATH = '/auth/microsoft';
16
+ const GIVE_UP_MS = 5 * 60 * 1000;
17
+
18
+ export const MICROSOFT_ENABLED = !!CLIENT_ID;
19
+
20
+ function randomHex(bytes = 16) {
21
+ const a = new Uint8Array(bytes);
22
+ crypto.getRandomValues(a);
23
+ return Array.from(a, (b) => b.toString(16).padStart(2, '0')).join('');
24
+ }
25
+
26
+ function jwtClaims(token) {
27
+ try {
28
+ const part = token.split('.')[1].replace(/-/g, '+').replace(/_/g, '/');
29
+ const bin = atob(part + '='.repeat((4 - (part.length % 4)) % 4));
30
+ return JSON.parse(new TextDecoder().decode(Uint8Array.from(bin, (c) => c.charCodeAt(0))));
31
+ } catch {
32
+ return {};
33
+ }
34
+ }
35
+
36
+ /** Open Microsoft's sign-in in a popup and resolve with the id token, or
37
+ * reject with a sentence a person can read. */
38
+ export function microsoftIdToken() {
39
+ return new Promise((resolve, reject) => {
40
+ const state = randomHex();
41
+ const nonce = randomHex();
42
+ const back = `${window.location.origin}${RETURN_PATH}`;
43
+ const url = `${AUTHORIZE}?${new URLSearchParams({
44
+ client_id: CLIENT_ID, response_type: 'id_token', redirect_uri: back,
45
+ scope: 'openid profile email', response_mode: 'fragment',
46
+ state, nonce, prompt: 'select_account',
47
+ })}`;
48
+ const w = 480;
49
+ const h = 640;
50
+ const left = Math.max(0, window.screenX + (window.outerWidth - w) / 2);
51
+ const top = Math.max(0, window.screenY + (window.outerHeight - h) / 2);
52
+ const popup = window.open(url, 'microsoft-sign-in', `width=${w},height=${h},left=${left},top=${top}`);
53
+ if (!popup) {
54
+ reject(new Error('Allow pop-ups for this site to sign in with Microsoft.'));
55
+ return;
56
+ }
57
+ const started = Date.now();
58
+ const timer = window.setInterval(() => {
59
+ if (popup.closed) {
60
+ window.clearInterval(timer);
61
+ reject(new Error('Microsoft sign in was cancelled.'));
62
+ return;
63
+ }
64
+ if (Date.now() - started > GIVE_UP_MS) {
65
+ window.clearInterval(timer);
66
+ popup.close();
67
+ reject(new Error('Microsoft sign in took too long. Try again.'));
68
+ return;
69
+ }
70
+ let href = '';
71
+ try { href = popup.location.href; } catch { return; } // still on Microsoft's pages
72
+ if (!href.startsWith(back)) return;
73
+ window.clearInterval(timer);
74
+ const params = new URLSearchParams(popup.location.hash.replace(/^#/, ''));
75
+ popup.close();
76
+ if (params.get('error')) {
77
+ const why = (params.get('error_description') || '').split(/\r?\n/)[0].replace(/^AADSTS\d+:\s*/, '');
78
+ reject(new Error(why || 'Microsoft sign in did not complete.'));
79
+ return;
80
+ }
81
+ const token = params.get('id_token') || '';
82
+ if (!token || params.get('state') !== state || jwtClaims(token).nonce !== nonce) {
83
+ reject(new Error('Microsoft sign in could not be confirmed. Try again.'));
84
+ return;
85
+ }
86
+ resolve(token);
87
+ }, 300);
88
+ });
89
+ }
90
+
91
+ function MicrosoftLogo() {
92
+ return (
93
+ <svg width="18" height="18" viewBox="0 0 21 21" aria-hidden="true">
94
+ <rect x="1" y="1" width="9" height="9" fill="#F25022" />
95
+ <rect x="11" y="1" width="9" height="9" fill="#7FBA00" />
96
+ <rect x="1" y="11" width="9" height="9" fill="#00A4EF" />
97
+ <rect x="11" y="11" width="9" height="9" fill="#FFB900" />
98
+ </svg>
99
+ );
100
+ }
101
+
102
+ export function MicrosoftButton({ onCredential, onError, disabled }) {
103
+ const [waiting, setWaiting] = useState(false);
104
+ const cb = useRef({ onCredential, onError });
105
+ cb.current = { onCredential, onError };
106
+ if (!CLIENT_ID) return null;
107
+
108
+ async function start() {
109
+ setWaiting(true);
110
+ try {
111
+ const token = await microsoftIdToken();
112
+ await cb.current.onCredential(token);
113
+ } catch (ex) {
114
+ cb.current.onError?.(ex instanceof Error ? ex.message : 'Microsoft sign in failed.');
115
+ } finally {
116
+ setWaiting(false);
117
+ }
118
+ }
119
+
120
+ return (
121
+ <div className="auth-mswrap">
122
+ <button type="button" className="auth-msbtn" onClick={start} disabled={disabled || waiting}>
123
+ <MicrosoftLogo />
124
+ <span>{waiting ? 'Waiting for Microsoft...' : 'Sign in with Microsoft'}</span>
125
+ </button>
126
+ </div>
127
+ );
128
+ }
@@ -108,6 +108,15 @@ export async function googleSignIn(credential) {
108
108
  return s;
109
109
  }
110
110
 
111
+ // Exchange a Microsoft (Entra) id token for a session, as googleSignIn does
112
+ // with Google's. The engine answers a refusal with a sentence to show as is:
113
+ // a personal account, a disabled member, or sign-in not configured.
114
+ export async function microsoftSignIn(credential) {
115
+ const s = toSession(await authPost('/v1/auth/microsoft', { credential, product: _cfg.product }));
116
+ setSession(s);
117
+ return s;
118
+ }
119
+
111
120
  export async function requestPasswordReset(email) {
112
121
  await fetch(`${_cfg.engine}/v1/auth/request-password-reset`, {
113
122
  method: 'POST',
package/src/index.js CHANGED
@@ -38,11 +38,12 @@ export { DialogHost, useDialog } from './components/Dialog.jsx';
38
38
  export {
39
39
  configureAuth, authConfig, SESSION_EVENT,
40
40
  getSession, clearSession, getToken, isAuthed,
41
- login, register, googleSignIn, requestPasswordReset, switchOrg,
41
+ login, register, googleSignIn, microsoftSignIn, requestPasswordReset, switchOrg,
42
42
  refreshToken, handleAuthExpired, logout, authFetch, fetchBalance,
43
43
  } from './auth/client.js';
44
44
  export { AuthForm } from './auth/AuthForm.jsx';
45
45
  export { GoogleButton, GOOGLE_ENABLED } from './auth/GoogleButton.jsx';
46
+ export { MicrosoftButton, MICROSOFT_ENABLED, microsoftIdToken } from './auth/MicrosoftButton.jsx';
46
47
  // Shared AI-spreadsheet grid (reusable in the Sheets product AND studio Spaces).
47
48
  export { SheetGrid, sheetToDelimited, sheetToAoA } from './sheet/SheetGrid.jsx';
48
49
  // Files, drawn the same wherever they appear. FileTypeIcon uses react-file-icon when it is