Skip to content
This repository has been archived by the owner on Apr 3, 2023. It is now read-only.

Support keycloak-js v17.0.0 #180

Open
fredriklindell opened this issue Feb 12, 2022 · 28 comments
Open

Support keycloak-js v17.0.0 #180

fredriklindell opened this issue Feb 12, 2022 · 28 comments

Comments

@fredriklindell
Copy link

Describe the bug
Unhandled Runtime Error
TypeError: Keycloak is not a constructor

When using @react-keycloak/ssr together with the latest version of keycloak-js.

To Reproduce
Steps to reproduce the behavior:

  1. React or NextJS application, in this case NextJS
  2. Install keycloak.js v17.0.0
  3. Install @react-keycloak/ssr v3.3.0
  4. Build and start application
  5. Go to http://localhost:3000
  6. See error

Expected behavior
Page should render without error as when same config but for earlier version of keycloak-js (v16.1.1).

Desktop (please complete the following information):

  • OS: Arch linux
  • Browser: chromium
  • Version: 98.0.4758.80 (Official Build) Arch Linux (64-bit)

Additional context
Unhandled Runtime Error
TypeError: Keycloak is not a constructor

Call Stack
getKeycloakInstance
node_modules/@react-keycloak/ssr/lib/internals/keycloak.js (25:0)
new SSRKeycloakProvider
node_modules/@react-keycloak/ssr/lib/SSRKeycloakProvider.js (63:41)

@bnopacheco
Copy link

bnopacheco commented Feb 20, 2022

same problem here

OS: macOS 10.14.6
Browser: Chrome
Version: 98.0.4758.102 (Versão oficial) (x86_64)

@irhamputra
Copy link

irhamputra commented Feb 22, 2022

any update? otherwise with keycloak-js@^16.1.1 is still working like a charm

@fredriklindell
Copy link
Author

FYI!

I found that Next-Auth now has a Keycloak provider. I migrated my app to use Next-Auth and it works really good.

@irhamputra
Copy link

@fredriklindell wow thats nice. But can you show me the workaround how do you implement?

@nouman91
Copy link

Any update on this will be really appreciated

@milosrs
Copy link

milosrs commented Apr 19, 2022

I have the same issue. Also, I'm getting a linter error on these lines stating:

<SSRKeycloakProvider
      keycloakConfig={keycloakCfg}
      initOptions={keycloakInitOptions}
      persistor={SSRCookies(cookies)}
      LoadingComponent={<Loader/>}
      autoRefreshToken={true}
    >
        <Component {...pageProps}/>
    </SSRKeycloakProvider>

Property 'children' does not exist on type 'IntrinsicAttributes & IntrinsicClassAttributes<SSRKeycloakProvider> & Readonly<SSRKeycloakProviderProps<SSRAuthClient>>

@tobiasfrei
Copy link

tobiasfrei commented May 4, 2022

it affects also 'keycloak v18.0.0', change needed in node_modules/@react-keycloak/ssr/lib/internals/keycloak.js

Line 20 (import default):
var Keycloak = !isServer() ? require('keycloak-js').default : null;

Line 25 (remove constructor):
keycloakInstance = Keycloak(keycloakConfig);

You are able to manage this package locally by resolving webpack modules, because it has become really quiet here.
resolve: { modules: ["node_modules", ROOT_PATH.resolve(__dirname, "dir/to/local/packages")], },

@rybkowskigrzegorz
Copy link

Have the same issue, reverting to previous versions on the other hand create a loop of log-in log-out. Any updates on where this can be fixed?

@SIMULATAN
Copy link

SIMULATAN commented May 7, 2022

I just noticed that using the keycloak.logout() method, it redirects you to the correct URL but with the query parameter redirect_uri instead of the correct redirect_url, is this also caused by the old keycloak-js version?

EDIT: I modified the keycloak.js file according to tobias and it FINALLY works now!
I also had to change the algorithm to HS256 tho, the server returned a HTTP 431 because the token in the request url was too long.
error

@tobiasfrei
Copy link

I've forked an updated package with Keycloak >=17 support until this one is back, you can use npm i @react-keycloak-fork/web --save and npm i @react-keycloak-fork/ssr --save

@react-keycloak-fork/web
@react-keycloak-fork/ssr

@tobiasfrei
Copy link

I've forked an updated package with Keycloak >=17 support until this one is back, you can use npm i @react-keycloak-fork/web --save and npm i @react-keycloak-fork/ssr --save

@react-keycloak-fork/web @react-keycloak-fork/ssr

Don't use this package or fork anymore, just use an openId connecter (oidc) and get rid of cookies and all that. Keycloak is in change.
https://www.keycloak.org/docs/latest/securing_apps/index.html#_modern_browsers

@SIMULATAN
Copy link

Please don't delete the package, I have a project using it due in 3 days and don't have the time to upgrade. (It's only a "testing"-project with no real issues with loosing things)

@tobiasfrei
Copy link

tobiasfrei commented Jun 7, 2022

Please don't delete the package, I have a project using it due in 3 days and don't have the time to upgrade. (It's only a "testing"-project with no real issues with loosing things)

I would never delete any package for sure. Just in case if you build big prod projects, use openid and only bearer. Otherwise you got a hard time to impersonate users role based.

@stephane-segning
Copy link

So after some researches I came across this library here https://www.npmjs.com/package/react-oidc-context which is doing the same job.

@giovannalinda
Copy link

giovannalinda commented Jul 13, 2022

hey @milosrs

did you manage to solve the problem? I have the same issue

@milosrs
Copy link

milosrs commented Jul 13, 2022

hey @milosrs

did you manage to solve the problem? I have the same issue

I have switched to NextAuth

@bitpickle
Copy link

@milosrs

can you show me how you implemented with NextAuth?

@pecataToshev
Copy link

@milosrs
If it's possible I also would like to take a look in your implementation 😃

@milosrs
Copy link

milosrs commented Jul 20, 2022

@pecataToshev
@bitpickle
@giovannalinda
Due to multiple requests, I'm making my example public. See my profile and look for marketing bots frontend.
https://github.com/milosrs/marketing-bots-frontend

@bitpickle
Copy link

@pecataToshev @bitpickle @giovannalinda Due to multiple requests, I'm making my example public. See my profile and look for marketing bots frontend. https://github.com/milosrs/marketing-bots-frontend

Thank you <3

@Sup3r-Us3r
Copy link

@milosrs

can you show me how you implemented with NextAuth?

I also chose to use NextAuth in Next.js, and I also created a Backend in Node.js with the implementation of keycloak-connect to simulate a real case, in which we need to consume a service that requires Keycloak authentication, the process is all documented step by step, the implementation in Next.js still has a Refresh Token, if you want to see it here it is:

https://github.com/Sup3r-Us3r/keycloak-nextjs-nodejs

@milosrs
Copy link

milosrs commented Aug 6, 2022

@Sup3r-Us3r
Look at my comment above.

@Sup3r-Us3r
Copy link

@milosrs Yes I saw your comment, it's just another implementation I wanted to share, both are valid, thanks!

@milosrs
Copy link

milosrs commented Aug 6, 2022

@Sup3r-Us3r
Oooh sorry, I didn't understand it at first. Great job!

@Shovan1016
Copy link

npm i keycloak-js@12.0.3 -----this is the solution

@adibamine
Copy link

https://github.com/milosrs/marketing-bots-frontend

I wanted to switch to nextauth, but i can t understand why does it need client secret for the configuration.
react-keycloak-ssr requires the client id only.
Any idea?

@lcanavesio
Copy link

Hello.
I ended up creating a simple project. You can use it and tell me if it worked for you.
npm install react-keycloak-js --save

@rsevalueserve
Copy link

I have the same issue. Also, I'm getting a linter error on these lines stating:

<SSRKeycloakProvider
      keycloakConfig={keycloakCfg}
      initOptions={keycloakInitOptions}
      persistor={SSRCookies(cookies)}
      LoadingComponent={<Loader/>}
      autoRefreshToken={true}
    >
        <Component {...pageProps}/>
    </SSRKeycloakProvider>

Property 'children' does not exist on type 'IntrinsicAttributes & IntrinsicClassAttributes<SSRKeycloakProvider> & Readonly<SSRKeycloakProviderProps<SSRAuthClient>>

I solve using the fork version https://www.npmjs.com/package/@react-keycloak-fork/web

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests