question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

set checkLoginIframe=false and then get error=login_required

See original GitHub issue

I’m using @react-keycloak/ssr 3.3.0, keycloak-js 12.0.4 and nextjs 10.1.3. I have to set checkLoginIframe=false in order to initialize keycloak by access token and refresh token. However, if a user is not logged in (both refresh token and access token are empty), the page will be reloaded. Then, I get this link http://localhost:3000/#error=login_required&state=9d3ee440-4001-464d-8926-ec1985dd1359. But if I try initializing KeycloakInstance of keycloak-js by the same configuration, everything is fine. My codes

 const keycloakConfig = {
        clientId: process.env.NEXT_PUBLIC_KEYCLOAK_CLIENT_ID,
        realm: process.env.NEXT_PUBLIC_KEYCLOAK_REALM,
        url: process.env.NEXT_PUBLIC_KEYCLOAK_URL
    };
    return (
        <SSRKeycloakProvider
            keycloakConfig={keycloakConfig}
            autoRefreshToken={true}
            initOptions={{
                // onLoad: "check-sso",
                // promiseType: "native",
                token: credentials.accessToken,
                refreshToken: credentials.refreshToken,
                checkLoginIframe: false,
                enableLogging: process.env.NEXT_PUBLIC_KEYCLOAK_ENABLE_LOGGING === "true"
            }}
            LoadingComponent={<BackdropLoading open={true} />}
            persistor={SSRCookies(cookies)}>
           {/* other components */}
        </SSRKeycloakProvider>
    );

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:2
  • Comments:9

github_iconTop GitHub Comments

1reaction
edivanteixeiracommented, Aug 23, 2022

This error is because the version of Keycloak-js is different from your server.

1reaction
fangwohungcommented, Dec 18, 2021

@fangwohung Could you please share your setup with next-auth-keycloak? I tried to implement it, but has a lot of uncertainty and couldn’t figured out the right init (and how to pass initOptions) Here with react-keycloak/ssr I am getting a token, but then same issue - next keep reloading an app and I could not understand why

If you’re using next-auth, you dont have to use keycloak-js client because your keycloak tokens (access token and refresh token) will be stored within next-auth session and then you can get session data by calling useSession (next-auth hook). I think you can try next-auth with google provider in order to understand how next-auth works, you also have to implement Refresh Token Rotation on your own. You must remember that the next-auth token is different from keycloak tokens which are stored within session

Unfortunately, I bound to keycloak because of the SSO and backend team preferences

Before using next auth, I had this issue and then used pure keycloak js for nextjs, I handled everything on client side, but the drawback of keycloakjs is that I cannot get the access token on server side and cannot take advantage of SSR. I havent implemented SSO for next auth yet, so you have to implement SSO feature by yourself if you really want to use next auth

Read more comments on GitHub >

github_iconTop Results From Across the Web

Keycloak does not login with checkLoginIframe true, refresh ...
The error is: [KEYCLOAK] Failed to refresh token. In the network tab I can see the client sends a request to the Keycloak...
Read more >
Automatic Login to Javascript Client Adapter with inital Access ...
I suppose it means that login failed somehow, however without anything like that in the server log. What could be going wrong here?...
Read more >
Keycloak Refresh Issue for angular application - Google Groups
I am using keycloak JavaScript adapter in my Angular 11 app and whilst my login and redirection work, the problem is that whenever...
Read more >
Chapter 2. Using OpenID Connect to secure applications and ...
If set to true , then during authentication with the bearer token, the adapter will verify whether the token contains this client name...
Read more >
How to Improve Web Application Security with Single Sign-On
Web application authentication is a very important mechanism to protect ... .init({ checkLoginIframe: false, }) .then(async (authenticated) ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found