@docyrus/signin 0.18.2 → 0.19.0
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/README.md +21 -1
- package/dist/{constants-CvMiR-RM.d.ts → constants-DXgxjFEl.d.ts} +3 -2
- package/dist/core-index.d.ts +3 -3
- package/dist/core-index.js +48 -1
- package/dist/core-index.js.map +1 -1
- package/dist/electron/index.d.ts +2 -1
- package/dist/index.d.ts +6 -5
- package/dist/index.js +69 -17
- package/dist/index.js.map +1 -1
- package/dist/nextjs/index.d.ts +2 -1
- package/dist/nextjs/index.js.map +1 -1
- package/dist/react-native/index.d.ts +4 -4
- package/dist/react-native/index.js +69 -17
- package/dist/react-native/index.js.map +1 -1
- package/dist/{types-BcLDyMdw.d.ts → types-C3TY5WcX.d.ts} +3 -2
- package/dist/{use-docyrus-client-C9uiHma9.d.ts → use-docyrus-client-D-oTYabD.d.ts} +6 -3
- package/dist/vue/index.d.ts +7 -3
- package/dist/vue/index.js +72 -19
- package/dist/vue/index.js.map +1 -1
- package/package.json +14 -8
package/README.md
CHANGED
|
@@ -513,7 +513,7 @@ Returns the full authentication context. Available in both React and Vue (`@docy
|
|
|
513
513
|
|
|
514
514
|
```tsx
|
|
515
515
|
const {
|
|
516
|
-
status, // 'loading' | 'authenticated' | 'unauthenticated'
|
|
516
|
+
status, // 'loading' | 'authenticated' | 'unauthenticated' | 'error'
|
|
517
517
|
mode, // 'standalone' | 'iframe'
|
|
518
518
|
client, // RestApiClient | null
|
|
519
519
|
tokens, // { accessToken, refreshToken, ... } | null
|
|
@@ -694,6 +694,26 @@ Used when the app is embedded in an iframe on `*.docyrus.app`. The flow:
|
|
|
694
694
|
4. When tokens expire, provider sends `{ type: 'token-refresh-request' }` to host
|
|
695
695
|
5. Host responds with fresh tokens
|
|
696
696
|
|
|
697
|
+
#### Backend URL at startup
|
|
698
|
+
|
|
699
|
+
The shell can include its API base URL in the iframe URL, for example
|
|
700
|
+
`?embedded=true&apiUrl=http%3A%2F%2Flocalhost%3A3000`. Sign-in reads it once
|
|
701
|
+
when the app starts and uses it for the API client, SSO exchange, and any OAuth
|
|
702
|
+
refresh performed by the app. Iframe token refresh still asks the host for new
|
|
703
|
+
tokens over postMessage.
|
|
704
|
+
|
|
705
|
+
The accepted hosts are `localhost`, `127.0.0.1`, and `[::1]` over HTTP or HTTPS
|
|
706
|
+
on any port, and `docyrus.com`, `attornaid.com`, and their subdomains over HTTPS.
|
|
707
|
+
Supply a base URL without credentials, a query, or a fragment. Apps opened
|
|
708
|
+
without `embedded=true` and embedded apps whose URL omits `apiUrl` use the
|
|
709
|
+
provider's configured `apiUrl` or the default `https://alpha-api.docyrus.com`.
|
|
710
|
+
|
|
711
|
+
An invalid host URL sets `status` to `'error'` and `error.message` to
|
|
712
|
+
`'invalid-host-api-url'`. Authentication and API requests are blocked, and the
|
|
713
|
+
provider displays an error message in place of the app. To customize that
|
|
714
|
+
message, pass `renderAuthError={(error) => …}` to the React provider or supply
|
|
715
|
+
the Vue provider's `#error="{ error }"` slot.
|
|
716
|
+
|
|
697
717
|
The host may post `signin` as often as it likes. Only a new session — the
|
|
698
718
|
first token, or one for a different user/tenant — creates a new `client` and
|
|
699
719
|
re-fetches the user. Repeats of the current token are ignored, and refreshed
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { OAuth2Tokens, RestApiClient } from '@docyrus/api-client';
|
|
2
|
-
import { D as DocyrusAuthConfig, c as AuthMode, e as AuthStatus, o as DocyrusUser, G as GuidyRoute, R as RouteChangePayload, w as HostNavigationRequestOptions, m as DocyrusSharePayload, i as DocyrusEmailPayload, h as DocyrusCalendarEventPayload, p as MsGraphClient, H as HostNavigationHandler, v as HostNotificationHandler, k as DocyrusRole, u as PermissionScope, P as PermissionConfig } from './types-
|
|
2
|
+
import { D as DocyrusAuthConfig, c as AuthMode, e as AuthStatus, o as DocyrusUser, G as GuidyRoute, R as RouteChangePayload, w as HostNavigationRequestOptions, m as DocyrusSharePayload, i as DocyrusEmailPayload, h as DocyrusCalendarEventPayload, p as MsGraphClient, H as HostNavigationHandler, v as HostNotificationHandler, k as DocyrusRole, u as PermissionScope, P as PermissionConfig } from './types-C3TY5WcX.js';
|
|
3
3
|
|
|
4
4
|
type AuthStateListener = (state: {
|
|
5
5
|
status: AuthStatus;
|
|
@@ -267,4 +267,5 @@ declare const DEFAULT_CALLBACK_PATH = "/auth/callback";
|
|
|
267
267
|
/** Default cookie name for SSR token sync */
|
|
268
268
|
declare const DEFAULT_SSR_COOKIE_KEY = "docyrus-token";
|
|
269
269
|
|
|
270
|
-
export { AuthManager as A, DEFAULT_API_URL as D, DEFAULT_OAUTH_SCOPES as a, getAllowedOperations as b, hasRole as c, DEFAULT_CALLBACK_PATH as d, DEFAULT_SSR_COOKIE_KEY as e,
|
|
270
|
+
export { AuthManager as A, DEFAULT_API_URL as D, DEFAULT_OAUTH_SCOPES as a, getAllowedOperations as b, hasRole as c, DEFAULT_CALLBACK_PATH as d, DEFAULT_SSR_COOKIE_KEY as e, getAllRoles as g, hasPermission as h };
|
|
271
|
+
export type { AuthStateListener as f };
|
package/dist/core-index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export { A as AuthManager, f as AuthStateListener, D as DEFAULT_API_URL, d as DEFAULT_CALLBACK_PATH, a as DEFAULT_OAUTH_SCOPES, g as getAllRoles, b as getAllowedOperations, h as hasPermission, c as hasRole } from './constants-
|
|
1
|
+
export { A as AuthManager, f as AuthStateListener, D as DEFAULT_API_URL, d as DEFAULT_CALLBACK_PATH, a as DEFAULT_OAUTH_SCOPES, g as getAllRoles, b as getAllowedOperations, h as hasPermission, c as hasRole } from './constants-DXgxjFEl.js';
|
|
2
2
|
import { OAuth2Tokens } from '@docyrus/api-client';
|
|
3
|
-
import { D as DocyrusAuthConfig, T as GuidyElementsMessage, W as GuidyRoutesMessage, U as GuidyPointAckMessage, G as GuidyRoute, Q as GuidyCommandMessage, c as AuthMode } from './types-
|
|
4
|
-
export { A as AclOperation, a as AclTargetType, b as AdaptiveCard, x as AppNavigationRequestMessage, y as AppRouteChangeMessage, e as AuthStatus, C as CalendarSendAckMessage, z as CalendarSendMessage, B as ChatSendAckMessage, E as ChatSendMessage, F as DocySendAckMessage, I as DocySendMessage, f as DocyrusAclRule, g as DocyrusAuthContextValue, h as DocyrusCalendarEventPayload, i as DocyrusEmailPayload, J as DocyrusNotification, j as DocyrusPermission, k as DocyrusRole, l as DocyrusShareAdaptiveCardPayload, m as DocyrusSharePayload, n as DocyrusShareTextPayload, o as DocyrusUser, K as EmailSendAckMessage, L as EmailSendMessage, N as GuidyCommandHandler, S as GuidyElement, V as GuidyPointMessage, X as GuidyScanMessage, H as HostNavigationHandler, Y as HostNavigationMessage, w as HostNavigationRequestOptions, v as HostNotificationHandler, Z as HostNotificationMessage, _ as HostSignInMessage, $ as IframeAuth, M as MsGraphAccount, p as MsGraphClient, q as MsGraphRequest, a0 as MsGraphRequestMessage, r as MsGraphRequestOptions, s as MsGraphResponse, a1 as MsGraphResponseMessage, t as MsGraphStatus, a2 as MsGraphStatusRequestMessage, a3 as MsGraphStatusResponseMessage, P as PermissionConfig, u as PermissionScope, R as RouteChangePayload, a4 as TokenRefreshRequestMessage } from './types-
|
|
3
|
+
import { D as DocyrusAuthConfig, T as GuidyElementsMessage, W as GuidyRoutesMessage, U as GuidyPointAckMessage, G as GuidyRoute, Q as GuidyCommandMessage, c as AuthMode } from './types-C3TY5WcX.js';
|
|
4
|
+
export { A as AclOperation, a as AclTargetType, b as AdaptiveCard, x as AppNavigationRequestMessage, y as AppRouteChangeMessage, e as AuthStatus, C as CalendarSendAckMessage, z as CalendarSendMessage, B as ChatSendAckMessage, E as ChatSendMessage, F as DocySendAckMessage, I as DocySendMessage, f as DocyrusAclRule, g as DocyrusAuthContextValue, h as DocyrusCalendarEventPayload, i as DocyrusEmailPayload, J as DocyrusNotification, j as DocyrusPermission, k as DocyrusRole, l as DocyrusShareAdaptiveCardPayload, m as DocyrusSharePayload, n as DocyrusShareTextPayload, o as DocyrusUser, K as EmailSendAckMessage, L as EmailSendMessage, N as GuidyCommandHandler, S as GuidyElement, V as GuidyPointMessage, X as GuidyScanMessage, H as HostNavigationHandler, Y as HostNavigationMessage, w as HostNavigationRequestOptions, v as HostNotificationHandler, Z as HostNotificationMessage, _ as HostSignInMessage, $ as IframeAuth, M as MsGraphAccount, p as MsGraphClient, q as MsGraphRequest, a0 as MsGraphRequestMessage, r as MsGraphRequestOptions, s as MsGraphResponse, a1 as MsGraphResponseMessage, t as MsGraphStatus, a2 as MsGraphStatusRequestMessage, a3 as MsGraphStatusResponseMessage, P as PermissionConfig, u as PermissionScope, R as RouteChangePayload, a4 as TokenRefreshRequestMessage } from './types-C3TY5WcX.js';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Standalone OAuth2 authorization code flow with PKCE via page redirect.
|
package/dist/core-index.js
CHANGED
|
@@ -4,6 +4,8 @@ import { BrowserOAuth2TokenStorage, OAuth2Client, RestApiClient, MemoryOAuth2Tok
|
|
|
4
4
|
|
|
5
5
|
// src/constants.ts
|
|
6
6
|
var DEFAULT_API_URL = "https://alpha-api.docyrus.com";
|
|
7
|
+
var INVALID_HOST_API_URL = "invalid-host-api-url";
|
|
8
|
+
var UNTRUSTED_BACKEND_MESSAGE = "This app can\u2019t run because its host gave it an untrusted backend address.";
|
|
7
9
|
var DEFAULT_OAUTH_SCOPES = [
|
|
8
10
|
"offline_access",
|
|
9
11
|
"Read.All",
|
|
@@ -1096,6 +1098,39 @@ function clearTokenCookie(cookieKey) {
|
|
|
1096
1098
|
document.cookie = `${key}=;path=/;max-age=0;SameSite=Lax${secure}`;
|
|
1097
1099
|
}
|
|
1098
1100
|
|
|
1101
|
+
// src/core/host-api-url.ts
|
|
1102
|
+
var LOOPBACK_HOSTS = [
|
|
1103
|
+
"localhost",
|
|
1104
|
+
"127.0.0.1",
|
|
1105
|
+
"[::1]"
|
|
1106
|
+
];
|
|
1107
|
+
var TRUSTED_DOMAINS = ["docyrus.com", "attornaid.com"];
|
|
1108
|
+
function readHostApiUrl() {
|
|
1109
|
+
if (typeof window === "undefined" || !window.location) return void 0;
|
|
1110
|
+
const params = new URLSearchParams(window.location.search);
|
|
1111
|
+
const value = params.get("apiUrl");
|
|
1112
|
+
if (params.get("embedded") !== "true" || value === null) return void 0;
|
|
1113
|
+
try {
|
|
1114
|
+
const url = new URL(value);
|
|
1115
|
+
const {
|
|
1116
|
+
protocol,
|
|
1117
|
+
hostname,
|
|
1118
|
+
username,
|
|
1119
|
+
password,
|
|
1120
|
+
search,
|
|
1121
|
+
hash
|
|
1122
|
+
} = url;
|
|
1123
|
+
const loopback = LOOPBACK_HOSTS.includes(hostname);
|
|
1124
|
+
const trustedDomain = TRUSTED_DOMAINS.some((domain) => hostname === domain || hostname.endsWith(`.${domain}`));
|
|
1125
|
+
if (username || password || search || hash) return null;
|
|
1126
|
+
if (protocol !== "https:" && !(loopback && protocol === "http:")) return null;
|
|
1127
|
+
if (!loopback && !trustedDomain) return null;
|
|
1128
|
+
return `${url.origin}${url.pathname.replace(/\/+$/, "")}`;
|
|
1129
|
+
} catch {
|
|
1130
|
+
return null;
|
|
1131
|
+
}
|
|
1132
|
+
}
|
|
1133
|
+
|
|
1099
1134
|
// src/core/auth-manager.ts
|
|
1100
1135
|
var AuthManager = class {
|
|
1101
1136
|
mode;
|
|
@@ -1123,7 +1158,12 @@ var AuthManager = class {
|
|
|
1123
1158
|
notificationHandlers = /* @__PURE__ */ new Set();
|
|
1124
1159
|
config;
|
|
1125
1160
|
constructor(config = {}) {
|
|
1126
|
-
|
|
1161
|
+
const hostApiUrl = readHostApiUrl();
|
|
1162
|
+
this.config = hostApiUrl ? { ...config, apiUrl: hostApiUrl } : config;
|
|
1163
|
+
if (hostApiUrl === null) {
|
|
1164
|
+
this.status = "error";
|
|
1165
|
+
this.error = new Error(INVALID_HOST_API_URL);
|
|
1166
|
+
}
|
|
1127
1167
|
this.mode = config.forceMode ?? detectAuthMode(config.allowedHostOrigins);
|
|
1128
1168
|
}
|
|
1129
1169
|
/** Whether the provider may refresh tokens on its own. Default: true. */
|
|
@@ -1171,6 +1211,11 @@ var AuthManager = class {
|
|
|
1171
1211
|
}
|
|
1172
1212
|
/** Initialize the auth manager. Must be called once on mount. */
|
|
1173
1213
|
async initialize() {
|
|
1214
|
+
if (this.status === "error") {
|
|
1215
|
+
console.error("[docyrus-signin]", UNTRUSTED_BACKEND_MESSAGE);
|
|
1216
|
+
this.notify();
|
|
1217
|
+
return;
|
|
1218
|
+
}
|
|
1174
1219
|
try {
|
|
1175
1220
|
if (this.mode === "iframe" && this.getInitialTokens()) {
|
|
1176
1221
|
throw new Error(
|
|
@@ -1453,6 +1498,7 @@ var AuthManager = class {
|
|
|
1453
1498
|
* browser redirect flow, such as a prior device authorization flow.
|
|
1454
1499
|
*/
|
|
1455
1500
|
async signInWithTokens(tokens) {
|
|
1501
|
+
if (this.status === "error") throw this.error;
|
|
1456
1502
|
if (this.mode === "iframe") {
|
|
1457
1503
|
throw new Error(
|
|
1458
1504
|
"signInWithTokens() is not supported in iframe mode. Use the host postMessage signin flow or force standalone mode."
|
|
@@ -1487,6 +1533,7 @@ var AuthManager = class {
|
|
|
1487
1533
|
* Iframe: clear local state (host manages the actual session).
|
|
1488
1534
|
*/
|
|
1489
1535
|
async signOut() {
|
|
1536
|
+
if (this.status === "error") return;
|
|
1490
1537
|
this.clearTokenRefreshTimer();
|
|
1491
1538
|
if (this.mode === "standalone" && this.standaloneAuth) {
|
|
1492
1539
|
await this.standaloneAuth.logout();
|