@svadmin/sso 0.11.5 → 0.11.7

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.
@@ -41,6 +41,8 @@ export interface SSOConfig {
41
41
  refreshLock?: RefreshLock;
42
42
  /** Injectable fetch implementation for testing and SSR runtimes. */
43
43
  fetcher?: typeof fetch;
44
+ /** Trusted permission resolver. Without one, getPermissions() returns null. */
45
+ getPermissions?: SSOPermissionResolver;
44
46
  /**
45
47
  * Manual OAuth2 endpoints for providers that don't support OIDC discovery
46
48
  * (e.g., GitHub). When provided, OIDC auto-discovery is skipped.
@@ -57,6 +59,12 @@ export interface TokenStorage {
57
59
  setItem: (key: string, value: string) => void;
58
60
  removeItem: (key: string) => void;
59
61
  }
62
+ export interface SSOPermissionResolverContext {
63
+ session: SSOSession;
64
+ getAccessToken: (options?: GetAccessTokenOptions) => Promise<string | null>;
65
+ createAuthenticatedFetch: (fetcher?: typeof fetch) => typeof fetch;
66
+ }
67
+ export type SSOPermissionResolver = (context: SSOPermissionResolverContext) => Promise<unknown> | unknown;
60
68
  export interface SSOAuthProvider extends AuthProvider {
61
69
  getSession: () => Promise<SSOSession | null>;
62
70
  refreshSession: () => Promise<SSOSession | null>;
@@ -356,6 +356,9 @@ export function createSSOAuthProvider(config) {
356
356
  : null;
357
357
  },
358
358
  };
359
+ function createProviderAuthenticatedFetch(fetcher) {
360
+ return buildAuthenticatedFetch(authorizationSource, fetcher ?? getFetcher());
361
+ }
359
362
  const provider = {
360
363
  async login() {
361
364
  if (typeof window === 'undefined') {
@@ -553,22 +556,20 @@ export function createSSOAuthProvider(config) {
553
556
  }
554
557
  },
555
558
  async getPermissions() {
556
- const idToken = sessions.getSession()?.id_token;
557
- if (!idToken)
558
- return null;
559
- try {
560
- const payload = decodeJwtPayload(idToken);
561
- return payload?.roles ?? payload?.groups ?? payload?.permissions ?? null;
562
- }
563
- catch {
559
+ const session = sessions.getSession();
560
+ if (!session || !config.getPermissions)
564
561
  return null;
565
- }
562
+ return config.getPermissions({
563
+ session,
564
+ getAccessToken: (options) => sessions.getAccessToken(options),
565
+ createAuthenticatedFetch: createProviderAuthenticatedFetch,
566
+ });
566
567
  },
567
568
  getSession: async () => sessions.getSession(),
568
569
  refreshSession: () => sessions.refreshSession(),
569
570
  getAccessToken: (options) => sessions.getAccessToken(options),
570
571
  onAuthStateChange: (callback) => sessions.onAuthStateChange(callback),
571
- createAuthenticatedFetch: (fetcher) => buildAuthenticatedFetch(authorizationSource, fetcher ?? getFetcher()),
572
+ createAuthenticatedFetch: createProviderAuthenticatedFetch,
572
573
  destroy: () => sessions.destroy(),
573
574
  async onError(error) {
574
575
  const status = getErrorStatus(error);
package/dist/index.d.ts CHANGED
@@ -7,7 +7,7 @@
7
7
  * ```
8
8
  */
9
9
  export { createSSOAuthProvider } from './auth-provider.js';
10
- export type { AuthStateChangeCallback, AuthStateChangeEvent, GetAccessTokenOptions, RefreshLock, SSOAuthProvider, SSOConfig, SSOSession, TokenStorage, } from './auth-provider.js';
10
+ export type { AuthStateChangeCallback, AuthStateChangeEvent, GetAccessTokenOptions, RefreshLock, SSOPermissionResolver, SSOPermissionResolverContext, SSOAuthProvider, SSOConfig, SSOSession, TokenStorage, } from './auth-provider.js';
11
11
  export { SSOAuthError } from './errors.js';
12
12
  export { createGoogleAuth, createMicrosoftAuth, createGitHubAuth, createGitLabAuth, createKeycloakAuth, createAuth0Auth, createSupauthAuth, } from './presets.js';
13
13
  export type { PresetOptions } from './presets.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@svadmin/sso",
3
- "version": "0.11.5",
3
+ "version": "0.11.7",
4
4
  "type": "module",
5
5
  "description": "OIDC/OAuth2 SSO AuthProvider plugin for svadmin — supports Okta, Azure AD, Cognito, Keycloak, Google",
6
6
  "license": "MIT",
@@ -18,7 +18,7 @@
18
18
  ],
19
19
  "repository": {
20
20
  "type": "git",
21
- "url": "https://github.com/zuohuadong/svadmin",
21
+ "url": "https://github.com/vibeunion/svadmin",
22
22
  "directory": "packages/sso"
23
23
  },
24
24
  "sideEffects": false,
@@ -34,7 +34,7 @@
34
34
  "dist"
35
35
  ],
36
36
  "peerDependencies": {
37
- "@svadmin/core": "^0.33.0"
37
+ "@svadmin/core": "^0.36.1"
38
38
  },
39
39
  "devDependencies": {
40
40
  "typescript": "^7.0.2"