gibahjoe / keycloak_flutter

Keycloak package for easy integration with flutter applications
BSD 3-Clause "New" or "Revised" License
24 stars 24 forks source link

updateToken() method does not refresh the access token #10

Open ptawde95 opened 3 years ago

ptawde95 commented 3 years ago

Describe the bug :

Using the package i am trying to refresh the access token by calling updateToken method which makes the refreshtoken api request from keyclaok.js. but the request returns Status 400 Bad Request ,then i checked the request in browser tool(network tab),the refresh_token is passed as undefined. I also tried to passed -1 as parameter to the updateToken() which forcefully refresh the token.

access_token expires in : 1 min

Expected behavior : The updatetoken method should refreshtoken if access token is expiry.

Flutter Version: Flutter 2.0.1 • channel beta • https://github.com/flutter/flutter.git Framework • revision c5a4b4029c (10 weeks ago) • 2021-03-04 09:47:48 -0800 Engine • revision 40441def69 Tools • Dart 2.12.0

gibahjoe commented 3 years ago

Hello, I just tested this on the sample app and it refreshes just fine. Please provide minimal code so that I can reproduce the error. Thanks

ptawde95 commented 3 years ago

Hi @gibahjoe Thanks for your Response.

Code to reproduce :

            // set the KeycloakConfig

          keycloakService = KeycloakService(KeycloakConfig(
                  url: '$keycloakIssuer://$keycloakWebDomain',
                  realm: '$keycloakRealm',
                  clientId: '$keycloakClientId',
                )); 

         // To listen all keycloak Events   

         keycloakService.keycloakEventsStream.listen((event) {
                  if (event.type == KeycloakEventType.onAuthSuccess) {

        print('event.type == KeycloakEventType.onAuthSuccess IN MuApp OnInIt');
        print(event.type == KeycloakEventType.onAuthSuccess);

        ///ACCESS_TOKEN ACCESS
        keycloakService.getToken(true).then((value) {
          print('keycloakService.getToken Response');
          print(value);

        }).catchError((e) {
          print('keycloakService.getToken Error Response');
          print(e);
        });
      }

      if (event.type == KeycloakEventType.onAuthRefreshError) {
        print(event.type);
      }

      if (event.type == KeycloakEventType.onAuthLogout) {
        print(event.type);
      }

      if (event.type == KeycloakEventType.onAuthRefreshSuccess) {
        print(event.type);
      }
    });

                    // Keycloak Service initialization      

                    keycloakService.init(
                              initOptions: KeycloakInitOptions(
                              onLoad: 'check-sso',
                              enableLogging: true,
                              silentCheckSsoRedirectUri:'http://localhost/silent-check-sso.html',

                            ));

Also Observed

Console Logs :

image (10)

This occurs initially , but if i comment the updateToken method call in the getToken method of Keycloak service. i was able to get the access token.

ptawde95 commented 3 years ago

@gibahjoe Any update..?