@civic/auth 0.0.1-beta.18 → 0.0.1-beta.2

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.
Files changed (52) hide show
  1. package/README.md +0 -26
  2. package/dist/chunk-5NUJ7LFF.mjs +17 -0
  3. package/dist/chunk-5NUJ7LFF.mjs.map +1 -0
  4. package/dist/chunk-KS7ERXGZ.js +481 -0
  5. package/dist/chunk-KS7ERXGZ.js.map +1 -0
  6. package/dist/chunk-NINRO7GS.js +209 -0
  7. package/dist/chunk-NINRO7GS.js.map +1 -0
  8. package/dist/chunk-NXBKSUKI.mjs +481 -0
  9. package/dist/chunk-NXBKSUKI.mjs.map +1 -0
  10. package/dist/chunk-T7HUHQ3J.mjs +209 -0
  11. package/dist/chunk-T7HUHQ3J.mjs.map +1 -0
  12. package/dist/chunk-WZLC5B4C.js +17 -0
  13. package/dist/chunk-WZLC5B4C.js.map +1 -0
  14. package/dist/index-DoDoIY_K.d.mts +79 -0
  15. package/dist/index-DoDoIY_K.d.ts +79 -0
  16. package/dist/index.css +70 -63
  17. package/dist/index.css.map +1 -1
  18. package/dist/index.d.mts +1 -3
  19. package/dist/index.d.ts +1 -3
  20. package/dist/nextjs.d.mts +11 -10
  21. package/dist/nextjs.d.ts +11 -10
  22. package/dist/nextjs.js +173 -62
  23. package/dist/nextjs.js.map +1 -1
  24. package/dist/nextjs.mjs +171 -60
  25. package/dist/nextjs.mjs.map +1 -1
  26. package/dist/react.d.mts +65 -39
  27. package/dist/react.d.ts +65 -39
  28. package/dist/react.js +212 -433
  29. package/dist/react.js.map +1 -1
  30. package/dist/react.mjs +235 -456
  31. package/dist/react.mjs.map +1 -1
  32. package/dist/server.d.mts +12 -13
  33. package/dist/server.d.ts +12 -13
  34. package/dist/server.js +186 -3
  35. package/dist/server.js.map +1 -1
  36. package/dist/server.mjs +192 -9
  37. package/dist/server.mjs.map +1 -1
  38. package/package.json +4 -4
  39. package/dist/chunk-5XL2ST72.mjs +0 -226
  40. package/dist/chunk-5XL2ST72.mjs.map +0 -1
  41. package/dist/chunk-G3P5TIO2.mjs +0 -708
  42. package/dist/chunk-G3P5TIO2.mjs.map +0 -1
  43. package/dist/chunk-RF23Q4V6.js +0 -708
  44. package/dist/chunk-RF23Q4V6.js.map +0 -1
  45. package/dist/chunk-SEKF2WZX.js +0 -226
  46. package/dist/chunk-SEKF2WZX.js.map +0 -1
  47. package/dist/index-DTimUlkB.d.ts +0 -17
  48. package/dist/index-DvjkKpkk.d.mts +0 -17
  49. package/dist/types-HdCjGldB.d.mts +0 -58
  50. package/dist/types-HdCjGldB.d.ts +0 -58
  51. package/dist/types-b4c1koXj.d.mts +0 -19
  52. package/dist/types-b4c1koXj.d.ts +0 -19
package/dist/react.d.ts CHANGED
@@ -1,10 +1,20 @@
1
- import { U as UserContextType, A as AuthContextType } from './index-DTimUlkB.js';
2
- import { F as ForwardedTokens, C as Config, S as SessionData, b as EmptyObject, U as User, D as DisplayMode } from './types-HdCjGldB.js';
3
- import { O as OAuthTokens } from './types-b4c1koXj.js';
4
- import { ReactNode, RefObject, Dispatch, SetStateAction } from 'react';
1
+ import { JWT } from 'oslo/jwt';
2
+ import { D as DisplayMode, U as User, F as ForwardedTokens, A as AuthSessionService, E as Endpoints, b as UserInfoService, S as SessionData, a as UnknownObject, O as OIDCTokenResponseBody, P as ParsedTokens, C as Config } from './index-DoDoIY_K.js';
5
3
  import * as react_jsx_runtime from 'react/jsx-runtime';
6
- import 'oslo/jwt';
7
- import 'oslo/oauth2';
4
+ import { ReactNode } from 'react';
5
+ import { OAuth2Client } from 'oslo/oauth2';
6
+
7
+ type AuthContextType = {
8
+ signIn: (displayMode?: DisplayMode) => Promise<void>;
9
+ isAuthenticated: boolean;
10
+ isLoading: boolean;
11
+ error: Error | null;
12
+ signOut: () => Promise<void>;
13
+ };
14
+
15
+ type UserContextType$1<T extends Record<string, unknown> & JWT["payload"] = Record<string, unknown> & JWT["payload"]> = {
16
+ user: User<T> | null;
17
+ } & Omit<AuthContextType, "isAuthenticated">;
8
18
 
9
19
  type TokenContextType = {
10
20
  accessToken: string | null;
@@ -15,8 +25,45 @@ type TokenContextType = {
15
25
  error: Error | null;
16
26
  };
17
27
 
18
- interface PKCEConsumer {
19
- getCodeChallenge(): Promise<string>;
28
+ declare class AuthSessionServiceImpl implements AuthSessionService {
29
+ readonly clientId: string;
30
+ readonly redirectUrl: string;
31
+ readonly oauthServer: string;
32
+ readonly inputEndpoints?: Partial<Endpoints> | undefined;
33
+ private endpoints;
34
+ private oauth2Client;
35
+ private userInfoService;
36
+ private codeVerifier;
37
+ private refreshTokenTimeout;
38
+ constructor(clientId: string, redirectUrl: string, oauthServer: string, inputEndpoints?: Partial<Endpoints> | undefined);
39
+ protected getCodeVerifier(): string;
40
+ getUserInfoService(): Promise<UserInfoService>;
41
+ protected getEndpoints(): Promise<Endpoints>;
42
+ protected getOauth2Client(): Promise<OAuth2Client>;
43
+ getSessionData(): SessionData;
44
+ updateSessionData(data: Partial<SessionData>): void;
45
+ getUser(): User<UnknownObject> | null;
46
+ setUser(data: User<UnknownObject> | null): void;
47
+ clearSessionData(): void;
48
+ getAuthorizationUrlWithChallenge(state: string, scopes: string[]): Promise<URL>;
49
+ getAuthorizationUrl(scopes: string[], displayMode: DisplayMode, nonce?: string): Promise<string>;
50
+ loadAuthorizationUrl(authorizationURL: string, displayMode: DisplayMode): void;
51
+ init(): Promise<this>;
52
+ logout(): Promise<void>;
53
+ determineDisplayMode(displayMode: DisplayMode): DisplayMode;
54
+ signIn(displayMode: DisplayMode, scopes: string[], nonce: string): Promise<void>;
55
+ tokenExchange(responseUrl: string): Promise<SessionData>;
56
+ private setupTokenRefresh;
57
+ refreshToken(): Promise<SessionData>;
58
+ getUserInfo<T extends UnknownObject>(): Promise<User<T> | null>;
59
+ /**
60
+ * Uses the jose library to validate a JWT token using the OAuth JWKS endpoint
61
+ * @returns {Promise<jose.JWTPayload>}
62
+ * @throws {Error} if the token is invalid
63
+ * @param tokens
64
+ */
65
+ validateTokens(tokens: OIDCTokenResponseBody): Promise<ParsedTokens>;
66
+ validateExistingSession(): Promise<SessionData>;
20
67
  }
21
68
 
22
69
  type AuthProviderProps = {
@@ -27,20 +74,23 @@ type AuthProviderProps = {
27
74
  config?: Config;
28
75
  onSignIn?: (error?: Error) => void;
29
76
  onSignOut?: () => void;
30
- pkceConsumer?: PKCEConsumer;
31
- modalIframe?: boolean;
32
- sessionData?: SessionData;
77
+ authServiceImpl?: AuthSessionServiceImpl;
78
+ serverSideTokenExchange?: boolean;
33
79
  };
34
80
 
35
- type CivicAuthProviderProps = Omit<AuthProviderProps, "pkceConsumer">;
81
+ type CivicAuthProviderProps = Omit<AuthProviderProps, "authServiceImpl" | "serverSideTokenExchange">;
36
82
  declare const CivicAuthProvider: ({ children, ...props }: CivicAuthProviderProps) => react_jsx_runtime.JSX.Element;
37
83
 
84
+ type UserContextType = {
85
+ user: User<UnknownObject> | null;
86
+ };
38
87
  type NextCivicAuthProviderProps = Omit<AuthProviderProps, "clientId">;
39
88
  declare const CivicNextAuthProvider: ({ children, ...props }: NextCivicAuthProviderProps) => react_jsx_runtime.JSX.Element;
89
+ declare const useNextUser: () => UserContextType;
40
90
 
41
- declare const useUser: <T extends Record<string, unknown> = Record<string, never>>() => UserContextType<T>;
91
+ declare const useUser: <T extends Record<string, unknown> = Record<string, never>>() => UserContextType$1<T>;
42
92
 
43
- declare const useUserCookie: <T extends EmptyObject>() => User<T> | null;
93
+ declare const useUserCookie: () => any;
44
94
 
45
95
  declare const useToken: () => TokenContextType;
46
96
 
@@ -48,30 +98,6 @@ declare const useAuth: () => AuthContextType;
48
98
 
49
99
  declare const useSession: () => SessionData;
50
100
 
51
- type ConfigProviderOutput = {
52
- config: Config;
53
- redirectUrl: string;
54
- modalIframe: boolean;
55
- serverTokenExchange: boolean;
56
- };
57
-
58
- declare const useConfig: () => ConfigProviderOutput;
59
-
60
- declare const useTokenCookie: (tokenName: OAuthTokens) => string | null;
61
-
62
- type IframeProviderOutput = {
63
- iframeRef: RefObject<HTMLIFrameElement> | null;
64
- setAuthResponseUrl: Dispatch<SetStateAction<string | null>>;
65
- };
66
-
67
- declare const useIframe: () => IframeProviderOutput;
68
-
69
- type CivicAuthIframeContainerProps = {
70
- onClose?: () => void;
71
- closeOnRedirect?: boolean;
72
- };
73
- declare const CivicAuthIframeContainer: ({ onClose, closeOnRedirect, }: CivicAuthIframeContainerProps) => react_jsx_runtime.JSX.Element;
74
-
75
101
  declare const UserButton: ({ displayMode, className, }: {
76
102
  displayMode?: DisplayMode;
77
103
  className?: string;
@@ -90,4 +116,4 @@ declare const NextLogOut: ({ children }: {
90
116
  children: ReactNode;
91
117
  }) => react_jsx_runtime.JSX.Element;
92
118
 
93
- export { AuthContextType, CivicAuthIframeContainer, CivicAuthProvider, type CivicAuthProviderProps, CivicNextAuthProvider, type NextCivicAuthProviderProps, NextLogOut, SignInButton, SignOutButton, type TokenContextType, UserButton, UserContextType, useAuth, useConfig, useIframe, useSession, useToken, useTokenCookie, useUser, useUserCookie };
119
+ export { type AuthContextType, CivicAuthProvider, CivicNextAuthProvider, NextLogOut, SignInButton, SignOutButton, type TokenContextType, UserButton, type UserContextType$1 as UserContextType, useAuth, useNextUser, useSession, useToken, useUser, useUserCookie };