@react-keycloak-refork/ssr 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.
Files changed (81) hide show
  1. package/LICENSE.md +24 -0
  2. package/README.md +261 -0
  3. package/lib/SSRKeycloakProvider.d.ts +20 -0
  4. package/lib/SSRKeycloakProvider.js +78 -0
  5. package/lib/SSRKeycloakProvider.js.map +10 -0
  6. package/lib/index.d.ts +7 -0
  7. package/lib/index.js +8 -0
  8. package/lib/index.js.map +10 -0
  9. package/lib/internals/KeycloakProvider.d.ts +146 -0
  10. package/lib/internals/KeycloakProvider.js +4 -0
  11. package/lib/internals/KeycloakProvider.js.map +10 -0
  12. package/lib/internals/context.d.ts +4 -0
  13. package/lib/internals/context.js +8 -0
  14. package/lib/internals/context.js.map +10 -0
  15. package/lib/internals/keycloak.d.ts +5 -0
  16. package/lib/internals/keycloak.js +29 -0
  17. package/lib/internals/keycloak.js.map +10 -0
  18. package/lib/internals/utils.d.ts +1 -0
  19. package/lib/internals/utils.js +2 -0
  20. package/lib/internals/utils.js.map +10 -0
  21. package/lib/persistors/client.d.ts +11 -0
  22. package/lib/persistors/client.js +26 -0
  23. package/lib/persistors/client.js.map +10 -0
  24. package/lib/persistors/server.d.ts +3 -0
  25. package/lib/persistors/server.js +34 -0
  26. package/lib/persistors/server.js.map +10 -0
  27. package/lib/persistors/types.d.ts +22 -0
  28. package/lib/persistors/types.js +2 -0
  29. package/lib/persistors/types.js.map +10 -0
  30. package/lib/persistors/utils.d.ts +5 -0
  31. package/lib/persistors/utils.js +20 -0
  32. package/lib/persistors/utils.js.map +10 -0
  33. package/lib/types.d.ts +6 -0
  34. package/lib/types.js +2 -0
  35. package/lib/types.js.map +10 -0
  36. package/lib/useKeycloak.d.ts +6 -0
  37. package/lib/useKeycloak.js +12 -0
  38. package/lib/useKeycloak.js.map +10 -0
  39. package/lib/withKeycloak.d.ts +43 -0
  40. package/lib/withKeycloak.js +25 -0
  41. package/lib/withKeycloak.js.map +10 -0
  42. package/lib-commonjs/SSRKeycloakProvider.d.ts +20 -0
  43. package/lib-commonjs/SSRKeycloakProvider.js +104 -0
  44. package/lib-commonjs/SSRKeycloakProvider.js.map +10 -0
  45. package/lib-commonjs/index.d.ts +7 -0
  46. package/lib-commonjs/index.js +29 -0
  47. package/lib-commonjs/index.js.map +10 -0
  48. package/lib-commonjs/internals/KeycloakProvider.d.ts +146 -0
  49. package/lib-commonjs/internals/KeycloakProvider.js +7 -0
  50. package/lib-commonjs/internals/KeycloakProvider.js.map +10 -0
  51. package/lib-commonjs/internals/context.d.ts +4 -0
  52. package/lib-commonjs/internals/context.js +11 -0
  53. package/lib-commonjs/internals/context.js.map +10 -0
  54. package/lib-commonjs/internals/keycloak.d.ts +5 -0
  55. package/lib-commonjs/internals/keycloak.js +34 -0
  56. package/lib-commonjs/internals/keycloak.js.map +10 -0
  57. package/lib-commonjs/internals/utils.d.ts +1 -0
  58. package/lib-commonjs/internals/utils.js +6 -0
  59. package/lib-commonjs/internals/utils.js.map +10 -0
  60. package/lib-commonjs/persistors/client.d.ts +11 -0
  61. package/lib-commonjs/persistors/client.js +29 -0
  62. package/lib-commonjs/persistors/client.js.map +10 -0
  63. package/lib-commonjs/persistors/server.d.ts +3 -0
  64. package/lib-commonjs/persistors/server.js +39 -0
  65. package/lib-commonjs/persistors/server.js.map +10 -0
  66. package/lib-commonjs/persistors/types.d.ts +22 -0
  67. package/lib-commonjs/persistors/types.js +3 -0
  68. package/lib-commonjs/persistors/types.js.map +10 -0
  69. package/lib-commonjs/persistors/utils.d.ts +5 -0
  70. package/lib-commonjs/persistors/utils.js +31 -0
  71. package/lib-commonjs/persistors/utils.js.map +10 -0
  72. package/lib-commonjs/types.d.ts +6 -0
  73. package/lib-commonjs/types.js +3 -0
  74. package/lib-commonjs/types.js.map +10 -0
  75. package/lib-commonjs/useKeycloak.d.ts +6 -0
  76. package/lib-commonjs/useKeycloak.js +16 -0
  77. package/lib-commonjs/useKeycloak.js.map +10 -0
  78. package/lib-commonjs/withKeycloak.d.ts +43 -0
  79. package/lib-commonjs/withKeycloak.js +52 -0
  80. package/lib-commonjs/withKeycloak.js.map +10 -0
  81. package/package.json +71 -0
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,261 @@
1
+ ![React Keycloak](/art/react-keycloak-logo.png?raw=true 'React Keycloak Logo')
2
+
3
+ # React Keycloak <!-- omit in toc -->
4
+
5
+ > SSR 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
+ [![NPM (scoped)](https://img.shields.io/npm/v/@react-keycloak-fork/ssr?label=npm%20%7C%20ssr)](https://www.npmjs.com/package/@react-keycloak-fork/ssr)
8
+
9
+ [![License](https://img.shields.io/github/license/react-keycloak/react-keycloak.svg)](https://github.com/react-keycloak/react-keycloak/blob/master/LICENSE.md)
10
+ [![lerna](https://img.shields.io/badge/maintained%20with-lerna-cc00ff.svg)](https://lerna.js.org/)
11
+ [![GitHub contributors](https://img.shields.io/github/contributors/react-keycloak/react-keycloak)](https://github.com/react-keycloak/react-keycloak/graphs/contributors)
12
+ [![Github Issues](https://img.shields.io/github/issues/react-keycloak/react-keycloak.svg)](https://github.com/react-keycloak/react-keycloak/issues)
13
+
14
+ [![Gitter](https://img.shields.io/gitter/room/react-keycloak/community)](https://gitter.im/react-keycloak/community)
15
+
16
+ ---
17
+
18
+ ## Table of Contents <!-- omit in toc -->
19
+
20
+ - [Install](#install)
21
+ - [Getting Started](#getting-started)
22
+ - [Setup](#setup)
23
+ - [NextJS](#nextjs)
24
+ - [Razzle](#razzle)
25
+ - [Hook Usage](#hook-usage)
26
+ - [Examples](#examples)
27
+ - [Guides and Articles](#guides-and-articles)
28
+ - [Other Resources](#other-resources)
29
+ - [Securing NextJS API](#securing-nextjs-api)
30
+ - [External Usage (Advanced)](#external-usage-advanced)
31
+ - [Alternatives](#alternatives)
32
+ - [Contributing](#contributing)
33
+ - [License](#license)
34
+
35
+ ---
36
+
37
+ ## Install
38
+
39
+ React Keycloak requires:
40
+
41
+ - React **16.8** or later
42
+ - `keycloak-js` **9.0.2** or later
43
+
44
+ ```shell
45
+ yarn add @react-keycloak-refork/ssr
46
+ ```
47
+
48
+ or
49
+
50
+ ```shell
51
+ npm install --save @react-keycloak-refork/ssr
52
+ ```
53
+
54
+ ## Getting Started
55
+
56
+ This module has been created to support `NextJS` and `Razzle`, other SSR frameworks might be working as well.
57
+
58
+ ### Setup
59
+
60
+ Follow the guide related to your SSR Framework and note that `SSRKeycloakProvider` also accepts all the properties of [`KeycloakProvider`](https://github.com/react-keycloak/react-keycloak/blob/master/packages/web/README.md#setup-keycloakprovider).
61
+
62
+ #### NextJS
63
+
64
+ Requires NextJS **9** or later
65
+
66
+ Create the `_app.tsx` file under `pages` folder and wrap your App inside `SSRKeycloakProvider` component and pass `keycloakConfig` and a `TokenPersistor`.
67
+
68
+ **Note:** `@react-keycloak-refork/ssr` provides a default `TokenPersistor` which works with `cookies` (exported as `ServerPersistors.SSRCookies`).
69
+
70
+ The following examples will be based on that.
71
+
72
+ ```tsx
73
+ import cookie from 'cookie'
74
+ import * as React from 'react'
75
+ import type { IncomingMessage } from 'http'
76
+ import type { AppProps, AppContext } from 'next/app'
77
+
78
+ import { SSRKeycloakProvider, SSRCookies } from '@react-keycloak-refork/ssr'
79
+
80
+ const keycloakCfg = {
81
+ realm: '',
82
+ url: '',
83
+ clientId: '',
84
+ }
85
+
86
+ interface InitialProps {
87
+ cookies: unknown
88
+ }
89
+
90
+ function MyApp({ Component, pageProps, cookies }: AppProps & InitialProps) {
91
+ return (
92
+ <SSRKeycloakProvider
93
+ keycloakConfig={keycloakCfg}
94
+ persistor={SSRCookies(cookies)}
95
+ >
96
+ <Component {...pageProps} />
97
+ </SSRKeycloakProvider>
98
+ )
99
+ }
100
+
101
+ function parseCookies(req: IncomingMessage) {
102
+ return cookie.parse(req.headers.cookie || '')
103
+ }
104
+
105
+ MyApp.getInitialProps = async (context: AppContext) => {
106
+ // Extract cookies from AppContext
107
+ return {
108
+ cookies: context.ctx.req ? parseCookies(context.ctx.req) : {},
109
+ }
110
+ }
111
+
112
+ export default MyApp
113
+ ```
114
+
115
+ #### Razzle
116
+
117
+ Requires `Razzle` **3** or later
118
+
119
+ > **N.B:** This setup requires you to install [`cookie-parser`](https://github.com/expressjs/cookie-parser) middleware.
120
+
121
+ Edit your app `server.js` as follow
122
+
123
+ ```js
124
+ ...
125
+
126
+ import { ExpressCookies, SSRKeycloakProvider } from '@react-keycloak-refork/ssr'
127
+
128
+ // Create a function to retrieve Keycloak configuration parameters -- 'see examples/razzle-app'
129
+ import { getKeycloakConfig } from './utils'
130
+
131
+ const assets = require(process.env.RAZZLE_ASSETS_MANIFEST)
132
+
133
+ const server = express()
134
+ server
135
+ .disable('x-powered-by')
136
+ .use(express.static(process.env.RAZZLE_PUBLIC_DIR))
137
+ .use(cookieParser()) // 1. Add cookieParser Express middleware
138
+ .get('/*', (req, res) => {
139
+ const context = {}
140
+
141
+ // 2. Create an instance of ExpressCookies passing the current request
142
+ const cookiePersistor = ExpressCookies(req)
143
+
144
+ // 3. Wrap the App inside SSRKeycloakProvider
145
+ const markup = renderToString(
146
+ <SSRKeycloakProvider
147
+ keycloakConfig={getKeycloakConfig()}
148
+ persistor={cookiePersistor}
149
+ >
150
+ <StaticRouter context={context} location={req.url}>
151
+ <App />
152
+ </StaticRouter>
153
+ </SSRKeycloakProvider>
154
+ )
155
+ ...
156
+ })
157
+
158
+ ...
159
+ ```
160
+
161
+ Edit your `client.js` as follow
162
+
163
+ ```js
164
+ import { Cookies, SSRKeycloakProvider } from '@react-keycloak-refork/ssr'
165
+
166
+ // Create a function to retrieve Keycloak configuration parameters -- 'see examples/razzle-app'
167
+ import { getKeycloakConfig } from './utils'
168
+
169
+ // 1. Create an instance of Cookies
170
+ const cookiePersistor = new Cookies()
171
+
172
+ // 2. Wrap the App inside SSRKeycloakProvider
173
+ hydrate(
174
+ <SSRKeycloakProvider
175
+ keycloakConfig={getKeycloakConfig()}
176
+ persistor={cookiePersistor}
177
+ >
178
+ <BrowserRouter>
179
+ <App />
180
+ </BrowserRouter>
181
+ </SSRKeycloakProvider>,
182
+ document.getElementById('root')
183
+ )
184
+ ...
185
+ ```
186
+
187
+ ### Hook Usage
188
+
189
+ When a component requires access to `Keycloak`, you can use the `useKeycloak` Hook.
190
+
191
+ ```js
192
+ import { useKeycloak } from '@react-keycloak-refork/ssr'
193
+
194
+ export default () => {
195
+ const { keycloak, initialized } = useKeycloak()
196
+
197
+ // Here you can access the current keycloak instance methods and variables...
198
+
199
+ return (
200
+ <div>
201
+ <div>{`User is ${
202
+ !keycloak.authenticated ? 'NOT ' : ''
203
+ }authenticated`}</div>
204
+
205
+ {!!keycloak.authenticated && (
206
+ <button type="button" onClick={() => keycloak.logout()}>
207
+ Logout
208
+ </button>
209
+ )}
210
+ </div>
211
+ )
212
+ }
213
+ ```
214
+
215
+ ## Examples
216
+
217
+ See inside `examples/nextjs-app` and `examples/razzle-app` folders of [`@react-keycloak-fork/react-keycloak-examples`](https://github.com/react-keycloak/react-keycloak-examples) repository for sample implementations.
218
+
219
+ ## Guides and Articles
220
+
221
+ - Migration guide for `@react-keycloak-refork/ssr` `v2.x to v3.x` can be found here [MIGRATION.md](https://github.com/react-keycloak/react-keycloak/blob/master/packages/ssr/MIGRATION.md).
222
+
223
+ ## Other Resources
224
+
225
+ ### Securing NextJS API
226
+
227
+ Whilst `@react-keycloak-refork/ssr` can help you secure the Frontend part of a `NextJS` app if you also want to secure `NextJS`-exposed APIs you can follow the sample in [this issue](https://github.com/react-keycloak/react-keycloak/issues/44#issuecomment-579877959).
228
+
229
+ Thanks to [@webdeb](https://github.com/webdeb) for reporting the issue and helping develop a solution.
230
+
231
+ ### External Usage (Advanced)
232
+
233
+ If you need to access `keycloak` instance from non-`React` files (such as `sagas`, `utils`, `providers` ...), you can retrieve the instance using the exported `getKeycloakInstance()` method.
234
+
235
+ The instance will be initialized by `react-keycloak` but you'll need to be carefull when using the instance, expecially server-side, and avoid setting/overriding any props, you can however freely access the exposed methods (such as `refreshToken`, `login`, etc...).
236
+
237
+ **Note:** This approach is NOT recommended on the server-side because can lead to `token leakage` issues (see [this issue](https://github.com/react-keycloak/react-keycloak/issues/65) for more details).
238
+
239
+ Thanks to [@webdeb](https://github.com/webdeb) for requesting this feature and helping develop and test the solution.
240
+
241
+ ## Alternatives
242
+
243
+ If you need to connect using a more generic OIDC client instead of `keycloak.js`, consider using one of the following libraries:
244
+
245
+ - [bjerkio/oidc-react](https://github.com/bjerkio/oidc-react)
246
+ - [thchia/react-oidc](https://github.com/thchia/react-oidc)
247
+ - [@axa-fr/react-oidc](https://github.com/AxaGuilDEv/react-oidc)
248
+
249
+ ## Contributing
250
+
251
+ See the [contributing guide](https://github.com/react-keycloak/react-keycloak/blob/master/CONTRIBUTING.md) to learn how to contribute to the repository and the development workflow.
252
+
253
+ ## License
254
+
255
+ MIT
256
+
257
+ ---
258
+
259
+ If you found this project to be helpful, please consider buying me a coffee.
260
+
261
+ [![buy me a coffee](https://www.buymeacoffee.com/assets/img/custom_images/orange_img.png)](https://buymeacoff.ee/4f18nT0Nk)
@@ -0,0 +1,20 @@
1
+ import type { AuthClient, AuthClientInitOptions, AuthProviderProps, AuthClientEvent, AuthClientError, AuthClientTokens } from '@react-keycloak-refork/core';
2
+ import type { KeycloakConfig } from 'keycloak-js';
3
+ import * as React from 'react';
4
+ import type { TokenPersistor } from './persistors/types';
5
+ import type { SSRAuthClient } from './types';
6
+ export interface SSRKeycloakProviderProps<T extends SSRAuthClient> extends Omit<AuthProviderProps<T>, 'authClient'> {
7
+ persistor: TokenPersistor;
8
+ keycloakConfig: KeycloakConfig;
9
+ }
10
+ interface SSRKeycloakProviderState {
11
+ initOptions: AuthClientInitOptions;
12
+ keycloak: AuthClient;
13
+ }
14
+ export declare class SSRKeycloakProvider extends React.PureComponent<SSRKeycloakProviderProps<SSRAuthClient>, SSRKeycloakProviderState> {
15
+ constructor(props: SSRKeycloakProviderProps<SSRAuthClient>);
16
+ onEvent: (event: AuthClientEvent, error?: AuthClientError) => void;
17
+ onTokens: (tokens: AuthClientTokens) => void;
18
+ render(): React.JSX.Element;
19
+ }
20
+ export {};
@@ -0,0 +1,78 @@
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
+ var __rest = (this && this.__rest) || function (s, e) {
28
+ var t = {};
29
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
30
+ t[p] = s[p];
31
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
32
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
33
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
34
+ t[p[i]] = s[p[i]];
35
+ }
36
+ return t;
37
+ };
38
+ import * as React from 'react';
39
+ import { getKeycloakInstance } from './internals/keycloak';
40
+ import { KeycloakProvider } from './internals/KeycloakProvider';
41
+ var SSRKeycloakProvider = /** @class */ (function (_super) {
42
+ __extends(SSRKeycloakProvider, _super);
43
+ function SSRKeycloakProvider(props) {
44
+ var _this = _super.call(this, props) || this;
45
+ _this.onEvent = function (event, error) {
46
+ var _a, _b, _c, _d;
47
+ if (event === 'onReady') {
48
+ if (!_this.state.keycloak.authenticated) {
49
+ (_b = (_a = _this.props) === null || _a === void 0 ? void 0 : _a.persistor) === null || _b === void 0 ? void 0 : _b.resetTokens();
50
+ }
51
+ }
52
+ // Propagate events up
53
+ (_d = (_c = _this.props) === null || _c === void 0 ? void 0 : _c.onEvent) === null || _d === void 0 ? void 0 : _d.call(_c, event, error);
54
+ };
55
+ _this.onTokens = function (tokens) {
56
+ var _a, _b, _c, _d;
57
+ // Persist updated tokens
58
+ (_b = (_a = _this.props) === null || _a === void 0 ? void 0 : _a.persistor) === null || _b === void 0 ? void 0 : _b.setTokens(tokens);
59
+ // Propagate events up
60
+ (_d = (_c = _this.props) === null || _c === void 0 ? void 0 : _c.onTokens) === null || _d === void 0 ? void 0 : _d.call(_c, tokens);
61
+ };
62
+ var initOptions = props.initOptions, keycloakConfig = props.keycloakConfig, persistor = props.persistor;
63
+ var cachedTokens = persistor.getTokens();
64
+ _this.state = {
65
+ keycloak: getKeycloakInstance(keycloakConfig, persistor),
66
+ initOptions: __assign(__assign({}, cachedTokens), initOptions),
67
+ };
68
+ return _this;
69
+ }
70
+ SSRKeycloakProvider.prototype.render = function () {
71
+ var _a = this.props, children = _a.children, persistor = _a.persistor, providerProps = __rest(_a, ["children", "persistor"]);
72
+ var _b = this.state, initOptions = _b.initOptions, keycloak = _b.keycloak;
73
+ return (React.createElement(KeycloakProvider, __assign({}, providerProps, { authClient: keycloak, initOptions: initOptions, onEvent: this.onEvent, onTokens: this.onTokens }), children));
74
+ };
75
+ return SSRKeycloakProvider;
76
+ }(React.PureComponent));
77
+ export { SSRKeycloakProvider };
78
+ //# sourceMappingURL=SSRKeycloakProvider.js.map
@@ -0,0 +1,10 @@
1
+ {
2
+ "version": 3,
3
+ "file": "SSRKeycloakProvider.js",
4
+ "sourceRoot": "",
5
+ "sources": [
6
+ "@react-keycloak-refork\\ssr\\SSRKeycloakProvider.tsx"
7
+ ],
8
+ "names": [],
9
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AASA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAI9B,OAAO,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAA;AAC1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAA;AAiB/D;IAAyC,uCAGxC;IACC,6BAAY,KAA8C;QAA1D,YACE,kBAAM,KAAK,CAAC,SAYb;QAED,aAAO,GAAG,UAAC,KAAsB,EAAE,KAAuB;;YACxD,IAAI,KAAK,KAAK,SAAS,EAAE;gBACvB,IAAI,CAAE,KAAI,CAAC,KAAK,CAAC,QAA6B,CAAC,aAAa,EAAE;oBAC5D,MAAA,MAAA,KAAI,CAAC,KAAK,0CAAE,SAAS,0CAAE,WAAW,EAAE,CAAA;iBACrC;aACF;YAED,sBAAsB;YACtB,MAAA,MAAA,KAAI,CAAC,KAAK,0CAAE,OAAO,mDAAG,KAAK,EAAE,KAAK,CAAC,CAAA;QACrC,CAAC,CAAA;QAED,cAAQ,GAAG,UAAC,MAAwB;;YAClC,yBAAyB;YACzB,MAAA,MAAA,KAAI,CAAC,KAAK,0CAAE,SAAS,0CAAE,SAAS,CAAC,MAAM,CAAC,CAAA;YAExC,sBAAsB;YACtB,MAAA,MAAA,KAAI,CAAC,KAAK,0CAAE,QAAQ,mDAAG,MAAM,CAAC,CAAA;QAChC,CAAC,CAAA;QA7BS,IAAA,WAAW,GAAgC,KAAK,YAArC,EAAE,cAAc,GAAgB,KAAK,eAArB,EAAE,SAAS,GAAK,KAAK,UAAV,CAAU;QACxD,IAAM,YAAY,GAAG,SAAS,CAAC,SAAS,EAAE,CAAA;QAE1C,KAAI,CAAC,KAAK,GAAG;YACX,QAAQ,EAAE,mBAAmB,CAAC,cAAc,EAAE,SAAS,CAAC;YACxD,WAAW,wBACN,YAAY,GACZ,WAAW,CACf;SACF,CAAA;;IACH,CAAC;IAqBD,oCAAM,GAAN;QACE,IAAM,KAA4C,IAAI,CAAC,KAAK,EAApD,QAAQ,cAAA,EAAE,SAAS,eAAA,EAAK,aAAa,cAAvC,yBAAyC,CAAa,CAAA;QACtD,IAAA,KAA4B,IAAI,CAAC,KAAK,EAApC,WAAW,iBAAA,EAAE,QAAQ,cAAe,CAAA;QAE5C,OAAO,CACL,oBAAC,gBAAgB,eACX,aAAa,IACjB,UAAU,EAAE,QAAQ,EACpB,WAAW,EAAE,WAAW,EACxB,OAAO,EAAE,IAAI,CAAC,OAAO,EACrB,QAAQ,EAAE,IAAI,CAAC,QAAQ,KAEtB,QAAQ,CACQ,CACpB,CAAA;IACH,CAAC;IACH,0BAAC;AAAD,CAAC,AAtDD,CAAyC,KAAK,CAAC,aAAa,GAsD3D"
10
+ }
package/lib/index.d.ts ADDED
@@ -0,0 +1,7 @@
1
+ export { SSRKeycloakProvider } from './SSRKeycloakProvider';
2
+ export { useKeycloak } from './useKeycloak';
3
+ export { withKeycloak } from './withKeycloak';
4
+ export { getKeycloakInstance } from './internals/keycloak';
5
+ export * from './persistors/client';
6
+ export * from './persistors/server';
7
+ export * from './types';
package/lib/index.js ADDED
@@ -0,0 +1,8 @@
1
+ export { SSRKeycloakProvider } from './SSRKeycloakProvider';
2
+ export { useKeycloak } from './useKeycloak';
3
+ export { withKeycloak } from './withKeycloak';
4
+ export { getKeycloakInstance } from './internals/keycloak';
5
+ export * from './persistors/client';
6
+ export * from './persistors/server';
7
+ export * from './types';
8
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,10 @@
1
+ {
2
+ "version": 3,
3
+ "file": "index.js",
4
+ "sourceRoot": "",
5
+ "sources": [
6
+ "@react-keycloak-refork\\ssr\\index.ts"
7
+ ],
8
+ "names": [],
9
+ "mappings": "AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAA;AAC3D,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAC3C,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAE7C,OAAO,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAA;AAE1D,cAAc,qBAAqB,CAAA;AACnC,cAAc,qBAAqB,CAAA;AAEnC,cAAc,SAAS,CAAA"
10
+ }
@@ -0,0 +1,146 @@
1
+ /// <reference types="react" />
2
+ export declare const KeycloakProvider: {
3
+ new (props: import("@react-keycloak-refork/core").AuthProviderProps<import("@react-keycloak-refork/core").AuthClient>): {
4
+ state: {
5
+ initialized: boolean;
6
+ isAuthenticated: boolean;
7
+ isLoading: boolean;
8
+ };
9
+ componentDidMount(): void;
10
+ componentDidUpdate({ authClient: prevAuthClient, initOptions: prevInitOptions, }: import("@react-keycloak-refork/core").AuthProviderProps<import("@react-keycloak-refork/core").AuthClient>): void;
11
+ init(): void;
12
+ onError: (event: import("@react-keycloak-refork/core").AuthClientEvent) => (error?: import("@react-keycloak-refork/core").AuthClientError | undefined) => void;
13
+ updateState: (event: import("@react-keycloak-refork/core").AuthClientEvent) => () => void;
14
+ refreshToken: (event: import("@react-keycloak-refork/core").AuthClientEvent) => () => void;
15
+ render(): import("react").JSX.Element;
16
+ context: unknown;
17
+ setState<K extends keyof {
18
+ initialized: boolean;
19
+ isAuthenticated: boolean;
20
+ isLoading: boolean;
21
+ }>(state: {
22
+ initialized: boolean;
23
+ isAuthenticated: boolean;
24
+ isLoading: boolean;
25
+ } | ((prevState: Readonly<{
26
+ initialized: boolean;
27
+ isAuthenticated: boolean;
28
+ isLoading: boolean;
29
+ }>, props: Readonly<import("@react-keycloak-refork/core").AuthProviderProps<import("@react-keycloak-refork/core").AuthClient>>) => {
30
+ initialized: boolean;
31
+ isAuthenticated: boolean;
32
+ isLoading: boolean;
33
+ } | Pick<{
34
+ initialized: boolean;
35
+ isAuthenticated: boolean;
36
+ isLoading: boolean;
37
+ }, K> | null) | Pick<{
38
+ initialized: boolean;
39
+ isAuthenticated: boolean;
40
+ isLoading: boolean;
41
+ }, K> | null, callback?: (() => void) | undefined): void;
42
+ forceUpdate(callback?: (() => void) | undefined): void;
43
+ readonly props: Readonly<import("@react-keycloak-refork/core").AuthProviderProps<import("@react-keycloak-refork/core").AuthClient>>;
44
+ refs: {
45
+ [key: string]: import("react").ReactInstance;
46
+ };
47
+ shouldComponentUpdate?(nextProps: Readonly<import("@react-keycloak-refork/core").AuthProviderProps<import("@react-keycloak-refork/core").AuthClient>>, nextState: Readonly<{
48
+ initialized: boolean;
49
+ isAuthenticated: boolean;
50
+ isLoading: boolean;
51
+ }>, nextContext: any): boolean;
52
+ componentWillUnmount?(): void;
53
+ componentDidCatch?(error: Error, errorInfo: import("react").ErrorInfo): void;
54
+ getSnapshotBeforeUpdate?(prevProps: Readonly<import("@react-keycloak-refork/core").AuthProviderProps<import("@react-keycloak-refork/core").AuthClient>>, prevState: Readonly<{
55
+ initialized: boolean;
56
+ isAuthenticated: boolean;
57
+ isLoading: boolean;
58
+ }>): any;
59
+ componentWillMount?(): void;
60
+ UNSAFE_componentWillMount?(): void;
61
+ componentWillReceiveProps?(nextProps: Readonly<import("@react-keycloak-refork/core").AuthProviderProps<import("@react-keycloak-refork/core").AuthClient>>, nextContext: any): void;
62
+ UNSAFE_componentWillReceiveProps?(nextProps: Readonly<import("@react-keycloak-refork/core").AuthProviderProps<import("@react-keycloak-refork/core").AuthClient>>, nextContext: any): void;
63
+ componentWillUpdate?(nextProps: Readonly<import("@react-keycloak-refork/core").AuthProviderProps<import("@react-keycloak-refork/core").AuthClient>>, nextState: Readonly<{
64
+ initialized: boolean;
65
+ isAuthenticated: boolean;
66
+ isLoading: boolean;
67
+ }>, nextContext: any): void;
68
+ UNSAFE_componentWillUpdate?(nextProps: Readonly<import("@react-keycloak-refork/core").AuthProviderProps<import("@react-keycloak-refork/core").AuthClient>>, nextState: Readonly<{
69
+ initialized: boolean;
70
+ isAuthenticated: boolean;
71
+ isLoading: boolean;
72
+ }>, nextContext: any): void;
73
+ };
74
+ new (props: import("@react-keycloak-refork/core").AuthProviderProps<import("@react-keycloak-refork/core").AuthClient>, context: any): {
75
+ state: {
76
+ initialized: boolean;
77
+ isAuthenticated: boolean;
78
+ isLoading: boolean;
79
+ };
80
+ componentDidMount(): void;
81
+ componentDidUpdate({ authClient: prevAuthClient, initOptions: prevInitOptions, }: import("@react-keycloak-refork/core").AuthProviderProps<import("@react-keycloak-refork/core").AuthClient>): void;
82
+ init(): void;
83
+ onError: (event: import("@react-keycloak-refork/core").AuthClientEvent) => (error?: import("@react-keycloak-refork/core").AuthClientError | undefined) => void;
84
+ updateState: (event: import("@react-keycloak-refork/core").AuthClientEvent) => () => void;
85
+ refreshToken: (event: import("@react-keycloak-refork/core").AuthClientEvent) => () => void;
86
+ render(): import("react").JSX.Element;
87
+ context: unknown;
88
+ setState<K_1 extends keyof {
89
+ initialized: boolean;
90
+ isAuthenticated: boolean;
91
+ isLoading: boolean;
92
+ }>(state: {
93
+ initialized: boolean;
94
+ isAuthenticated: boolean;
95
+ isLoading: boolean;
96
+ } | ((prevState: Readonly<{
97
+ initialized: boolean;
98
+ isAuthenticated: boolean;
99
+ isLoading: boolean;
100
+ }>, props: Readonly<import("@react-keycloak-refork/core").AuthProviderProps<import("@react-keycloak-refork/core").AuthClient>>) => {
101
+ initialized: boolean;
102
+ isAuthenticated: boolean;
103
+ isLoading: boolean;
104
+ } | Pick<{
105
+ initialized: boolean;
106
+ isAuthenticated: boolean;
107
+ isLoading: boolean;
108
+ }, K_1> | null) | Pick<{
109
+ initialized: boolean;
110
+ isAuthenticated: boolean;
111
+ isLoading: boolean;
112
+ }, K_1> | null, callback?: (() => void) | undefined): void;
113
+ forceUpdate(callback?: (() => void) | undefined): void;
114
+ readonly props: Readonly<import("@react-keycloak-refork/core").AuthProviderProps<import("@react-keycloak-refork/core").AuthClient>>;
115
+ refs: {
116
+ [key: string]: import("react").ReactInstance;
117
+ };
118
+ shouldComponentUpdate?(nextProps: Readonly<import("@react-keycloak-refork/core").AuthProviderProps<import("@react-keycloak-refork/core").AuthClient>>, nextState: Readonly<{
119
+ initialized: boolean;
120
+ isAuthenticated: boolean;
121
+ isLoading: boolean;
122
+ }>, nextContext: any): boolean;
123
+ componentWillUnmount?(): void;
124
+ componentDidCatch?(error: Error, errorInfo: import("react").ErrorInfo): void;
125
+ getSnapshotBeforeUpdate?(prevProps: Readonly<import("@react-keycloak-refork/core").AuthProviderProps<import("@react-keycloak-refork/core").AuthClient>>, prevState: Readonly<{
126
+ initialized: boolean;
127
+ isAuthenticated: boolean;
128
+ isLoading: boolean;
129
+ }>): any;
130
+ componentWillMount?(): void;
131
+ UNSAFE_componentWillMount?(): void;
132
+ componentWillReceiveProps?(nextProps: Readonly<import("@react-keycloak-refork/core").AuthProviderProps<import("@react-keycloak-refork/core").AuthClient>>, nextContext: any): void;
133
+ UNSAFE_componentWillReceiveProps?(nextProps: Readonly<import("@react-keycloak-refork/core").AuthProviderProps<import("@react-keycloak-refork/core").AuthClient>>, nextContext: any): void;
134
+ componentWillUpdate?(nextProps: Readonly<import("@react-keycloak-refork/core").AuthProviderProps<import("@react-keycloak-refork/core").AuthClient>>, nextState: Readonly<{
135
+ initialized: boolean;
136
+ isAuthenticated: boolean;
137
+ isLoading: boolean;
138
+ }>, nextContext: any): void;
139
+ UNSAFE_componentWillUpdate?(nextProps: Readonly<import("@react-keycloak-refork/core").AuthProviderProps<import("@react-keycloak-refork/core").AuthClient>>, nextState: Readonly<{
140
+ initialized: boolean;
141
+ isAuthenticated: boolean;
142
+ isLoading: boolean;
143
+ }>, nextContext: any): void;
144
+ };
145
+ contextType?: import("react").Context<any> | undefined;
146
+ };
@@ -0,0 +1,4 @@
1
+ import { createAuthProvider } from '@react-keycloak-refork/core';
2
+ import { reactKeycloakSsrContext } from './context';
3
+ export var KeycloakProvider = createAuthProvider(reactKeycloakSsrContext);
4
+ //# sourceMappingURL=KeycloakProvider.js.map
@@ -0,0 +1,10 @@
1
+ {
2
+ "version": 3,
3
+ "file": "KeycloakProvider.js",
4
+ "sourceRoot": "",
5
+ "sources": [
6
+ "@react-keycloak-refork\\ssr\\internals\\KeycloakProvider.ts"
7
+ ],
8
+ "names": [],
9
+ "mappings": "AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAA;AAEhE,OAAO,EAAE,uBAAuB,EAAE,MAAM,WAAW,CAAA;AAEnD,MAAM,CAAC,IAAM,gBAAgB,GAAG,kBAAkB,CAAC,uBAAuB,CAAC,CAAA"
10
+ }
@@ -0,0 +1,4 @@
1
+ /// <reference types="react" />
2
+ import type { AuthClient } from '@react-keycloak-refork/core';
3
+ export declare const reactKeycloakSsrContext: import("react").Context<import("@react-keycloak-refork/core").IAuthContextProps<AuthClient>>;
4
+ export declare const ReactKeycloakSSRContextConsumer: import("react").Consumer<import("@react-keycloak-refork/core").IAuthContextProps<AuthClient>>;
@@ -0,0 +1,8 @@
1
+ import { createAuthContext } from '@react-keycloak-refork/core';
2
+ import { isServer } from './utils';
3
+ // Context to hold Keycloak and his state
4
+ export var reactKeycloakSsrContext = createAuthContext({
5
+ initialized: isServer(),
6
+ });
7
+ export var ReactKeycloakSSRContextConsumer = reactKeycloakSsrContext.Consumer;
8
+ //# sourceMappingURL=context.js.map
@@ -0,0 +1,10 @@
1
+ {
2
+ "version": 3,
3
+ "file": "context.js",
4
+ "sourceRoot": "",
5
+ "sources": [
6
+ "@react-keycloak-refork\\ssr\\internals\\context.ts"
7
+ ],
8
+ "names": [],
9
+ "mappings": "AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAA;AAG/D,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAElC,yCAAyC;AACzC,MAAM,CAAC,IAAM,uBAAuB,GAAG,iBAAiB,CAAa;IACnE,WAAW,EAAE,QAAQ,EAAE;CACxB,CAAC,CAAA;AAEF,MAAM,CAAC,IAAM,+BAA+B,GAAG,uBAAuB,CAAC,QAAQ,CAAA"
10
+ }
@@ -0,0 +1,5 @@
1
+ import type { AuthClient } from '@react-keycloak-refork/core';
2
+ import type { KeycloakConfig } from 'keycloak-js';
3
+ import type { TokenPersistor } from '../persistors/types';
4
+ export declare const getKeycloakStub: (persistor: TokenPersistor) => AuthClient;
5
+ export declare const getKeycloakInstance: (keycloakConfig: KeycloakConfig, persistor?: TokenPersistor, recreate?: boolean) => AuthClient;
@@ -0,0 +1,29 @@
1
+ import { isServer } from './utils';
2
+ // Keycloak singleton
3
+ var keycloakInstance;
4
+ // KeycloakStub singleton
5
+ var keycloakStubInstance;
6
+ // this is a fake Keycloak instance we use to initialize Keycloak on the server.
7
+ // This gets over-written as soon as Keycloak is initialized on the client.
8
+ export var getKeycloakStub = function (persistor) {
9
+ var kcTokens = persistor.getTokens();
10
+ keycloakStubInstance = {
11
+ init: function () { return Promise.resolve(true); },
12
+ updateToken: function () { return Promise.resolve(false); },
13
+ idToken: kcTokens.idToken,
14
+ token: kcTokens.token,
15
+ refreshToken: kcTokens.refreshToken,
16
+ authenticated: !!kcTokens.idToken && !!kcTokens.token,
17
+ };
18
+ return keycloakStubInstance;
19
+ };
20
+ var Keycloak = !isServer() ? require('keycloak-js').default : null;
21
+ export var getKeycloakInstance = function (keycloakConfig, persistor, recreate) {
22
+ if (recreate === void 0) { recreate = false; }
23
+ var isServerCheck = isServer();
24
+ if (recreate || (!keycloakInstance && !isServerCheck)) {
25
+ keycloakInstance = Keycloak(keycloakConfig);
26
+ }
27
+ return !isServerCheck ? keycloakInstance : getKeycloakStub(persistor);
28
+ };
29
+ //# sourceMappingURL=keycloak.js.map