{"_id":"@baolq/react-keycloak-ssr","_rev":"2-a10868c8cfe1ef34dad0e9a94685f8e6","name":"@baolq/react-keycloak-ssr","dist-tags":{"latest":"3.4.2"},"versions":{"3.3.0":{"name":"@baolq/react-keycloak-ssr","version":"3.3.0","license":"MIT","description":"SSR bindings for Keycloak javascript adapter","repository":{"type":"git","url":"git+https://github.com/react-keycloak/react-keycloak.git"},"author":{"name":"Mattia Panzeri","email":"mattia.panzeri93@gmail.com"},"bugs":{"url":"https://github.com/react-keycloak/react-keycloak/issues"},"homepage":"https://github.com/react-keycloak/react-keycloak#readme","keywords":["react","keycloak","keycloak-js","nextjs","razzle"],"main":"lib-commonjs/index.js","jsnext:main":"lib/index.js","module":"lib/index.js","typings":"lib/index.d.ts","publishConfig":{"access":"public"},"funding":{"type":"patreon","url":"https://www.patreon.com/reactkeycloak"},"scripts":{"clean":"rimraf lib lib-commonjs","prebuild":"npm run clean","compile:commonjs":"tsc --module commonjs --outDir lib-commonjs","compile:esnext":"tsc --module esnext --outDir lib","compile":"run-p compile:*","fixmaps:lib":"tweak_sourcemap_paths -a --include 'lib/**/*.js.map' 'lib-commonjs/**/*.js.map'","fixmaps":"run-p fixmaps:*","build":"run-s compile fixmaps","test":"jest","test:coverage":"jest --coverage","coveralls":"cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js","prepublishOnly":"npm run build"},"peerDependencies":{"keycloak-js":">=9.0.2","react":">=16.8","typescript":">=3.8"},"peerDependenciesMeta":{"typescript":{"optional":true}},"dependencies":{"@babel/runtime":"^7.9.0","@baolq/react-keycloak-core":"file:../core","detect-node":"^2.0.4","hoist-non-react-statics":"^3.3.2","js-base64":"^3.4.5","js-cookie":"^2.2.1"},"jest":{"preset":"ts-jest","testEnvironment":"jsdom"},"gitHead":"2709af2d999bd94522f6afd011df41935a40eee3","_id":"@baolq/react-keycloak-ssr@3.3.0","_nodeVersion":"18.17.1","_npmVersion":"9.6.7","dist":{"integrity":"sha512-CPc8zxvJN/iPFBiLna8CSTDqSkFsay3wiexs1Q6ccOGJqVHm0MjUD4X/p73+EiAsfv+Ch7UtvLzqYvCc/bxwVg==","shasum":"0a7a99fd3f38c144340b618500fa62f2a1efb718","tarball":"https://registry.npmjs.org/@baolq/react-keycloak-ssr/-/react-keycloak-ssr-3.3.0.tgz","fileCount":80,"unpackedSize":82390,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIA9ICHdp4rj4IOWBWhQ2Y1s4WHUaFLshS4z9ev/hdtR3AiEA7qfRYQ3afKpsq8qd4kVQnPPSWTdMNGnsNMKEkdYu8Y4="}]},"_npmUser":{"name":"baolq","email":"bao.lq.it@gmail.com"},"directories":{},"maintainers":[{"name":"baolq","email":"bao.lq.it@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/react-keycloak-ssr_3.3.0_1708063863801_0.8987559306751176"},"_hasShrinkwrap":false},"3.4.1":{"name":"@baolq/react-keycloak-ssr","version":"3.4.1","license":"MIT","description":"SSR bindings for Keycloak javascript adapter","repository":{"type":"git","url":"git+https://github.com/react-keycloak/react-keycloak.git"},"author":{"name":"Mattia Panzeri","email":"mattia.panzeri93@gmail.com"},"bugs":{"url":"https://github.com/react-keycloak/react-keycloak/issues"},"homepage":"https://github.com/react-keycloak/react-keycloak#readme","keywords":["react","keycloak","keycloak-js","nextjs","razzle"],"main":"lib-commonjs/index.js","jsnext:main":"lib/index.js","module":"lib/index.js","typings":"lib/index.d.ts","publishConfig":{"access":"public"},"funding":{"type":"patreon","url":"https://www.patreon.com/reactkeycloak"},"scripts":{"clean":"rimraf lib lib-commonjs","prebuild":"npm run clean","compile:commonjs":"tsc --module commonjs --outDir lib-commonjs","compile:esnext":"tsc --module esnext --outDir lib","compile":"run-p compile:*","fixmaps:lib":"tweak_sourcemap_paths -a --include 'lib/**/*.js.map' 'lib-commonjs/**/*.js.map'","fixmaps":"run-p fixmaps:*","build":"run-s compile fixmaps","test":"jest","test:coverage":"jest --coverage","coveralls":"cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js","prepublishOnly":"npm run build"},"peerDependencies":{"keycloak-js":">=9.0.2","react":">=16.8","typescript":">=3.8"},"peerDependenciesMeta":{"typescript":{"optional":true}},"dependencies":{"@babel/runtime":"^7.9.0","@baolq/react-keycloak-core":"^4.0.1","detect-node":"^2.0.4","hoist-non-react-statics":"^3.3.2","js-base64":"^3.4.5","js-cookie":"^2.2.1"},"jest":{"preset":"ts-jest","testEnvironment":"jsdom"},"gitHead":"4a14d39f92c7bbb8d92577220a29ec45af626cd8","_id":"@baolq/react-keycloak-ssr@3.4.1","_nodeVersion":"18.17.1","_npmVersion":"lerna/3.22.1/node@v18.17.1+x64 (win32)","dist":{"integrity":"sha512-rfLr/I2Y42BzuBWn6p3pHGOc78IraRpEL+sHT3oHFEDA8Q4aDQ1L9A7Lh9pDNRbJ+kUyYQvVLiGeH9FtnhS6aA==","shasum":"6aed490ce67691c93dd0060154ce9e3ef88d90b4","tarball":"https://registry.npmjs.org/@baolq/react-keycloak-ssr/-/react-keycloak-ssr-3.4.1.tgz","fileCount":82,"unpackedSize":87567,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIAm5sS9zgDiRZwTEngrHRVPn8vxliObGh9MjUMbJuTLLAiBTERFmKWPlY6gDIR7ej/Yh83WW9PU9elR4XR/gvmHWGA=="}]},"_npmUser":{"name":"baolq","email":"bao.lq.it@gmail.com"},"directories":{},"maintainers":[{"name":"baolq","email":"bao.lq.it@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/react-keycloak-ssr_3.4.1_1708064738531_0.9677336182881551"},"_hasShrinkwrap":false},"3.4.2":{"name":"@baolq/react-keycloak-ssr","version":"3.4.2","license":"MIT","description":"SSR bindings for Keycloak javascript adapter","repository":{"type":"git","url":"git+https://github.com/react-keycloak/react-keycloak.git"},"author":{"name":"Mattia Panzeri","email":"mattia.panzeri93@gmail.com"},"bugs":{"url":"https://github.com/react-keycloak/react-keycloak/issues"},"homepage":"https://github.com/react-keycloak/react-keycloak#readme","keywords":["react","keycloak","keycloak-js","nextjs","razzle"],"main":"lib-commonjs/index.js","jsnext:main":"lib/index.js","module":"lib/index.js","typings":"lib/index.d.ts","publishConfig":{"access":"public"},"funding":{"type":"patreon","url":"https://www.patreon.com/reactkeycloak"},"scripts":{"clean":"rimraf lib lib-commonjs","prebuild":"npm run clean","compile:commonjs":"tsc --module commonjs --outDir lib-commonjs","compile:esnext":"tsc --module esnext --outDir lib","compile":"run-p compile:*","fixmaps:lib":"tweak_sourcemap_paths -a --include 'lib/**/*.js.map' 'lib-commonjs/**/*.js.map'","fixmaps":"run-p fixmaps:*","build":"run-s compile fixmaps","test":"jest","test:coverage":"jest --coverage","coveralls":"cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js","prepublishOnly":"npm run build"},"peerDependencies":{"keycloak-js":">=9.0.2","react":">=16.8","typescript":">=3.8"},"peerDependenciesMeta":{"typescript":{"optional":true}},"dependencies":{"@babel/runtime":"^7.9.0","@baolq/react-keycloak-core":"^4.1.0","detect-node":"^2.0.4","hoist-non-react-statics":"^3.3.2","js-base64":"^3.4.5","js-cookie":"^2.2.1"},"jest":{"preset":"ts-jest","testEnvironment":"jsdom"},"gitHead":"52e8b5d6397c52423c1e4b45ea5145a760c6183d","_id":"@baolq/react-keycloak-ssr@3.4.2","_nodeVersion":"18.17.1","_npmVersion":"lerna/3.22.1/node@v18.17.1+x64 (win32)","dist":{"integrity":"sha512-UX5WLm+j62WDRYCEUDGPi4rdMdItBQHovD5ou+vdveDuEY8j/Wzj4Cq6ra/7eadEAYnhaTftf8kxnhq1vuTU/g==","shasum":"9de3245e35d63da6a3eb5c5eb4bfb906736d3925","tarball":"https://registry.npmjs.org/@baolq/react-keycloak-ssr/-/react-keycloak-ssr-3.4.2.tgz","fileCount":82,"unpackedSize":87787,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDzOIBpPsT8frWooq7qIiDX5xQBJOs4l9CbjAVh3PbzCwIgetyiEeYRqmmEH1tETgr7Ri9xc+KGoeiDt1c8gsd2JU8="}]},"_npmUser":{"name":"baolq","email":"bao.lq.it@gmail.com"},"directories":{},"maintainers":[{"name":"baolq","email":"bao.lq.it@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/react-keycloak-ssr_3.4.2_1708420492713_0.35983392880447185"},"_hasShrinkwrap":false}},"time":{"created":"2024-02-16T06:11:03.681Z","3.3.0":"2024-02-16T06:11:03.984Z","modified":"2024-02-20T09:14:53.342Z","3.4.1":"2024-02-16T06:25:38.762Z","3.4.2":"2024-02-20T09:14:52.860Z"},"maintainers":[{"name":"baolq","email":"bao.lq.it@gmail.com"}],"description":"SSR bindings for Keycloak javascript adapter","homepage":"https://github.com/react-keycloak/react-keycloak#readme","keywords":["react","keycloak","keycloak-js","nextjs","razzle"],"repository":{"type":"git","url":"git+https://github.com/react-keycloak/react-keycloak.git"},"author":{"name":"Mattia Panzeri","email":"mattia.panzeri93@gmail.com"},"bugs":{"url":"https://github.com/react-keycloak/react-keycloak/issues"},"license":"MIT","readme":"![React Keycloak](/art/react-keycloak-logo.png?raw=true 'React Keycloak Logo')\n\n# React Keycloak <!-- omit in toc -->\n\n> SSR bindings for [Keycloak](https://www.keycloak.org/)\n\n[![NPM (scoped)](https://img.shields.io/npm/v/@react-keycloak/ssr?label=npm%20%7C%20ssr)](https://www.npmjs.com/package/@react-keycloak/ssr)\n\n[![License](https://img.shields.io/github/license/react-keycloak/react-keycloak.svg)](https://github.com/react-keycloak/react-keycloak/blob/master/LICENSE.md)\n[![lerna](https://img.shields.io/badge/maintained%20with-lerna-cc00ff.svg)](https://lerna.js.org/)\n[![GitHub contributors](https://img.shields.io/github/contributors/react-keycloak/react-keycloak)](https://github.com/react-keycloak/react-keycloak/graphs/contributors)\n[![Github Issues](https://img.shields.io/github/issues/react-keycloak/react-keycloak.svg)](https://github.com/react-keycloak/react-keycloak/issues)\n\n[![Gitter](https://img.shields.io/gitter/room/react-keycloak/community)](https://gitter.im/react-keycloak/community)\n\n---\n\n## Table of Contents <!-- omit in toc -->\n\n- [Install](#install)\n- [Getting Started](#getting-started)\n  - [Setup](#setup)\n    - [NextJS](#nextjs)\n    - [Razzle](#razzle)\n  - [Hook Usage](#hook-usage)\n- [Examples](#examples)\n- [Guides and Articles](#guides-and-articles)\n- [Other Resources](#other-resources)\n  - [Securing NextJS API](#securing-nextjs-api)\n  - [External Usage (Advanced)](#external-usage-advanced)\n- [Alternatives](#alternatives)\n- [Contributing](#contributing)\n- [License](#license)\n\n---\n\n## Install\n\nReact Keycloak requires:\n\n- React **16.8** or later\n- `keycloak-js` **9.0.2** or later\n\n```shell\nyarn add @react-keycloak/ssr\n```\n\nor\n\n```shell\nnpm install --save @react-keycloak/ssr\n```\n\n## Getting Started\n\nThis module has been created to support `NextJS` and `Razzle`, other SSR frameworks might be working as well.\n\n### Setup\n\nFollow 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).\n\n#### NextJS\n\nRequires NextJS **9** or later\n\nCreate the `_app.tsx` file under `pages` folder and wrap your App inside `SSRKeycloakProvider` component and pass `keycloakConfig` and a `TokenPersistor`.\n\n**Note:** `@react-keycloak/ssr` provides a default `TokenPersistor` which works with `cookies` (exported as `ServerPersistors.SSRCookies`).\n\nThe following examples will be based on that.\n\n```tsx\nimport cookie from 'cookie'\nimport * as React from 'react'\nimport type { IncomingMessage } from 'http'\nimport type { AppProps, AppContext } from 'next/app'\n\nimport { SSRKeycloakProvider, SSRCookies } from '@react-keycloak/ssr'\n\nconst keycloakCfg = {\n  realm: '',\n  url: '',\n  clientId: '',\n}\n\ninterface InitialProps {\n  cookies: unknown\n}\n\nfunction MyApp({ Component, pageProps, cookies }: AppProps & InitialProps) {\n  return (\n    <SSRKeycloakProvider\n      keycloakConfig={keycloakCfg}\n      persistor={SSRCookies(cookies)}\n    >\n      <Component {...pageProps} />\n    </SSRKeycloakProvider>\n  )\n}\n\nfunction parseCookies(req: IncomingMessage) {\n  return cookie.parse(req.headers.cookie || '')\n}\n\nMyApp.getInitialProps = async (context: AppContext) => {\n  // Extract cookies from AppContext\n  return {\n    cookies: context.ctx.req ? parseCookies(context.ctx.req) : {},\n  }\n}\n\nexport default MyApp\n```\n\n#### Razzle\n\nRequires `Razzle` **3** or later\n\n> **N.B:** This setup requires you to install [`cookie-parser`](https://github.com/expressjs/cookie-parser) middleware.\n\nEdit your app `server.js` as follow\n\n```js\n...\n\nimport { ExpressCookies, SSRKeycloakProvider } from '@react-keycloak/ssr'\n\n// Create a function to retrieve Keycloak configuration parameters -- 'see examples/razzle-app'\nimport { getKeycloakConfig } from './utils'\n\nconst assets = require(process.env.RAZZLE_ASSETS_MANIFEST)\n\nconst server = express()\nserver\n  .disable('x-powered-by')\n  .use(express.static(process.env.RAZZLE_PUBLIC_DIR))\n  .use(cookieParser()) // 1. Add cookieParser Express middleware\n  .get('/*', (req, res) => {\n    const context = {}\n\n    // 2. Create an instance of ExpressCookies passing the current request\n    const cookiePersistor = ExpressCookies(req)\n\n    // 3. Wrap the App inside SSRKeycloakProvider\n    const markup = renderToString(\n      <SSRKeycloakProvider\n        keycloakConfig={getKeycloakConfig()}\n        persistor={cookiePersistor}\n      >\n        <StaticRouter context={context} location={req.url}>\n          <App />\n        </StaticRouter>\n      </SSRKeycloakProvider>\n    )\n    ...\n  })\n\n...\n```\n\nEdit your `client.js` as follow\n\n```js\nimport { Cookies, SSRKeycloakProvider } from '@react-keycloak/ssr'\n\n// Create a function to retrieve Keycloak configuration parameters -- 'see examples/razzle-app'\nimport { getKeycloakConfig } from './utils'\n\n// 1. Create an instance of Cookies\nconst cookiePersistor = new Cookies()\n\n// 2. Wrap the App inside SSRKeycloakProvider\nhydrate(\n  <SSRKeycloakProvider\n    keycloakConfig={getKeycloakConfig()}\n    persistor={cookiePersistor}\n  >\n    <BrowserRouter>\n      <App />\n    </BrowserRouter>\n  </SSRKeycloakProvider>,\n  document.getElementById('root')\n)\n...\n```\n\n### Hook Usage\n\nWhen a component requires access to `Keycloak`, you can use the `useKeycloak` Hook.\n\n```js\nimport { useKeycloak } from '@react-keycloak/ssr'\n\nexport default () => {\n  const { keycloak, initialized } = useKeycloak()\n\n  // Here you can access the current keycloak instance methods and variables...\n\n  return (\n    <div>\n      <div>{`User is ${\n        !keycloak.authenticated ? 'NOT ' : ''\n      }authenticated`}</div>\n\n      {!!keycloak.authenticated && (\n        <button type=\"button\" onClick={() => keycloak.logout()}>\n          Logout\n        </button>\n      )}\n    </div>\n  )\n}\n```\n\n## Examples\n\nSee inside `examples/nextjs-app` and `examples/razzle-app` folders of [`@react-keycloak/react-keycloak-examples`](https://github.com/react-keycloak/react-keycloak-examples) repository for sample implementations.\n\n## Guides and Articles\n\n- Migration guide for `@react-keycloak/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).\n\n## Other Resources\n\n### Securing NextJS API\n\nWhilst `@react-keycloak/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).\n\nThanks to [@webdeb](https://github.com/webdeb) for reporting the issue and helping develop a solution.\n\n### External Usage (Advanced)\n\nIf 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.\n\nThe 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...).\n\n**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).\n\nThanks to [@webdeb](https://github.com/webdeb) for requesting this feature and helping develop and test the solution.\n\n## Alternatives\n\nIf you need to connect using a more generic OIDC client instead of `keycloak.js`, consider using one of the following libraries:\n\n- [bjerkio/oidc-react](https://github.com/bjerkio/oidc-react)\n- [thchia/react-oidc](https://github.com/thchia/react-oidc)\n- [@axa-fr/react-oidc](https://github.com/AxaGuilDEv/react-oidc)\n\n## Contributing\n\nSee 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.\n\n## License\n\nMIT\n\n---\n\nIf you found this project to be helpful, please consider buying me a coffee.\n\n[![buy me a coffee](https://www.buymeacoffee.com/assets/img/custom_images/orange_img.png)](https://buymeacoff.ee/4f18nT0Nk)\n","readmeFilename":"README.md"}