8000 keycloak.js example from the documentation leads to error path · Issue #8935 · keycloak/keycloak · GitHub
[go: up one dir, main page]

Skip to content

keycloak.js example from the documentation leads to error path #8935

Closed

Description

@ioah86

Describe the bug

When I tried to implement the example from the documentation, namely

<html>
<head>
    <script src="keycloak.js"></script>
    <script>
        function initKeycloak() {
            var keycloak = new Keycloak();
            keycloak.init().then(function(authenticated) {
                alert(authenticated ? 'authenticated' : 'not authenticated');
            }).catch(function() {
                alert('failed to initialize');
            });
        }
    </script>
</head>
<body >
    <!-- your page content goes here -->
</body>
</html>

I consistently reached the "failed to initialize" alert.

When printing out the error code, it was coming from this line. Upon further debugging, it appears that the variable kc.messageReceiveTimeout is null, while the default timeout is supposed to be 10000. Studying the initialization, I came to the conclusion that it never gets initialized here, since this if-condition will not be fulfilled if init is not called with a non-empty options parameter. But that is what is being done in the example from the documentation.

So, this is an issue of default parameters not being initialized (or the documentation needs fixing; your team's call ;-))

Version

15.0.1

Expected behavior

I would have expected that default values are set no matter what is passed to the init function.

Actual behavior

As mentioned in the description, my code is reaching the catch statement.

How to Reproduce?

Just use your example as is from the documentation, point it to an OIDC configured client, and you should be able to reproduce.

Anything else?

No response

Activity

  1. FlyveHest commented on Apr 1, 2022

    @FlyveHest

    I can confirm that this is still an issue in 17.0.1, doing this

    keycloak.init({messageReceiveTimeout: 10000});

    lets you actually progress using the javascript adapter.

  2. added this to the milestone on Mar 16, 2023
  3. pelepelin commented on Feb 22, 2024

    @pelepelin

    Still an issue with keycloak-js@23.

    With keycloak.init({}) the default messageReceiveTimeout is properly set to 10000 ms but with keycloak.init() it's effectively 0.

    This line

    kc.messageReceiveTimeout = 10000;

    is never executed in the latter case because of this

    Looking at the code, there are more options which suffer from the same problem.

  4. jonkoops commented on Feb 22, 2024

    @jonkoops
    Contributor

    Feel free to submit a fix for this, we'll accept PRs.

  5. 29 remaining items

  6. added this to the milestone on Oct 15, 2024
  7. added a commit that references this issue on Oct 15, 2024
    ef7c017
  8. added 2 commits that reference this issue on Oct 15, 2024
    228c21a
    25d8bce
  9. added a commit that references this issue on Oct 15, 2024
    253ca1d
  10. removed this from the milestone on Oct 16, 2024
  11. mVirat22 commented on Nov 11, 2024

    @mVirat22

    Hello,
    I have a customised theme for keycloak account management page, where we can edit user info.
    So when we try to
    var keycloak = new Keycloak({
    authServerUrl: authUrl,
    realm: realm,
    clientId: 'account-console'
    });

    it throws error i.e. "Keycloak is not defined".
    Keycloak version 24.0.1 it works fine
    Keycloak version 26.0.0 this issue is happening.
    Any help/suggestion would be of appreciated.
    Thanks!

  12. FlyveHest commented on Nov 11, 2024

    @FlyveHest
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    0