Giter Club home page Giter Club logo

Comments (16)

juansmolano avatar juansmolano commented on September 4, 2024 9

Hi @mauriciovigolo

At the moment we are enhancing a Platform with PWA attributes, Offline access to be precise. We are using Angular 6 with keycloak-angular. So far everything is fine (Thanks you so much for keycloak-angular :D )
The problem we are having is trying to came up with an strategy for offline access. Keycloak official documentation explains offline access in this URL: https://www.keycloak.org/docs/3.2/server_admin/topics/sessions/offline.html but we do not understand how to achieve offline access using keycloak-angular.
It could really help us if you can just give us some help or advice to enable offline access using keycloak-angular

We are willing to either help with the implementation or documentation, we just need someone to point us the right way to go.

from keycloak-angular.

mauriciovigolo avatar mauriciovigolo commented on September 4, 2024 4

@juansmolano, thanks for sharing your thoughts and needs. The keycloak do have support for offline access, however, as far as I know, keycloak-js doesn't. So consequently, keycloak-angular doesn't have it too.
I also think this is a must feature, supporting both PWA and Ionic, so we could move forward this discussion and feature.

from keycloak-angular.

nerumo avatar nerumo commented on September 4, 2024 1

My workaround:

  • Increase the SSO Session Timeout to numbers that are usual for offline tokens
  • Use standard flow (I need the refresh token)
  • Override the KeycloakService to handle offline scenarios more gracefully
import { KeycloakService } from 'keycloak-angular';

export class OfflineKeycloakService extends KeycloakService {
  async updateToken(minValidity: number = 5) {
    try {
      return await super.updateToken (minValidity);
    } catch (err) {
      // this means that there was an issue with
      // the network or the server, but no logout occurred
      if ((<any>this)._instance.refreshToken) {
        return false;
      }
      // if the token got removed, it means that there
      // was a 400 of the server
      throw err;
    }
  }
}

It's a hack, it's limited, it's less secure...but maybe it helps somebody.

from keycloak-angular.

Rezorl avatar Rezorl commented on September 4, 2024 1

Hi,

Anything new about this? I'm creating a PWA app that uses keycloak-angular and needs offline access.

from keycloak-angular.

mauriciovigolo avatar mauriciovigolo commented on September 4, 2024

@aelkz, you are right, this is something we really could move on.

In progressive web apps, are you suggesting to describe offline access?

from keycloak-angular.

mauriciovigolo avatar mauriciovigolo commented on September 4, 2024

@aelkz could you add more information about which features we need to doc for PWA? Tks!

from keycloak-angular.

bligny avatar bligny commented on September 4, 2024

Have a look at this interesting post:
https://stackoverflow.com/questions/35270343/keycloak-javascript-adapter-request-offline-token

The init method doesn't accept the scope option, but the login method does.

from keycloak-angular.

dieAte avatar dieAte commented on September 4, 2024

Are there any new Documentations about using keycloak-angular with PWA or Cordova apps, with or without offline access token?

from keycloak-angular.

jonkoops avatar jonkoops commented on September 4, 2024

There are no updates on documentation to use Keycloak Angular in an offline app. There is some discussion going on in #232 about offline tokens.

It would of course be great if we can get documentation for this in place so if you have any experience using Keycloak offline please do share.

from keycloak-angular.

jonkoops avatar jonkoops commented on September 4, 2024

Closing this in favour of #272

from keycloak-angular.

WernerRaath avatar WernerRaath commented on September 4, 2024

Just FYI, one can pass in your token, id token and refresh tokens into the init command, so storing them upon login in localStorage should work well.

    const keycloakToken = localStorage.keycloakToken
    const keycloakIdToken = localStorage.keycloakIdToken
    return keycloak
      .init({
        onLoad: 'login-required',
        checkLoginIframe: false,
        flow: 'hybrid',
        scope: 'openid offline_access',
        token: keycloakToken,
        idToken: keycloakIdToken
      })
      .success((authenticated) => {
        console.log(keycloak)
        localStorage.keycloakToken = keycloak.token
        localStorage.keycloakIdToken = keycloak.idToken
        localStorage.keycloakRefreshToken = keycloak.refreshToken
      })
      .error(function() {
        alert('failed to initialize')
      })

from keycloak-angular.

fstouten avatar fstouten commented on September 4, 2024

hi all,

Did someone find a solution as how to make keycloak-angular work with PWA? Or does the post by WerrnerRaath is a valid solution?

from keycloak-angular.

ITOmauricioherran avatar ITOmauricioherran commented on September 4, 2024

Any news?

from keycloak-angular.

ITOmauricioherran avatar ITOmauricioherran commented on September 4, 2024

Hi,

Anything new about this? I'm creating a PWA app that uses keycloak-angular and needs offline access.

@Rezorl did you found any solution?

from keycloak-angular.

Rezorl avatar Rezorl commented on September 4, 2024

@ITOmauricioherran

Yes, but I don't know if this is the right solution. However, everything works as it should.
Link to source code: https://github.com/Rezorl/angular-keycloak-pwa

from keycloak-angular.

Codefans-fan avatar Codefans-fan commented on September 4, 2024

@ITOmauricioherran

Yes, but I don't know if this is the right solution. However, everything works as it should. Link to source code: https://github.com/Rezorl/angular-keycloak-pwa

Seem this only work when my device have no internet. Can we detective whether keycloak or server is online or offline ?
then we go offline or not ?

from keycloak-angular.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.