mauriciovigolo / keycloak-angular

Easy Keycloak setup for Angular applications.
MIT License
729 stars 280 forks source link

Token and Refresh Token expired instantaneously #237

Closed KrzAyi closed 4 years ago

KrzAyi commented 4 years ago

Bug Report or Feature Request (mark with an x)

- [ x ] bug report
- [   ] feature request

Versions

 keycloak-angular: 7.2.0
 keycloak-js: 7.0.1
 angular: 8.1.1

The log given

capturaLog

I am having problems with authentication.

Keycloak takes the token as expired immediately after obtaining it.

As can be seen in the following images, the tokens are valid with respect to the expiration time.

token

refresh

This happens only on some devices, and they are always the same (from phones, tablets, noteeboks).

As I read in another thread, when the Token is expired, keycloak-js automatically executes the UpdateToken method, and that generates an infinite loop from which I cannot exit.

Do you have any idea what might be happening? Thanks.

vmagalhaes commented 4 years ago

Same to me! I think is something with Google Chrome last update

vmagalhaes commented 4 years ago

Hey @mauriciovigolo I think this can resolve our question. https://issues.redhat.com/browse/KEYCLOAK-12125?_sscc=t

KrzAyi commented 4 years ago

Hi @vmagalhaes!

I was able to solve the problem by adding the checkLoginIframe property in the init function options of the keycloakservice, like this:

import { KeycloakService } from 'keycloak-angular';
import { config } from 'src/configs/config';

export function initializer(keycloak: KeycloakService): () => Promise<any> {
  return (): Promise<any> => keycloak.init({
    config: config.keycloak,
    initOptions: {
      checkLoginIframe: false
    },
    enableBearerInterceptor: true,
    bearerExcludedUrls: ['/assets', '/'],
  });
}

checkLoginIframe is true by default, this property needs to be false.

Thanks for sharing the redhat issue, it was very helpful.

Greetings.

jonkoops commented 4 years ago

Sorry for the late reply, but the problem is most likely indeed a combination of Chrome and an older version of Keycloak. If your problem is resolved @KrzAyi then I will go ahead and close this issue.