@react-keycloak-refork/core 5.0.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/LICENSE.md ADDED
@@ -0,0 +1,24 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2019-present, Mattia Panzeri <mattia.panzeri93@gmail.com>
4
+
5
+ Permission is hereby granted, free of charge, to any person
6
+ obtaining a copy of this software and associated documentation
7
+ files (the "Software"), to deal in the Software without
8
+ restriction, including without limitation the rights to use,
9
+ copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the
11
+ Software is furnished to do so, subject to the following
12
+ conditions:
13
+
14
+ The above copyright notice and this permission notice shall be
15
+ included in all copies or substantial portions of the Software.
16
+
17
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
19
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
21
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
22
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
24
+ OTHER DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,150 @@
1
+ ![React Keycloak](/art/react-keycloak-logo.png?raw=true 'React Keycloak Logo')
2
+
3
+ # React Keycloak (Keycloak >=v26 Fork) <!-- omit in toc -->
4
+
5
+ > React bindings for [Keycloak](https://www.keycloak.org/). Fork of https://github.com/react-keycloak/react-keycloak.git with updated packages for keycloak >=26 support.
6
+
7
+ ⚠️ **IMPORTANT NOTICE**: This fork has been updated to support Keycloak 26, but it is **NOT MAINTAINED**. We strongly recommend migrating to [NextAuth.js](https://next-auth.js.org/) for new projects, as it provides better maintenance, security updates, and broader OAuth provider support.
8
+
9
+ [![NPM (scoped)](https://img.shields.io/npm/v/@react-keycloak-fork/core?label=npm%20%7C%20core)](https://www.npmjs.com/package/@react-keycloak-refork/core)
10
+ [![NPM (scoped)](https://img.shields.io/npm/v/@react-keycloak-fork/web?label=npm%20%7C%20web)](https://www.npmjs.com/package/@react-keycloak-refork/web)
11
+ [![NPM (scoped)](https://img.shields.io/npm/v/@react-keycloak-fork/ssr?label=npm%20%7C%20ssr)](https://www.npmjs.com/package/@react-keycloak-refork/ssr)
12
+ [![NPM (scoped)](https://img.shields.io/npm/v/@react-keycloak-fork/native?label=npm%20%7C%20native)](https://www.npmjs.com/package/@react-keycloak-refork/native)
13
+
14
+ [![License](https://img.shields.io/github/license/react-keycloak/react-keycloak.svg)](https://github.com/react-keycloak/react-keycloak-fork/blob/master/LICENSE.md)
15
+ [![lerna](https://img.shields.io/badge/maintained%20with-lerna-cc00ff.svg)](https://lerna.js.org/)
16
+ [![GitHub contributors](https://img.shields.io/github/contributors/react-keycloak/react-keycloak)](https://github.com/react-keycloak/react-keycloak-fork/graphs/contributors)
17
+ [![Github Issues](https://img.shields.io/github/issues/react-keycloak/react-keycloak.svg)](https://github.com/react-keycloak/react-keycloak/issues) ![npm](https://img.shields.io/npm/dm/@react-keycloak-refork/core)
18
+
19
+ [![Gitter](https://img.shields.io/gitter/room/react-keycloak/community)](https://gitter.im/react-keycloak/community)
20
+
21
+ ---
22
+
23
+ ## Table of Contents <!-- omit in toc -->
24
+
25
+ - [Integrations](#integrations)
26
+ - [React](#react)
27
+ - [SSR](#ssr)
28
+ - [React Native](#react-native)
29
+ - [Support](#support)
30
+ - [Examples](#examples)
31
+ - [Alternatives](#alternatives)
32
+ - [Contributing](#contributing)
33
+ - [License](#license)
34
+
35
+ ---
36
+
37
+ ## Integrations
38
+
39
+ ### React
40
+
41
+ React Keycloak for Web requires:
42
+
43
+ - React **18.0** or later
44
+ - `keycloak-js` **26.0.0** or later
45
+
46
+ ```shell
47
+ yarn add @react-keycloak-refork/web
48
+ ```
49
+
50
+ or
51
+
52
+ ```shell
53
+ npm install --save @react-keycloak-refork/web
54
+ ```
55
+
56
+ or as a `UMD` package through `unpkg`
57
+
58
+ See `@react-keycloak-refork/web` package [README](https://github.com/react-keycloak/react-keycloak/blob/master/packages/web/README.md) for complete documentation.
59
+
60
+ ### SSR
61
+
62
+ React Keycloak for SSR frameworks requires:
63
+
64
+ - React **18.0** or later
65
+ - SSR Framework:
66
+ - NextJS **9** or later
67
+ - Razzle **3** or later
68
+ - `keycloak-js` **26.0.0** or later
69
+
70
+ ```shell
71
+ yarn add @react-keycloak-refork/ssr
72
+ ```
73
+
74
+ or
75
+
76
+ ```shell
77
+ npm install --save @react-keycloak-refork/ssr
78
+ ```
79
+
80
+ See `@react-keycloak-refork/ssr` package [README](https://github.com/react-keycloak/react-keycloak/blob/master/packages/ssr/README.md) for complete documentation.
81
+
82
+ ### React Native
83
+
84
+ React Keycloak for React Native requires React Native **61.0** or later
85
+
86
+ To install run
87
+
88
+ ```shell
89
+ yarn add @react-keycloak-refork/native
90
+ ```
91
+
92
+ or
93
+
94
+ ```shell
95
+ npm install --save @react-keycloak-refork/native
96
+ ```
97
+
98
+ See `@react-keycloak-refork/native` package [README](https://github.com/react-keycloak/react-native-keycloak/blob/master/README.md) for complete documentation.
99
+
100
+ ## Support
101
+
102
+ | version | keycloak-js version | notes |
103
+ | ------- | ------------------- | ------ |
104
+ | v5.0.0+ | 26.0.0+ | (fork) |
105
+ | v4.0.3+ | 26.0.0+ | (fork) |
106
+ | v4.0.1+ | 17.0.0+ | (fork) |
107
+ | v2.0.0+ | 9.0.2+ |
108
+ | v1.x | >=8.0.2 <9.0.2 |
109
+
110
+ ## Examples
111
+
112
+ See [`@react-keycloak-fork/react-keycloak-examples`](https://github.com/react-keycloak/react-keycloak-examples) repository for various demo implementing this library main features.
113
+
114
+ ## Alternatives
115
+
116
+ If you need to connect using a more generic OIDC client instead of `keycloak.js`, consider using one of the following libraries:
117
+
118
+ - [bjerkio/oidc-react](https://github.com/bjerkio/oidc-react)
119
+ - [thchia/react-oidc](https://github.com/thchia/react-oidc)
120
+ - [@axa-fr/react-oidc](https://github.com/AxaGuilDEv/react-oidc)
121
+
122
+ ## Migration Notice
123
+
124
+ ⚠️ **This project is no longer maintained**. For new projects, we strongly recommend using [NextAuth.js](https://next-auth.js.org/) instead, which provides:
125
+
126
+ - ✅ Active maintenance and security updates
127
+ - ✅ Support for 50+ OAuth providers including Keycloak
128
+ - ✅ Better TypeScript support
129
+ - ✅ Modern React patterns and hooks
130
+ - ✅ Comprehensive documentation and examples
131
+ - ✅ Active community and support
132
+
133
+ ### Migrating to NextAuth.js
134
+
135
+ To migrate from this library to NextAuth.js with Keycloak:
136
+
137
+ 1. Install NextAuth.js: `npm install next-auth`
138
+ 2. Configure Keycloak as a provider in your NextAuth configuration
139
+ 3. Replace `useKeycloak()` hooks with NextAuth's `useSession()` and `signIn()`/`signOut()` functions
140
+ 4. Update your authentication logic to use NextAuth's session management
141
+
142
+ See the [NextAuth.js documentation](https://next-auth.js.org/configuration/providers/keycloak) for detailed migration instructions.
143
+
144
+ ## Contributing
145
+
146
+ See the [contributing guide](CONTRIBUTING.md) to learn how to contribute to the repository and the development workflow.
147
+
148
+ ## License
149
+
150
+ MIT
@@ -0,0 +1,24 @@
1
+ /// <reference types="react" />
2
+ import { AuthClient } from './types';
3
+ /**
4
+ * Auth Context props
5
+ */
6
+ export type IAuthContextProps<T extends AuthClient> = {
7
+ /**
8
+ * The single AuthClient of your application.
9
+ */
10
+ authClient?: T;
11
+ /**
12
+ * Boolean indicating whenever the AuthClient has been initialized by AuthProvider
13
+ */
14
+ initialized: boolean;
15
+ };
16
+ /**
17
+ * Create a React context containing an AuthClient instance.
18
+ *
19
+ * @param {IAuthContextProps} initialContext initial context value.
20
+ *
21
+ * @returns {React.Context} the ReactKeycloak context.
22
+ */
23
+ export declare function createAuthContext<T extends AuthClient>(initialContext?: Partial<IAuthContextProps<T>>): React.Context<IAuthContextProps<T>>;
24
+ export default createAuthContext;
package/lib/context.js ADDED
@@ -0,0 +1,24 @@
1
+ var __assign = (this && this.__assign) || function () {
2
+ __assign = Object.assign || function(t) {
3
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
4
+ s = arguments[i];
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
+ t[p] = s[p];
7
+ }
8
+ return t;
9
+ };
10
+ return __assign.apply(this, arguments);
11
+ };
12
+ import { createContext } from 'react';
13
+ /**
14
+ * Create a React context containing an AuthClient instance.
15
+ *
16
+ * @param {IAuthContextProps} initialContext initial context value.
17
+ *
18
+ * @returns {React.Context} the ReactKeycloak context.
19
+ */
20
+ export function createAuthContext(initialContext) {
21
+ return createContext(__assign({ initialized: false }, initialContext));
22
+ }
23
+ export default createAuthContext;
24
+ //# sourceMappingURL=context.js.map
@@ -0,0 +1,10 @@
1
+ {
2
+ "version": 3,
3
+ "file": "context.js",
4
+ "sourceRoot": "",
5
+ "sources": [
6
+ "@react-keycloak-refork\\core\\context.ts"
7
+ ],
8
+ "names": [],
9
+ "mappings": ";;;;;;;;;;;AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,OAAO,CAAA;AAmBrC;;;;;;GAMG;AACH,MAAM,UAAU,iBAAiB,CAC/B,cAA8C;IAE9C,OAAO,aAAa,YAClB,WAAW,EAAE,KAAK,IACf,cAAc,EACjB,CAAA;AACJ,CAAC;AAED,eAAe,iBAAiB,CAAA"
10
+ }
package/lib/index.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ export * from './context';
2
+ export * from './provider';
3
+ export * from './types';
package/lib/index.js ADDED
@@ -0,0 +1,5 @@
1
+ /* istanbul ignore file */
2
+ export * from './context';
3
+ export * from './provider';
4
+ export * from './types';
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,10 @@
1
+ {
2
+ "version": 3,
3
+ "file": "index.js",
4
+ "sourceRoot": "",
5
+ "sources": [
6
+ "@react-keycloak-refork\\core\\index.ts"
7
+ ],
8
+ "names": [],
9
+ "mappings": "AAAA,0BAA0B;AAE1B,cAAc,WAAW,CAAA;AACzB,cAAc,YAAY,CAAA;AAC1B,cAAc,SAAS,CAAA"
10
+ }
@@ -0,0 +1,132 @@
1
+ import * as React from 'react';
2
+ import { ReactNode } from 'react';
3
+ import { IAuthContextProps } from './context';
4
+ import { AuthClient, AuthClientError, AuthClientEvent, AuthClientInitOptions, AuthClientTokens } from './types';
5
+ /**
6
+ * Props that can be passed to AuthProvider
7
+ */
8
+ export type AuthProviderProps<T extends AuthClient> = {
9
+ /**
10
+ * The single AuthClient instance to be used by your application.
11
+ */
12
+ authClient: T;
13
+ /**
14
+ * The single AuthClient instance to be used by your application.
15
+ */
16
+ children: React.JSXElementConstructor<{
17
+ children: React.ReactElement | ReactNode | Element;
18
+ }> | any;
19
+ /**
20
+ * A flag to enable automatic token refresh. Defaults to true.
21
+ * This is useful if you need to disable it (not recommended).
22
+ *
23
+ * @default true
24
+ */
25
+ autoRefreshToken?: boolean;
26
+ /**
27
+ * The config to be used when initializing AuthClient instance.
28
+ */
29
+ initOptions?: AuthClientInitOptions;
30
+ /**
31
+ * An optional loading check function to customize LoadingComponent display condition.
32
+ * Return `true` to display LoadingComponent, `false` to hide it.
33
+ *
34
+ * @param authClient the current AuthClient instance.
35
+ *
36
+ * @returns {boolean} Set to true to display LoadingComponent, false to hide it.
37
+ */
38
+ isLoadingCheck?: (authClient: T) => boolean;
39
+ /**
40
+ * An optional component to display while AuthClient instance is being initialized.
41
+ */
42
+ LoadingComponent?: JSX.Element;
43
+ /**
44
+ * An optional function to receive AuthClient events as they happen.
45
+ */
46
+ onEvent?: (eventType: AuthClientEvent, error?: AuthClientError) => void;
47
+ /**
48
+ * An optional function to receive AuthClient tokens when changed.
49
+ *
50
+ * @param {AuthClientTokens} tokens The current AuthClient tokens set.
51
+ */
52
+ onTokens?: (tokens: AuthClientTokens) => void;
53
+ };
54
+ type AuthProviderState = {
55
+ initialized: boolean;
56
+ isAuthenticated: boolean;
57
+ isLoading: boolean;
58
+ };
59
+ /**
60
+ * Create an AuthProvider component to wrap a React app with, it will take care of common AuthClient
61
+ * lifecycle handling (such as initialization and token refresh).
62
+ *
63
+ * @param AuthContext the Auth context to be used by the created AuthProvider
64
+ *
65
+ * @returns the AuthProvider component
66
+ */
67
+ export declare function createAuthProvider<T extends AuthClient>(AuthContext: React.Context<IAuthContextProps<T>>): {
68
+ new (props: AuthProviderProps<T>): {
69
+ state: {
70
+ initialized: boolean;
71
+ isAuthenticated: boolean;
72
+ isLoading: boolean;
73
+ };
74
+ componentDidMount(): void;
75
+ componentDidUpdate({ authClient: prevAuthClient, initOptions: prevInitOptions, }: AuthProviderProps<T>): void;
76
+ init(): void;
77
+ onError: (event: AuthClientEvent) => (error?: AuthClientError) => void;
78
+ updateState: (event: AuthClientEvent) => () => void;
79
+ refreshToken: (event: AuthClientEvent) => () => void;
80
+ render(): React.JSX.Element;
81
+ context: unknown;
82
+ setState<K extends keyof AuthProviderState>(state: AuthProviderState | ((prevState: Readonly<AuthProviderState>, props: Readonly<AuthProviderProps<T>>) => AuthProviderState | Pick<AuthProviderState, K> | null) | Pick<AuthProviderState, K> | null, callback?: (() => void) | undefined): void;
83
+ forceUpdate(callback?: (() => void) | undefined): void;
84
+ readonly props: Readonly<AuthProviderProps<T>>;
85
+ refs: {
86
+ [key: string]: React.ReactInstance;
87
+ };
88
+ shouldComponentUpdate?(nextProps: Readonly<AuthProviderProps<T>>, nextState: Readonly<AuthProviderState>, nextContext: any): boolean;
89
+ componentWillUnmount?(): void;
90
+ componentDidCatch?(error: Error, errorInfo: React.ErrorInfo): void;
91
+ getSnapshotBeforeUpdate?(prevProps: Readonly<AuthProviderProps<T>>, prevState: Readonly<AuthProviderState>): any;
92
+ componentWillMount?(): void;
93
+ UNSAFE_componentWillMount?(): void;
94
+ componentWillReceiveProps?(nextProps: Readonly<AuthProviderProps<T>>, nextContext: any): void;
95
+ UNSAFE_componentWillReceiveProps?(nextProps: Readonly<AuthProviderProps<T>>, nextContext: any): void;
96
+ componentWillUpdate?(nextProps: Readonly<AuthProviderProps<T>>, nextState: Readonly<AuthProviderState>, nextContext: any): void;
97
+ UNSAFE_componentWillUpdate?(nextProps: Readonly<AuthProviderProps<T>>, nextState: Readonly<AuthProviderState>, nextContext: any): void;
98
+ };
99
+ new (props: AuthProviderProps<T>, context: any): {
100
+ state: {
101
+ initialized: boolean;
102
+ isAuthenticated: boolean;
103
+ isLoading: boolean;
104
+ };
105
+ componentDidMount(): void;
106
+ componentDidUpdate({ authClient: prevAuthClient, initOptions: prevInitOptions, }: AuthProviderProps<T>): void;
107
+ init(): void;
108
+ onError: (event: AuthClientEvent) => (error?: AuthClientError) => void;
109
+ updateState: (event: AuthClientEvent) => () => void;
110
+ refreshToken: (event: AuthClientEvent) => () => void;
111
+ render(): React.JSX.Element;
112
+ context: unknown;
113
+ setState<K extends keyof AuthProviderState>(state: AuthProviderState | ((prevState: Readonly<AuthProviderState>, props: Readonly<AuthProviderProps<T>>) => AuthProviderState | Pick<AuthProviderState, K> | null) | Pick<AuthProviderState, K> | null, callback?: (() => void) | undefined): void;
114
+ forceUpdate(callback?: (() => void) | undefined): void;
115
+ readonly props: Readonly<AuthProviderProps<T>>;
116
+ refs: {
117
+ [key: string]: React.ReactInstance;
118
+ };
119
+ shouldComponentUpdate?(nextProps: Readonly<AuthProviderProps<T>>, nextState: Readonly<AuthProviderState>, nextContext: any): boolean;
120
+ componentWillUnmount?(): void;
121
+ componentDidCatch?(error: Error, errorInfo: React.ErrorInfo): void;
122
+ getSnapshotBeforeUpdate?(prevProps: Readonly<AuthProviderProps<T>>, prevState: Readonly<AuthProviderState>): any;
123
+ componentWillMount?(): void;
124
+ UNSAFE_componentWillMount?(): void;
125
+ componentWillReceiveProps?(nextProps: Readonly<AuthProviderProps<T>>, nextContext: any): void;
126
+ UNSAFE_componentWillReceiveProps?(nextProps: Readonly<AuthProviderProps<T>>, nextContext: any): void;
127
+ componentWillUpdate?(nextProps: Readonly<AuthProviderProps<T>>, nextState: Readonly<AuthProviderState>, nextContext: any): void;
128
+ UNSAFE_componentWillUpdate?(nextProps: Readonly<AuthProviderProps<T>>, nextState: Readonly<AuthProviderState>, nextContext: any): void;
129
+ };
130
+ contextType?: React.Context<any> | undefined;
131
+ };
132
+ export default createAuthProvider;
@@ -0,0 +1,146 @@
1
+ var __extends = (this && this.__extends) || (function () {
2
+ var extendStatics = function (d, b) {
3
+ extendStatics = Object.setPrototypeOf ||
4
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
5
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
6
+ return extendStatics(d, b);
7
+ };
8
+ return function (d, b) {
9
+ if (typeof b !== "function" && b !== null)
10
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
11
+ extendStatics(d, b);
12
+ function __() { this.constructor = d; }
13
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
14
+ };
15
+ })();
16
+ var __assign = (this && this.__assign) || function () {
17
+ __assign = Object.assign || function(t) {
18
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
19
+ s = arguments[i];
20
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
21
+ t[p] = s[p];
22
+ }
23
+ return t;
24
+ };
25
+ return __assign.apply(this, arguments);
26
+ };
27
+ import * as React from 'react';
28
+ import isEqual from 'react-fast-compare';
29
+ /**
30
+ * Create an AuthProvider component to wrap a React app with, it will take care of common AuthClient
31
+ * lifecycle handling (such as initialization and token refresh).
32
+ *
33
+ * @param AuthContext the Auth context to be used by the created AuthProvider
34
+ *
35
+ * @returns the AuthProvider component
36
+ */
37
+ export function createAuthProvider(AuthContext) {
38
+ var defaultInitOptions = {
39
+ onLoad: 'check-sso',
40
+ };
41
+ var initialState = {
42
+ initialized: false,
43
+ isAuthenticated: false,
44
+ isLoading: true,
45
+ };
46
+ return /** @class */ (function (_super) {
47
+ __extends(KeycloakProvider, _super);
48
+ function KeycloakProvider() {
49
+ var _this = _super !== null && _super.apply(this, arguments) || this;
50
+ _this.state = __assign({}, initialState);
51
+ _this.onError = function (event) { return function (error) {
52
+ var onEvent = _this.props.onEvent;
53
+ // Notify Events listener
54
+ onEvent && onEvent(event, error);
55
+ }; };
56
+ _this.updateState = function (event) { return function () {
57
+ var _a = _this.props, authClient = _a.authClient, onEvent = _a.onEvent, onTokens = _a.onTokens, isLoadingCheck = _a.isLoadingCheck;
58
+ var _b = _this.state, prevInitialized = _b.initialized, prevAuthenticated = _b.isAuthenticated, prevLoading = _b.isLoading;
59
+ // Notify Events listener
60
+ onEvent && onEvent(event);
61
+ // Check Loading state
62
+ var isLoading = isLoadingCheck ? isLoadingCheck(authClient) : false;
63
+ // Check if user is authenticated
64
+ var isAuthenticated = isUserAuthenticated(authClient);
65
+ // Avoid double-refresh if state hasn't changed
66
+ if (!prevInitialized ||
67
+ isAuthenticated !== prevAuthenticated ||
68
+ isLoading !== prevLoading) {
69
+ _this.setState({
70
+ initialized: true,
71
+ isAuthenticated: isAuthenticated,
72
+ isLoading: isLoading,
73
+ });
74
+ }
75
+ // Notify token listener, if any
76
+ var idToken = authClient.idToken, refreshToken = authClient.refreshToken, token = authClient.token;
77
+ onTokens &&
78
+ onTokens({
79
+ idToken: idToken,
80
+ refreshToken: refreshToken,
81
+ token: token,
82
+ });
83
+ }; };
84
+ _this.refreshToken = function (event) { return function () {
85
+ var _a = _this.props, autoRefreshToken = _a.autoRefreshToken, authClient = _a.authClient, onEvent = _a.onEvent;
86
+ // Notify Events listener
87
+ onEvent && onEvent(event);
88
+ if (autoRefreshToken !== false) {
89
+ // Refresh Keycloak token
90
+ authClient.updateToken(5);
91
+ }
92
+ }; };
93
+ return _this;
94
+ }
95
+ KeycloakProvider.prototype.componentDidMount = function () {
96
+ this.init();
97
+ };
98
+ KeycloakProvider.prototype.componentDidUpdate = function (_a) {
99
+ var prevAuthClient = _a.authClient, prevInitOptions = _a.initOptions;
100
+ var _b = this.props, initOptions = _b.initOptions, authClient = _b.authClient;
101
+ if (authClient !== prevAuthClient ||
102
+ !isEqual(initOptions, prevInitOptions)) {
103
+ // De-init previous AuthClient instance
104
+ prevAuthClient.onReady = undefined;
105
+ prevAuthClient.onAuthSuccess = undefined;
106
+ prevAuthClient.onAuthError = undefined;
107
+ prevAuthClient.onAuthRefreshSuccess = undefined;
108
+ prevAuthClient.onAuthRefreshError = undefined;
109
+ prevAuthClient.onAuthLogout = undefined;
110
+ prevAuthClient.onTokenExpired = undefined;
111
+ // Reset state
112
+ this.setState(__assign({}, initialState));
113
+ // Init new AuthClient instance
114
+ this.init();
115
+ }
116
+ };
117
+ KeycloakProvider.prototype.init = function () {
118
+ var _a = this.props, initOptions = _a.initOptions, authClient = _a.authClient;
119
+ // Attach Keycloak listeners
120
+ authClient.onReady = this.updateState('onReady');
121
+ authClient.onAuthSuccess = this.updateState('onAuthSuccess');
122
+ authClient.onAuthError = this.onError('onAuthError');
123
+ authClient.onAuthRefreshSuccess = this.updateState('onAuthRefreshSuccess');
124
+ authClient.onAuthRefreshError = this.onError('onAuthRefreshError');
125
+ authClient.onAuthLogout = this.updateState('onAuthLogout');
126
+ authClient.onTokenExpired = this.refreshToken('onTokenExpired');
127
+ authClient
128
+ .init(__assign(__assign({}, defaultInitOptions), initOptions))
129
+ .catch(this.onError('onInitError'));
130
+ };
131
+ KeycloakProvider.prototype.render = function () {
132
+ var _a = this.props, children = _a.children, authClient = _a.authClient, LoadingComponent = _a.LoadingComponent;
133
+ var _b = this.state, initialized = _b.initialized, isLoading = _b.isLoading;
134
+ if (!!LoadingComponent && (!initialized || isLoading)) {
135
+ return LoadingComponent;
136
+ }
137
+ return (React.createElement(AuthContext.Provider, { value: { initialized: initialized, authClient: authClient } }, children));
138
+ };
139
+ return KeycloakProvider;
140
+ }(React.PureComponent));
141
+ }
142
+ function isUserAuthenticated(authClient) {
143
+ return !!authClient.idToken && !!authClient.token;
144
+ }
145
+ export default createAuthProvider;
146
+ //# sourceMappingURL=provider.js.map
@@ -0,0 +1,10 @@
1
+ {
2
+ "version": 3,
3
+ "file": "provider.js",
4
+ "sourceRoot": "",
5
+ "sources": [
6
+ "@react-keycloak-refork\\core\\provider.tsx"
7
+ ],
8
+ "names": [],
9
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAE9B,OAAO,OAAO,MAAM,oBAAoB,CAAA;AA0ExC;;;;;;;GAOG;AACH,MAAM,UAAU,kBAAkB,CAChC,WAAgD;IAEhD,IAAM,kBAAkB,GAA0B;QAChD,MAAM,EAAE,WAAW;KACpB,CAAA;IAED,IAAM,YAAY,GAAsB;QACtC,WAAW,EAAE,KAAK;QAClB,eAAe,EAAE,KAAK;QACtB,SAAS,EAAE,IAAI;KAChB,CAAA;IAED;QAAsC,oCAGrC;QAHM;YAAA,qEA6HN;YAzHC,WAAK,gBACA,YAAY,EAChB;YAgDD,aAAO,GAAG,UAAC,KAAsB,IAAK,OAAA,UAAC,KAAuB;gBACpD,IAAA,OAAO,GAAK,KAAI,CAAC,KAAK,QAAf,CAAe;gBAC9B,yBAAyB;gBACzB,OAAO,IAAI,OAAO,CAAC,KAAK,EAAE,KAAK,CAAC,CAAA;YAClC,CAAC,EAJqC,CAIrC,CAAA;YAED,iBAAW,GAAG,UAAC,KAAsB,IAAK,OAAA;gBAClC,IAAA,KAAoD,KAAI,CAAC,KAAK,EAA5D,UAAU,gBAAA,EAAE,OAAO,aAAA,EAAE,QAAQ,cAAA,EAAE,cAAc,oBAAe,CAAA;gBAC9D,IAAA,KAIF,KAAI,CAAC,KAAK,EAHC,eAAe,iBAAA,EACX,iBAAiB,qBAAA,EACvB,WAAW,eACV,CAAA;gBAEd,yBAAyB;gBACzB,OAAO,IAAI,OAAO,CAAC,KAAK,CAAC,CAAA;gBAEzB,sBAAsB;gBACtB,IAAM,SAAS,GAAG,cAAc,CAA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G;iBAC/C,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC,CAAA;QACvC,CAAC;QA2DD,iCAAM,GAAN;YACQ,IAAA,KAA6C,IAAI,CAAC,KAAK,EAArD,QAAQ,cAAA,EAAE,UAAU,gBAAA,EAAE,gBAAgB,sBAAe,CAAA;YACvD,IAAA,KAA6B,IAAI,CAAC,KAAK,EAArC,WAAW,iBAAA,EAAE,SAAS,eAAe,CAAA;YAE7C,IAAI,CAAC,CAAC,gBAAgB,IAAI,CAAC,CAAC,WAAW,IAAI,SAAS,CAAC,EAAE;gBACrD,OAAO,gBAAgB,CAAA;aACxB;YAED,OAAO,CACL,oBAAC,WAAW,CAAC,QAAQ,IAAC,KAAK,EAAE,EAAE,WAAW,aAAA,EAAE,UAAU,YAAA,EAAE,IACrD,QAAQ,CACY,CACxB,CAAA;QACH,CAAC;QACH,uBAAC;IAAD,CAAC,AA7HM,CAA+B,KAAK,CAAC,aAAa,GA6HxD;AACH,CAAC;AAED,SAAS,mBAAmB,CAAC,UAAsB;IACjD,OAAO,CAAC,CAAC,UAAU,CAAC,OAAO,IAAI,CAAC,CAAC,UAAU,CAAC,KAAK,CAAA;AACnD,CAAC;AAED,eAAe,kBAAkB,CAAA"
10
+ }
package/lib/types.d.ts ADDED
@@ -0,0 +1,80 @@
1
+ export interface AuthClientError {
2
+ error: string;
3
+ error_description: string;
4
+ }
5
+ export interface AuthClientInitOptions {
6
+ [paramName: string]: any;
7
+ }
8
+ /**
9
+ * A client for the Auth server.
10
+ */
11
+ export interface AuthClient {
12
+ /**
13
+ * The base64 encoded token that can be sent in the Authorization header in
14
+ * requests to services.
15
+ */
16
+ token?: string;
17
+ /**
18
+ * The base64 encoded refresh token that can be used to retrieve a new token.
19
+ */
20
+ refreshToken?: string;
21
+ /**
22
+ * The base64 encoded ID token.
23
+ */
24
+ idToken?: string;
25
+ /**
26
+ * Called when the adapter is initialized.
27
+ */
28
+ onReady?(authenticated?: boolean): void;
29
+ /**
30
+ * Called when a user is successfully authenticated.
31
+ */
32
+ onAuthSuccess?(): void;
33
+ /**
34
+ * Called if there was an error during authentication.
35
+ */
36
+ onAuthError?(errorData: AuthClientError): void;
37
+ /**
38
+ * Called when the token is refreshed.
39
+ */
40
+ onAuthRefreshSuccess?(): void;
41
+ /**
42
+ * Called if there was an error while trying to refresh the token.
43
+ */
44
+ onAuthRefreshError?(): void;
45
+ /**
46
+ * Called if the user is logged out (will only be called if the session
47
+ * status iframe is enabled, or in Cordova mode).
48
+ */
49
+ onAuthLogout?(): void;
50
+ /**
51
+ * Called when the access token is expired. If a refresh token is available
52
+ * the token can be refreshed with Auth#updateToken, or in cases where
53
+ * it's not (ie. with implicit flow) you can redirect to login screen to
54
+ * obtain a new access token.
55
+ */
56
+ onTokenExpired?(): void;
57
+ /**
58
+ * Called to initialize the adapter.
59
+ * @param initOptions Initialization options.
60
+ * @returns A promise to set functions to be invoked on success or error.
61
+ */
62
+ init(initOptions: AuthClientInitOptions): Promise<boolean>;
63
+ /**
64
+ * If the token expires within `minValidity` seconds, the token is refreshed.
65
+ * If the session status iframe is enabled, the session status is also
66
+ * checked.
67
+ *
68
+ * @returns A promise to set functions that can be invoked if the token is
69
+ * still valid, or if the token is no longer valid.
70
+ */
71
+ updateToken(minValidity: number): Promise<boolean>;
72
+ }
73
+ /**
74
+ * Set of tokens provided by AuthClient
75
+ */
76
+ export type AuthClientTokens = Pick<AuthClient, 'idToken' | 'refreshToken' | 'token'>;
77
+ /**
78
+ * ReactAuth event types
79
+ */
80
+ export type AuthClientEvent = 'onReady' | 'onInitError' | 'onAuthSuccess' | 'onAuthError' | 'onAuthRefreshSuccess' | 'onAuthRefreshError' | 'onAuthLogout' | 'onTokenExpired';
package/lib/types.js ADDED
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1,10 @@
1
+ {
2
+ "version": 3,
3
+ "file": "types.js",
4
+ "sourceRoot": "",
5
+ "sources": [
6
+ "@react-keycloak-refork\\core\\types.ts"
7
+ ],
8
+ "names": [],
9
+ "mappings": ""
10
+ }
@@ -0,0 +1,24 @@
1
+ /// <reference types="react" />
2
+ import { AuthClient } from './types';
3
+ /**
4
+ * Auth Context props
5
+ */
6
+ export type IAuthContextProps<T extends AuthClient> = {
7
+ /**
8
+ * The single AuthClient of your application.
9
+ */
10
+ authClient?: T;
11
+ /**
12
+ * Boolean indicating whenever the AuthClient has been initialized by AuthProvider
13
+ */
14
+ initialized: boolean;
15
+ };
16
+ /**
17
+ * Create a React context containing an AuthClient instance.
18
+ *
19
+ * @param {IAuthContextProps} initialContext initial context value.
20
+ *
21
+ * @returns {React.Context} the ReactKeycloak context.
22
+ */
23
+ export declare function createAuthContext<T extends AuthClient>(initialContext?: Partial<IAuthContextProps<T>>): React.Context<IAuthContextProps<T>>;
24
+ export default createAuthContext;
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ Object.defineProperty(exports, "__esModule", { value: true });
14
+ exports.createAuthContext = void 0;
15
+ var react_1 = require("react");
16
+ /**
17
+ * Create a React context containing an AuthClient instance.
18
+ *
19
+ * @param {IAuthContextProps} initialContext initial context value.
20
+ *
21
+ * @returns {React.Context} the ReactKeycloak context.
22
+ */
23
+ function createAuthContext(initialContext) {
24
+ return (0, react_1.createContext)(__assign({ initialized: false }, initialContext));
25
+ }
26
+ exports.createAuthContext = createAuthContext;
27
+ exports.default = createAuthContext;
28
+ //# sourceMappingURL=context.js.map
@@ -0,0 +1,10 @@
1
+ {
2
+ "version": 3,
3
+ "file": "context.js",
4
+ "sourceRoot": "",
5
+ "sources": [
6
+ "@react-keycloak-refork\\core\\context.ts"
7
+ ],
8
+ "names": [],
9
+ "mappings": ";;;;;;;;;;;;;;AAAA,+BAAqC;AAmBrC;;;;;;GAMG;AACH,SAAgB,iBAAiB,CAC/B,cAA8C;IAE9C,OAAO,IAAA,qBAAa,aAClB,WAAW,EAAE,KAAK,IACf,cAAc,EACjB,CAAA;AACJ,CAAC;AAPD,8CAOC;AAED,kBAAe,iBAAiB,CAAA"
10
+ }
@@ -0,0 +1,3 @@
1
+ export * from './context';
2
+ export * from './provider';
3
+ export * from './types';
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ /* istanbul ignore file */
3
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4
+ if (k2 === undefined) k2 = k;
5
+ var desc = Object.getOwnPropertyDescriptor(m, k);
6
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
7
+ desc = { enumerable: true, get: function() { return m[k]; } };
8
+ }
9
+ Object.defineProperty(o, k2, desc);
10
+ }) : (function(o, m, k, k2) {
11
+ if (k2 === undefined) k2 = k;
12
+ o[k2] = m[k];
13
+ }));
14
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
16
+ };
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ __exportStar(require("./context"), exports);
19
+ __exportStar(require("./provider"), exports);
20
+ __exportStar(require("./types"), exports);
21
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,10 @@
1
+ {
2
+ "version": 3,
3
+ "file": "index.js",
4
+ "sourceRoot": "",
5
+ "sources": [
6
+ "@react-keycloak-refork\\core\\index.ts"
7
+ ],
8
+ "names": [],
9
+ "mappings": ";AAAA,0BAA0B;;;;;;;;;;;;;;;;AAE1B,4CAAyB;AACzB,6CAA0B;AAC1B,0CAAuB"
10
+ }
@@ -0,0 +1,132 @@
1
+ import * as React from 'react';
2
+ import { ReactNode } from 'react';
3
+ import { IAuthContextProps } from './context';
4
+ import { AuthClient, AuthClientError, AuthClientEvent, AuthClientInitOptions, AuthClientTokens } from './types';
5
+ /**
6
+ * Props that can be passed to AuthProvider
7
+ */
8
+ export type AuthProviderProps<T extends AuthClient> = {
9
+ /**
10
+ * The single AuthClient instance to be used by your application.
11
+ */
12
+ authClient: T;
13
+ /**
14
+ * The single AuthClient instance to be used by your application.
15
+ */
16
+ children: React.JSXElementConstructor<{
17
+ children: React.ReactElement | ReactNode | Element;
18
+ }> | any;
19
+ /**
20
+ * A flag to enable automatic token refresh. Defaults to true.
21
+ * This is useful if you need to disable it (not recommended).
22
+ *
23
+ * @default true
24
+ */
25
+ autoRefreshToken?: boolean;
26
+ /**
27
+ * The config to be used when initializing AuthClient instance.
28
+ */
29
+ initOptions?: AuthClientInitOptions;
30
+ /**
31
+ * An optional loading check function to customize LoadingComponent display condition.
32
+ * Return `true` to display LoadingComponent, `false` to hide it.
33
+ *
34
+ * @param authClient the current AuthClient instance.
35
+ *
36
+ * @returns {boolean} Set to true to display LoadingComponent, false to hide it.
37
+ */
38
+ isLoadingCheck?: (authClient: T) => boolean;
39
+ /**
40
+ * An optional component to display while AuthClient instance is being initialized.
41
+ */
42
+ LoadingComponent?: JSX.Element;
43
+ /**
44
+ * An optional function to receive AuthClient events as they happen.
45
+ */
46
+ onEvent?: (eventType: AuthClientEvent, error?: AuthClientError) => void;
47
+ /**
48
+ * An optional function to receive AuthClient tokens when changed.
49
+ *
50
+ * @param {AuthClientTokens} tokens The current AuthClient tokens set.
51
+ */
52
+ onTokens?: (tokens: AuthClientTokens) => void;
53
+ };
54
+ type AuthProviderState = {
55
+ initialized: boolean;
56
+ isAuthenticated: boolean;
57
+ isLoading: boolean;
58
+ };
59
+ /**
60
+ * Create an AuthProvider component to wrap a React app with, it will take care of common AuthClient
61
+ * lifecycle handling (such as initialization and token refresh).
62
+ *
63
+ * @param AuthContext the Auth context to be used by the created AuthProvider
64
+ *
65
+ * @returns the AuthProvider component
66
+ */
67
+ export declare function createAuthProvider<T extends AuthClient>(AuthContext: React.Context<IAuthContextProps<T>>): {
68
+ new (props: AuthProviderProps<T>): {
69
+ state: {
70
+ initialized: boolean;
71
+ isAuthenticated: boolean;
72
+ isLoading: boolean;
73
+ };
74
+ componentDidMount(): void;
75
+ componentDidUpdate({ authClient: prevAuthClient, initOptions: prevInitOptions, }: AuthProviderProps<T>): void;
76
+ init(): void;
77
+ onError: (event: AuthClientEvent) => (error?: AuthClientError) => void;
78
+ updateState: (event: AuthClientEvent) => () => void;
79
+ refreshToken: (event: AuthClientEvent) => () => void;
80
+ render(): React.JSX.Element;
81
+ context: unknown;
82
+ setState<K extends keyof AuthProviderState>(state: AuthProviderState | ((prevState: Readonly<AuthProviderState>, props: Readonly<AuthProviderProps<T>>) => AuthProviderState | Pick<AuthProviderState, K> | null) | Pick<AuthProviderState, K> | null, callback?: (() => void) | undefined): void;
83
+ forceUpdate(callback?: (() => void) | undefined): void;
84
+ readonly props: Readonly<AuthProviderProps<T>>;
85
+ refs: {
86
+ [key: string]: React.ReactInstance;
87
+ };
88
+ shouldComponentUpdate?(nextProps: Readonly<AuthProviderProps<T>>, nextState: Readonly<AuthProviderState>, nextContext: any): boolean;
89
+ componentWillUnmount?(): void;
90
+ componentDidCatch?(error: Error, errorInfo: React.ErrorInfo): void;
91
+ getSnapshotBeforeUpdate?(prevProps: Readonly<AuthProviderProps<T>>, prevState: Readonly<AuthProviderState>): any;
92
+ componentWillMount?(): void;
93
+ UNSAFE_componentWillMount?(): void;
94
+ componentWillReceiveProps?(nextProps: Readonly<AuthProviderProps<T>>, nextContext: any): void;
95
+ UNSAFE_componentWillReceiveProps?(nextProps: Readonly<AuthProviderProps<T>>, nextContext: any): void;
96
+ componentWillUpdate?(nextProps: Readonly<AuthProviderProps<T>>, nextState: Readonly<AuthProviderState>, nextContext: any): void;
97
+ UNSAFE_componentWillUpdate?(nextProps: Readonly<AuthProviderProps<T>>, nextState: Readonly<AuthProviderState>, nextContext: any): void;
98
+ };
99
+ new (props: AuthProviderProps<T>, context: any): {
100
+ state: {
101
+ initialized: boolean;
102
+ isAuthenticated: boolean;
103
+ isLoading: boolean;
104
+ };
105
+ componentDidMount(): void;
106
+ componentDidUpdate({ authClient: prevAuthClient, initOptions: prevInitOptions, }: AuthProviderProps<T>): void;
107
+ init(): void;
108
+ onError: (event: AuthClientEvent) => (error?: AuthClientError) => void;
109
+ updateState: (event: AuthClientEvent) => () => void;
110
+ refreshToken: (event: AuthClientEvent) => () => void;
111
+ render(): React.JSX.Element;
112
+ context: unknown;
113
+ setState<K extends keyof AuthProviderState>(state: AuthProviderState | ((prevState: Readonly<AuthProviderState>, props: Readonly<AuthProviderProps<T>>) => AuthProviderState | Pick<AuthProviderState, K> | null) | Pick<AuthProviderState, K> | null, callback?: (() => void) | undefined): void;
114
+ forceUpdate(callback?: (() => void) | undefined): void;
115
+ readonly props: Readonly<AuthProviderProps<T>>;
116
+ refs: {
117
+ [key: string]: React.ReactInstance;
118
+ };
119
+ shouldComponentUpdate?(nextProps: Readonly<AuthProviderProps<T>>, nextState: Readonly<AuthProviderState>, nextContext: any): boolean;
120
+ componentWillUnmount?(): void;
121
+ componentDidCatch?(error: Error, errorInfo: React.ErrorInfo): void;
122
+ getSnapshotBeforeUpdate?(prevProps: Readonly<AuthProviderProps<T>>, prevState: Readonly<AuthProviderState>): any;
123
+ componentWillMount?(): void;
124
+ UNSAFE_componentWillMount?(): void;
125
+ componentWillReceiveProps?(nextProps: Readonly<AuthProviderProps<T>>, nextContext: any): void;
126
+ UNSAFE_componentWillReceiveProps?(nextProps: Readonly<AuthProviderProps<T>>, nextContext: any): void;
127
+ componentWillUpdate?(nextProps: Readonly<AuthProviderProps<T>>, nextState: Readonly<AuthProviderState>, nextContext: any): void;
128
+ UNSAFE_componentWillUpdate?(nextProps: Readonly<AuthProviderProps<T>>, nextState: Readonly<AuthProviderState>, nextContext: any): void;
129
+ };
130
+ contextType?: React.Context<any> | undefined;
131
+ };
132
+ export default createAuthProvider;
@@ -0,0 +1,176 @@
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
17
+ var __assign = (this && this.__assign) || function () {
18
+ __assign = Object.assign || function(t) {
19
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
20
+ s = arguments[i];
21
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
22
+ t[p] = s[p];
23
+ }
24
+ return t;
25
+ };
26
+ return __assign.apply(this, arguments);
27
+ };
28
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
29
+ if (k2 === undefined) k2 = k;
30
+ var desc = Object.getOwnPropertyDescriptor(m, k);
31
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
32
+ desc = { enumerable: true, get: function() { return m[k]; } };
33
+ }
34
+ Object.defineProperty(o, k2, desc);
35
+ }) : (function(o, m, k, k2) {
36
+ if (k2 === undefined) k2 = k;
37
+ o[k2] = m[k];
38
+ }));
39
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
40
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
41
+ }) : function(o, v) {
42
+ o["default"] = v;
43
+ });
44
+ var __importStar = (this && this.__importStar) || function (mod) {
45
+ if (mod && mod.__esModule) return mod;
46
+ var result = {};
47
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
48
+ __setModuleDefault(result, mod);
49
+ return result;
50
+ };
51
+ var __importDefault = (this && this.__importDefault) || function (mod) {
52
+ return (mod && mod.__esModule) ? mod : { "default": mod };
53
+ };
54
+ Object.defineProperty(exports, "__esModule", { value: true });
55
+ exports.createAuthProvider = void 0;
56
+ var React = __importStar(require("react"));
57
+ var react_fast_compare_1 = __importDefault(require("react-fast-compare"));
58
+ /**
59
+ * Create an AuthProvider component to wrap a React app with, it will take care of common AuthClient
60
+ * lifecycle handling (such as initialization and token refresh).
61
+ *
62
+ * @param AuthContext the Auth context to be used by the created AuthProvider
63
+ *
64
+ * @returns the AuthProvider component
65
+ */
66
+ function createAuthProvider(AuthContext) {
67
+ var defaultInitOptions = {
68
+ onLoad: 'check-sso',
69
+ };
70
+ var initialState = {
71
+ initialized: false,
72
+ isAuthenticated: false,
73
+ isLoading: true,
74
+ };
75
+ return /** @class */ (function (_super) {
76
+ __extends(KeycloakProvider, _super);
77
+ function KeycloakProvider() {
78
+ var _this = _super !== null && _super.apply(this, arguments) || this;
79
+ _this.state = __assign({}, initialState);
80
+ _this.onError = function (event) { return function (error) {
81
+ var onEvent = _this.props.onEvent;
82
+ // Notify Events listener
83
+ onEvent && onEvent(event, error);
84
+ }; };
85
+ _this.updateState = function (event) { return function () {
86
+ var _a = _this.props, authClient = _a.authClient, onEvent = _a.onEvent, onTokens = _a.onTokens, isLoadingCheck = _a.isLoadingCheck;
87
+ var _b = _this.state, prevInitialized = _b.initialized, prevAuthenticated = _b.isAuthenticated, prevLoading = _b.isLoading;
88
+ // Notify Events listener
89
+ onEvent && onEvent(event);
90
+ // Check Loading state
91
+ var isLoading = isLoadingCheck ? isLoadingCheck(authClient) : false;
92
+ // Check if user is authenticated
93
+ var isAuthenticated = isUserAuthenticated(authClient);
94
+ // Avoid double-refresh if state hasn't changed
95
+ if (!prevInitialized ||
96
+ isAuthenticated !== prevAuthenticated ||
97
+ isLoading !== prevLoading) {
98
+ _this.setState({
99
+ initialized: true,
100
+ isAuthenticated: isAuthenticated,
101
+ isLoading: isLoading,
102
+ });
103
+ }
104
+ // Notify token listener, if any
105
+ var idToken = authClient.idToken, refreshToken = authClient.refreshToken, token = authClient.token;
106
+ onTokens &&
107
+ onTokens({
108
+ idToken: idToken,
109
+ refreshToken: refreshToken,
110
+ token: token,
111
+ });
112
+ }; };
113
+ _this.refreshToken = function (event) { return function () {
114
+ var _a = _this.props, autoRefreshToken = _a.autoRefreshToken, authClient = _a.authClient, onEvent = _a.onEvent;
115
+ // Notify Events listener
116
+ onEvent && onEvent(event);
117
+ if (autoRefreshToken !== false) {
118
+ // Refresh Keycloak token
119
+ authClient.updateToken(5);
120
+ }
121
+ }; };
122
+ return _this;
123
+ }
124
+ KeycloakProvider.prototype.componentDidMount = function () {
125
+ this.init();
126
+ };
127
+ KeycloakProvider.prototype.componentDidUpdate = function (_a) {
128
+ var prevAuthClient = _a.authClient, prevInitOptions = _a.initOptions;
129
+ var _b = this.props, initOptions = _b.initOptions, authClient = _b.authClient;
130
+ if (authClient !== prevAuthClient ||
131
+ !(0, react_fast_compare_1.default)(initOptions, prevInitOptions)) {
132
+ // De-init previous AuthClient instance
133
+ prevAuthClient.onReady = undefined;
134
+ prevAuthClient.onAuthSuccess = undefined;
135
+ prevAuthClient.onAuthError = undefined;
136
+ prevAuthClient.onAuthRefreshSuccess = undefined;
137
+ prevAuthClient.onAuthRefreshError = undefined;
138
+ prevAuthClient.onAuthLogout = undefined;
139
+ prevAuthClient.onTokenExpired = undefined;
140
+ // Reset state
141
+ this.setState(__assign({}, initialState));
142
+ // Init new AuthClient instance
143
+ this.init();
144
+ }
145
+ };
146
+ KeycloakProvider.prototype.init = function () {
147
+ var _a = this.props, initOptions = _a.initOptions, authClient = _a.authClient;
148
+ // Attach Keycloak listeners
149
+ authClient.onReady = this.updateState('onReady');
150
+ authClient.onAuthSuccess = this.updateState('onAuthSuccess');
151
+ authClient.onAuthError = this.onError('onAuthError');
152
+ authClient.onAuthRefreshSuccess = this.updateState('onAuthRefreshSuccess');
153
+ authClient.onAuthRefreshError = this.onError('onAuthRefreshError');
154
+ authClient.onAuthLogout = this.updateState('onAuthLogout');
155
+ authClient.onTokenExpired = this.refreshToken('onTokenExpired');
156
+ authClient
157
+ .init(__assign(__assign({}, defaultInitOptions), initOptions))
158
+ .catch(this.onError('onInitError'));
159
+ };
160
+ KeycloakProvider.prototype.render = function () {
161
+ var _a = this.props, children = _a.children, authClient = _a.authClient, LoadingComponent = _a.LoadingComponent;
162
+ var _b = this.state, initialized = _b.initialized, isLoading = _b.isLoading;
163
+ if (!!LoadingComponent && (!initialized || isLoading)) {
164
+ return LoadingComponent;
165
+ }
166
+ return (React.createElement(AuthContext.Provider, { value: { initialized: initialized, authClient: authClient } }, children));
167
+ };
168
+ return KeycloakProvider;
169
+ }(React.PureComponent));
170
+ }
171
+ exports.createAuthProvider = createAuthProvider;
172
+ function isUserAuthenticated(authClient) {
173
+ return !!authClient.idToken && !!authClient.token;
174
+ }
175
+ exports.default = createAuthProvider;
176
+ //# sourceMappingURL=provider.js.map
@@ -0,0 +1,10 @@
1
+ {
2
+ "version": 3,
3
+ "file": "provider.js",
4
+ "sourceRoot": "",
5
+ "sources": [
6
+ "@react-keycloak-refork\\core\\provider.tsx"
7
+ ],
8
+ "names": [],
9
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,2CAA8B;AAE9B,0EAAwC;AA0ExC;;;;;;;GAOG;AACH,SAAgB,kBAAkB,CAChC,WAAgD;IAEhD,IAAM,kBAAkB,GAA0B;QAChD,MAAM,EAAE,WAAW;KACpB,CAAA;IAED,IAAM,YAAY,GAAsB;QACtC,WAAW,EAAE,KAAK;QAClB,eAAe,EAAE,KAAK;QACtB,SAAS,EAAE,IAAI;KAChB,CAAA;IAED;QAAsC,oCAGrC;QAHM;YAAA,qEA6HN;YAzHC,WAAK,gBACA,YAAY,EACh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CAAC;AA3ID,gDA2IC;AAED,SAAS,mBAAmB,CAAC,UAAsB;IACjD,OAAO,CAAC,CAAC,UAAU,CAAC,OAAO,IAAI,CAAC,CAAC,UAAU,CAAC,KAAK,CAAA;AACnD,CAAC;AAED,kBAAe,kBAAkB,CAAA"
10
+ }
@@ -0,0 +1,80 @@
1
+ export interface AuthClientError {
2
+ error: string;
3
+ error_description: string;
4
+ }
5
+ export interface AuthClientInitOptions {
6
+ [paramName: string]: any;
7
+ }
8
+ /**
9
+ * A client for the Auth server.
10
+ */
11
+ export interface AuthClient {
12
+ /**
13
+ * The base64 encoded token that can be sent in the Authorization header in
14
+ * requests to services.
15
+ */
16
+ token?: string;
17
+ /**
18
+ * The base64 encoded refresh token that can be used to retrieve a new token.
19
+ */
20
+ refreshToken?: string;
21
+ /**
22
+ * The base64 encoded ID token.
23
+ */
24
+ idToken?: string;
25
+ /**
26
+ * Called when the adapter is initialized.
27
+ */
28
+ onReady?(authenticated?: boolean): void;
29
+ /**
30
+ * Called when a user is successfully authenticated.
31
+ */
32
+ onAuthSuccess?(): void;
33
+ /**
34
+ * Called if there was an error during authentication.
35
+ */
36
+ onAuthError?(errorData: AuthClientError): void;
37
+ /**
38
+ * Called when the token is refreshed.
39
+ */
40
+ onAuthRefreshSuccess?(): void;
41
+ /**
42
+ * Called if there was an error while trying to refresh the token.
43
+ */
44
+ onAuthRefreshError?(): void;
45
+ /**
46
+ * Called if the user is logged out (will only be called if the session
47
+ * status iframe is enabled, or in Cordova mode).
48
+ */
49
+ onAuthLogout?(): void;
50
+ /**
51
+ * Called when the access token is expired. If a refresh token is available
52
+ * the token can be refreshed with Auth#updateToken, or in cases where
53
+ * it's not (ie. with implicit flow) you can redirect to login screen to
54
+ * obtain a new access token.
55
+ */
56
+ onTokenExpired?(): void;
57
+ /**
58
+ * Called to initialize the adapter.
59
+ * @param initOptions Initialization options.
60
+ * @returns A promise to set functions to be invoked on success or error.
61
+ */
62
+ init(initOptions: AuthClientInitOptions): Promise<boolean>;
63
+ /**
64
+ * If the token expires within `minValidity` seconds, the token is refreshed.
65
+ * If the session status iframe is enabled, the session status is also
66
+ * checked.
67
+ *
68
+ * @returns A promise to set functions that can be invoked if the token is
69
+ * still valid, or if the token is no longer valid.
70
+ */
71
+ updateToken(minValidity: number): Promise<boolean>;
72
+ }
73
+ /**
74
+ * Set of tokens provided by AuthClient
75
+ */
76
+ export type AuthClientTokens = Pick<AuthClient, 'idToken' | 'refreshToken' | 'token'>;
77
+ /**
78
+ * ReactAuth event types
79
+ */
80
+ export type AuthClientEvent = 'onReady' | 'onInitError' | 'onAuthSuccess' | 'onAuthError' | 'onAuthRefreshSuccess' | 'onAuthRefreshError' | 'onAuthLogout' | 'onTokenExpired';
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1,10 @@
1
+ {
2
+ "version": 3,
3
+ "file": "types.js",
4
+ "sourceRoot": "",
5
+ "sources": [
6
+ "@react-keycloak-refork\\core\\types.ts"
7
+ ],
8
+ "names": [],
9
+ "mappings": ""
10
+ }
package/package.json ADDED
@@ -0,0 +1,55 @@
1
+ {
2
+ "name": "@react-keycloak-refork/core",
3
+ "version": "5.0.0",
4
+ "license": "MIT",
5
+ "description": "Fork of https://github.com/react-keycloak/react-keycloak.git with updated packages for Keycloak >=26. React bindings for Keycloak javascript adapter (core)",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/leoluzh/react-keycloak-fork.git"
9
+ },
10
+ "author": "leoluzh",
11
+ "bugs": {
12
+ "url": "https://github.com/leoluzh/react-keycloak-fork/issues"
13
+ },
14
+ "homepage": "https://github.com/leoluzh/react-keycloak-fork#readme",
15
+ "keywords": [
16
+ "react",
17
+ "keycloak",
18
+ "fork"
19
+ ],
20
+ "main": "lib-commonjs/index.js",
21
+ "jsnext:main": "lib/index.js",
22
+ "module": "lib/index.js",
23
+ "typings": "lib/index.d.ts",
24
+ "files": [
25
+ "lib",
26
+ "lib-commonjs"
27
+ ],
28
+ "publishConfig": {
29
+ "access": "public"
30
+ },
31
+ "scripts": {
32
+ "clean": "rimraf lib lib-commonjs",
33
+ "prebuild": "npm run clean",
34
+ "compile:commonjs": "tsc --module commonjs --outDir lib-commonjs",
35
+ "compile:esnext": "tsc --module esnext --outDir lib",
36
+ "compile": "run-p compile:*",
37
+ "fixmaps:lib": "tweak_sourcemap_paths -a --include 'lib/**/*.js.map' 'lib-commonjs/**/*.js.map'",
38
+ "fixmaps": "run-p fixmaps:*",
39
+ "build": "run-s compile fixmaps",
40
+ "test": "jest",
41
+ "test:coverage": "jest --coverage",
42
+ "prepublishOnly": "npm run build && cp ../../README.md . && cp ../../LICENSE.md ."
43
+ },
44
+ "peerDependencies": {
45
+ "react": ">=18"
46
+ },
47
+ "dependencies": {
48
+ "react-fast-compare": "^3.2.0"
49
+ },
50
+ "jest": {
51
+ "preset": "ts-jest",
52
+ "testEnvironment": "jsdom"
53
+ },
54
+ "gitHead": "0cd23235e898e822306c4f868c3e8dd10b45e41b"
55
+ }