doct-ui-auth-kit 1.0.2 → 1.0.3
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/dist/adapters/http-auth-adapter.d.ts +2 -1
- package/dist/core/auth-api-adapter.d.ts +6 -0
- package/dist/core/sso-session.d.ts +42 -0
- package/dist/index.js +1083 -1023
- package/package.json +1 -1
|
@@ -6,6 +6,7 @@ import type { AuthApiAdapter } from '@/core/auth-api-adapter';
|
|
|
6
6
|
/**
|
|
7
7
|
* Creates an AuthApiAdapter that calls the given API base URL.
|
|
8
8
|
* Expects routes: POST /api/auth/send-otp, verify-otp, complete-profile,
|
|
9
|
-
* authenticate-provider, validate-session, refresh-session
|
|
9
|
+
* authenticate-provider, validate-session, refresh-session; GET validate-session
|
|
10
|
+
* (with credentials) for validateSessionFromCookie.
|
|
10
11
|
*/
|
|
11
12
|
export declare function createHttpAuthAdapter(baseUrl: string): AuthApiAdapter;
|
|
@@ -33,6 +33,12 @@ export interface AuthApiAdapter {
|
|
|
33
33
|
authenticateWithProvider(params: AuthenticateWithProviderParams): Promise<VerifyOtpResponse>;
|
|
34
34
|
/** Validate an existing SSO session token; called on SDK mount. Returns null if invalid/expired. */
|
|
35
35
|
validateSession(token: string): Promise<SSOSession | null>;
|
|
36
|
+
/**
|
|
37
|
+
* Optional: validate session using server-read cookie (no token from client).
|
|
38
|
+
* Required when using serverCookieTokenStorage. Client sends credentials;
|
|
39
|
+
* server reads cookie from the request and returns session or null.
|
|
40
|
+
*/
|
|
41
|
+
validateSessionFromCookie?(): Promise<SSOSession | null>;
|
|
36
42
|
/** Optional: refresh an expired SSO session using refresh token. */
|
|
37
43
|
refreshSession?(refreshToken: string): Promise<SSOSession | null>;
|
|
38
44
|
}
|
|
@@ -13,6 +13,48 @@ export interface TokenStorageStrategy {
|
|
|
13
13
|
* Suitable for dev or when all Docthub apps share the same origin.
|
|
14
14
|
*/
|
|
15
15
|
export declare function localStorageTokenStorage(): TokenStorageStrategy;
|
|
16
|
+
/**
|
|
17
|
+
* Token storage when the token lives in a server-set cookie (e.g. HttpOnly).
|
|
18
|
+
* The client never reads or writes the token; the server sets the cookie on
|
|
19
|
+
* login and reads it from the request. Use with validateSessionFromCookie
|
|
20
|
+
* in your adapter and createAxiosAuthInterceptors (withCredentials) so the
|
|
21
|
+
* cookie is sent on every request.
|
|
22
|
+
*/
|
|
23
|
+
export declare function serverCookieTokenStorage(): TokenStorageStrategy;
|
|
24
|
+
/**
|
|
25
|
+
* Axios instance shape needed to attach auth interceptors (avoids hard axios dependency).
|
|
26
|
+
* Use createAxiosAuthInterceptors with your axios instance.
|
|
27
|
+
*/
|
|
28
|
+
export interface AxiosAuthInterceptorInstance {
|
|
29
|
+
interceptors: {
|
|
30
|
+
request: {
|
|
31
|
+
use(onFulfilled?: (config: AxiosRequestConfig) => AxiosRequestConfig | Promise<AxiosRequestConfig>, onRejected?: (err: unknown) => unknown): number;
|
|
32
|
+
};
|
|
33
|
+
response: {
|
|
34
|
+
use(onFulfilled?: (res: unknown) => unknown, onRejected?: (err: unknown) => unknown): number;
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
defaults: {
|
|
38
|
+
withCredentials?: boolean;
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
/** Minimal request config type for the interceptor (no axios import). */
|
|
42
|
+
export interface AxiosRequestConfig {
|
|
43
|
+
headers?: Record<string, string> | {
|
|
44
|
+
[key: string]: string;
|
|
45
|
+
};
|
|
46
|
+
withCredentials?: boolean;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Attaches request and response interceptors to an axios instance for SSO auth
|
|
50
|
+
* when using server-side cookies (e.g. serverCookieTokenStorage):
|
|
51
|
+
* - Request: sets withCredentials so the browser sends cookies on every request.
|
|
52
|
+
* - Response: on 401, calls onUnauthorized (e.g. redirect to login).
|
|
53
|
+
*
|
|
54
|
+
* @param axiosInstance - Your axios instance (e.g. axios.create({ baseURL: '...' }))
|
|
55
|
+
* @param onUnauthorized - Optional callback when a response has status 401
|
|
56
|
+
*/
|
|
57
|
+
export declare function createAxiosAuthInterceptors(axiosInstance: AxiosAuthInterceptorInstance, onUnauthorized?: () => void): void;
|
|
16
58
|
/**
|
|
17
59
|
* useAuthSession hook is implemented in auth-context (uses AuthFlowContext).
|
|
18
60
|
* Re-exported from core index for consumer convenience.
|