@civic/auth 0.0.1-beta.19 → 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 (84) 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-CRTRMMJ7.js.map +1 -1
  5. package/dist/chunk-KS7ERXGZ.js +481 -0
  6. package/dist/chunk-KS7ERXGZ.js.map +1 -0
  7. package/dist/chunk-NINRO7GS.js +209 -0
  8. package/dist/chunk-NINRO7GS.js.map +1 -0
  9. package/dist/chunk-NXBKSUKI.mjs +481 -0
  10. package/dist/chunk-NXBKSUKI.mjs.map +1 -0
  11. package/dist/chunk-T7HUHQ3J.mjs +209 -0
  12. package/dist/chunk-T7HUHQ3J.mjs.map +1 -0
  13. package/dist/chunk-WZLC5B4C.js +17 -0
  14. package/dist/chunk-WZLC5B4C.js.map +1 -0
  15. package/dist/index-DoDoIY_K.d.mts +79 -0
  16. package/dist/index-DoDoIY_K.d.ts +79 -0
  17. package/dist/index.css +70 -63
  18. package/dist/index.css.map +1 -1
  19. package/dist/index.d.mts +1 -3
  20. package/dist/index.d.ts +1 -3
  21. package/dist/index.js +1 -2
  22. package/dist/index.js.map +1 -1
  23. package/dist/index.mjs +0 -1
  24. package/dist/nextjs.d.mts +15 -42
  25. package/dist/nextjs.d.ts +15 -42
  26. package/dist/nextjs.js +180 -156
  27. package/dist/nextjs.js.map +1 -1
  28. package/dist/nextjs.mjs +177 -153
  29. package/dist/nextjs.mjs.map +1 -1
  30. package/dist/react.d.mts +81 -31
  31. package/dist/react.d.ts +81 -31
  32. package/dist/react.js +634 -35
  33. package/dist/react.js.map +1 -1
  34. package/dist/react.mjs +664 -65
  35. package/dist/react.mjs.map +1 -1
  36. package/dist/server.d.mts +34 -14
  37. package/dist/server.d.ts +34 -14
  38. package/dist/server.js +185 -4
  39. package/dist/server.js.map +1 -1
  40. package/dist/server.mjs +191 -10
  41. package/dist/server.mjs.map +1 -1
  42. package/package.json +17 -26
  43. package/dist/AuthProvider-Bj_Prt1x.d.ts +0 -21
  44. package/dist/AuthProvider-DUAoX4G9.d.mts +0 -21
  45. package/dist/UserProvider-CMLaYOUD.d.ts +0 -16
  46. package/dist/UserProvider-Cbm8MZkJ.d.mts +0 -16
  47. package/dist/chunk-5UQQYXCX.js +0 -1
  48. package/dist/chunk-5UQQYXCX.js.map +0 -1
  49. package/dist/chunk-BFESCRFK.mjs +0 -118
  50. package/dist/chunk-BFESCRFK.mjs.map +0 -1
  51. package/dist/chunk-CBQ3HKRV.mjs +0 -599
  52. package/dist/chunk-CBQ3HKRV.mjs.map +0 -1
  53. package/dist/chunk-CZ3AVCKD.js +0 -171
  54. package/dist/chunk-CZ3AVCKD.js.map +0 -1
  55. package/dist/chunk-DJFTZS4P.js +0 -118
  56. package/dist/chunk-DJFTZS4P.js.map +0 -1
  57. package/dist/chunk-HTTTZ2BP.mjs +0 -223
  58. package/dist/chunk-HTTTZ2BP.mjs.map +0 -1
  59. package/dist/chunk-O2SODTR3.js +0 -599
  60. package/dist/chunk-O2SODTR3.js.map +0 -1
  61. package/dist/chunk-O6DPCPRH.js +0 -223
  62. package/dist/chunk-O6DPCPRH.js.map +0 -1
  63. package/dist/chunk-PMJAV4JJ.mjs +0 -1
  64. package/dist/chunk-PMJAV4JJ.mjs.map +0 -1
  65. package/dist/chunk-UADVRCHY.mjs +0 -710
  66. package/dist/chunk-UADVRCHY.mjs.map +0 -1
  67. package/dist/chunk-VJVRFKDH.js +0 -710
  68. package/dist/chunk-VJVRFKDH.js.map +0 -1
  69. package/dist/chunk-X3FQBE22.mjs +0 -171
  70. package/dist/chunk-X3FQBE22.mjs.map +0 -1
  71. package/dist/nextjs/client.css +0 -335
  72. package/dist/nextjs/client.css.map +0 -1
  73. package/dist/nextjs/client.d.mts +0 -12
  74. package/dist/nextjs/client.d.ts +0 -12
  75. package/dist/nextjs/client.js +0 -179
  76. package/dist/nextjs/client.js.map +0 -1
  77. package/dist/nextjs/client.mjs +0 -179
  78. package/dist/nextjs/client.mjs.map +0 -1
  79. package/dist/storage-B2eAQNdv.d.ts +0 -25
  80. package/dist/storage-BJPUpxhm.d.mts +0 -25
  81. package/dist/types-Bqm9OCZN.d.mts +0 -22
  82. package/dist/types-Bqm9OCZN.d.ts +0 -22
  83. package/dist/types-HdCjGldB.d.mts +0 -58
  84. package/dist/types-HdCjGldB.d.ts +0 -58
package/dist/react.d.mts CHANGED
@@ -1,10 +1,20 @@
1
- import { U as UserContextType, A as AuthContextType } from './UserProvider-Cbm8MZkJ.mjs';
2
- import { F as ForwardedTokens, C as Config, S as SessionData, D as DisplayMode } from './types-HdCjGldB.mjs';
3
- import { RefObject, Dispatch, SetStateAction, ReactNode } 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.mjs';
4
3
  import * as react_jsx_runtime from 'react/jsx-runtime';
5
- import { A as AuthProviderProps } from './AuthProvider-DUAoX4G9.mjs';
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,38 +25,78 @@ type TokenContextType = {
15
25
  error: Error | null;
16
26
  };
17
27
 
18
- type CivicAuthProviderProps = Omit<AuthProviderProps, "pkceConsumer">;
19
- declare const CivicAuthProvider: ({ children, ...props }: CivicAuthProviderProps) => react_jsx_runtime.JSX.Element;
20
-
21
- declare const useUser: <T extends Record<string, unknown> = Record<string, never>>() => UserContextType<T>;
22
-
23
- declare const useToken: () => TokenContextType;
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>;
67
+ }
68
+
69
+ type AuthProviderProps = {
70
+ children: ReactNode;
71
+ clientId: string;
72
+ redirectUrl?: string;
73
+ nonce?: string;
74
+ config?: Config;
75
+ onSignIn?: (error?: Error) => void;
76
+ onSignOut?: () => void;
77
+ authServiceImpl?: AuthSessionServiceImpl;
78
+ serverSideTokenExchange?: boolean;
79
+ };
24
80
 
25
- declare const useAuth: () => AuthContextType;
81
+ type CivicAuthProviderProps = Omit<AuthProviderProps, "authServiceImpl" | "serverSideTokenExchange">;
82
+ declare const CivicAuthProvider: ({ children, ...props }: CivicAuthProviderProps) => react_jsx_runtime.JSX.Element;
26
83
 
27
- type ConfigProviderOutput = {
28
- config: Config;
29
- redirectUrl: string;
30
- modalIframe: boolean;
31
- serverTokenExchange: boolean;
84
+ type UserContextType = {
85
+ user: User<UnknownObject> | null;
32
86
  };
87
+ type NextCivicAuthProviderProps = Omit<AuthProviderProps, "clientId">;
88
+ declare const CivicNextAuthProvider: ({ children, ...props }: NextCivicAuthProviderProps) => react_jsx_runtime.JSX.Element;
89
+ declare const useNextUser: () => UserContextType;
33
90
 
34
- declare const useConfig: () => ConfigProviderOutput;
91
+ declare const useUser: <T extends Record<string, unknown> = Record<string, never>>() => UserContextType$1<T>;
35
92
 
36
- type IframeProviderOutput = {
37
- iframeRef: RefObject<HTMLIFrameElement> | null;
38
- setAuthResponseUrl: Dispatch<SetStateAction<string | null>>;
39
- };
93
+ declare const useUserCookie: () => any;
40
94
 
41
- declare const useIframe: () => IframeProviderOutput;
95
+ declare const useToken: () => TokenContextType;
42
96
 
43
- declare const useSession: () => SessionData;
97
+ declare const useAuth: () => AuthContextType;
44
98
 
45
- type CivicAuthIframeContainerProps = {
46
- onClose?: () => void;
47
- closeOnRedirect?: boolean;
48
- };
49
- declare const CivicAuthIframeContainer: ({ onClose, closeOnRedirect, }: CivicAuthIframeContainerProps) => react_jsx_runtime.JSX.Element;
99
+ declare const useSession: () => SessionData;
50
100
 
51
101
  declare const UserButton: ({ displayMode, className, }: {
52
102
  displayMode?: DisplayMode;
@@ -66,4 +116,4 @@ declare const NextLogOut: ({ children }: {
66
116
  children: ReactNode;
67
117
  }) => react_jsx_runtime.JSX.Element;
68
118
 
69
- export { AuthContextType, CivicAuthIframeContainer, CivicAuthProvider, type CivicAuthProviderProps, NextLogOut, SignInButton, SignOutButton, type TokenContextType, UserButton, UserContextType, useAuth, useConfig, useIframe, useSession, useToken, useUser };
119
+ export { type AuthContextType, CivicAuthProvider, CivicNextAuthProvider, NextLogOut, SignInButton, SignOutButton, type TokenContextType, UserButton, type UserContextType$1 as UserContextType, useAuth, useNextUser, useSession, useToken, useUser, useUserCookie };
package/dist/react.d.ts CHANGED
@@ -1,10 +1,20 @@
1
- import { U as UserContextType, A as AuthContextType } from './UserProvider-CMLaYOUD.js';
2
- import { F as ForwardedTokens, C as Config, S as SessionData, D as DisplayMode } from './types-HdCjGldB.js';
3
- import { RefObject, Dispatch, SetStateAction, ReactNode } 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';
4
3
  import * as react_jsx_runtime from 'react/jsx-runtime';
5
- import { A as AuthProviderProps } from './AuthProvider-Bj_Prt1x.js';
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,38 +25,78 @@ type TokenContextType = {
15
25
  error: Error | null;
16
26
  };
17
27
 
18
- type CivicAuthProviderProps = Omit<AuthProviderProps, "pkceConsumer">;
19
- declare const CivicAuthProvider: ({ children, ...props }: CivicAuthProviderProps) => react_jsx_runtime.JSX.Element;
20
-
21
- declare const useUser: <T extends Record<string, unknown> = Record<string, never>>() => UserContextType<T>;
22
-
23
- declare const useToken: () => TokenContextType;
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>;
67
+ }
68
+
69
+ type AuthProviderProps = {
70
+ children: ReactNode;
71
+ clientId: string;
72
+ redirectUrl?: string;
73
+ nonce?: string;
74
+ config?: Config;
75
+ onSignIn?: (error?: Error) => void;
76
+ onSignOut?: () => void;
77
+ authServiceImpl?: AuthSessionServiceImpl;
78
+ serverSideTokenExchange?: boolean;
79
+ };
24
80
 
25
- declare const useAuth: () => AuthContextType;
81
+ type CivicAuthProviderProps = Omit<AuthProviderProps, "authServiceImpl" | "serverSideTokenExchange">;
82
+ declare const CivicAuthProvider: ({ children, ...props }: CivicAuthProviderProps) => react_jsx_runtime.JSX.Element;
26
83
 
27
- type ConfigProviderOutput = {
28
- config: Config;
29
- redirectUrl: string;
30
- modalIframe: boolean;
31
- serverTokenExchange: boolean;
84
+ type UserContextType = {
85
+ user: User<UnknownObject> | null;
32
86
  };
87
+ type NextCivicAuthProviderProps = Omit<AuthProviderProps, "clientId">;
88
+ declare const CivicNextAuthProvider: ({ children, ...props }: NextCivicAuthProviderProps) => react_jsx_runtime.JSX.Element;
89
+ declare const useNextUser: () => UserContextType;
33
90
 
34
- declare const useConfig: () => ConfigProviderOutput;
91
+ declare const useUser: <T extends Record<string, unknown> = Record<string, never>>() => UserContextType$1<T>;
35
92
 
36
- type IframeProviderOutput = {
37
- iframeRef: RefObject<HTMLIFrameElement> | null;
38
- setAuthResponseUrl: Dispatch<SetStateAction<string | null>>;
39
- };
93
+ declare const useUserCookie: () => any;
40
94
 
41
- declare const useIframe: () => IframeProviderOutput;
95
+ declare const useToken: () => TokenContextType;
42
96
 
43
- declare const useSession: () => SessionData;
97
+ declare const useAuth: () => AuthContextType;
44
98
 
45
- type CivicAuthIframeContainerProps = {
46
- onClose?: () => void;
47
- closeOnRedirect?: boolean;
48
- };
49
- declare const CivicAuthIframeContainer: ({ onClose, closeOnRedirect, }: CivicAuthIframeContainerProps) => react_jsx_runtime.JSX.Element;
99
+ declare const useSession: () => SessionData;
50
100
 
51
101
  declare const UserButton: ({ displayMode, className, }: {
52
102
  displayMode?: DisplayMode;
@@ -66,4 +116,4 @@ declare const NextLogOut: ({ children }: {
66
116
  children: ReactNode;
67
117
  }) => react_jsx_runtime.JSX.Element;
68
118
 
69
- export { AuthContextType, CivicAuthIframeContainer, CivicAuthProvider, type CivicAuthProviderProps, NextLogOut, SignInButton, SignOutButton, type TokenContextType, UserButton, UserContextType, useAuth, useConfig, useIframe, useSession, useToken, useUser };
119
+ export { type AuthContextType, CivicAuthProvider, CivicNextAuthProvider, NextLogOut, SignInButton, SignOutButton, type TokenContextType, UserButton, type UserContextType$1 as UserContextType, useAuth, useNextUser, useSession, useToken, useUser, useUserCookie };