Comments (10)
@abhishekkaura and @angular101
I've been working on a new example to show how to handle the keycloak events and I started to build it using angular 6, so I came across a bigger issue, regarding the angular versions. I expect to finish all the migration to angular 6 this weekend and also release the examples.
from keycloak-angular.
Hi @angular101,
First of all you need to check your keycloak initialization. From the keycloak javascript adapter docs
By default, the JavaScript adapter creates a hidden iframe that is used to detect if a Single-Sign Out has occurred. This does not require any network traffic, instead the status is retrieved by looking at a special status cookie. This feature can be disabled by setting checkLoginIframe: false in the options passed to the init method.
You should not rely on looking at this cookie directly. Itβs format can change and itβs also associated with the URL of the Keycloak server, not your application.
So, you cannot set the checkLoginIframe to false.
Regarding the way to invoke a function for the events, you could do something like this:
ngOnInit() {
....
const keycloakInstance = this.keycloakService.getKeycloakInstance();
keycloakInstance.onAuthLogout = () => console.log('logout');
}
This code is just an example, use it inside the best method or function in your project.
from keycloak-angular.
Hi @mauriciovigolo ,
Thanks for responding and sorry for my late response.
I checked and I have checkLoginIframe set to false.
onAuthLogout works fine - I still cannot get onAuthSuccess to fire?
I register the onAuthSuccess callback after keycloak.init() which is maybe too late, is it?
but I cannot set it up before keycloak.init() as keycloak instance is undefined.
You see what I mean?
from keycloak-angular.
Hi @mauriciovigolo ,
As an example I've set onAuthSuccess in 2 locations below in the keycloakService init() method:
The first will be called - the second won't (if you uncomment it)
I presume first one is called because it's set before _this.instance.init() is called.
The second is after _this.instance.init() and seems to be too late?
Given the current keycloakService implementation I can only get the keycloak instance after this, so how can I set onAuthSuccess so it will be called? I must be missing something?
Thanks.
KeycloakService.prototype.init = function (options) {
var _this = this;
if (options === void 0) { options = {}; }
return new Promise(function (resolve, reject) {
_this.bearerExcludedUrls = options.bearerExcludedUrls || [];
_this.instance = Keycloak(options.config);
_this.instance.onAuthSuccess = () => { console.log('************ LOGIN')};
_this.instance
.init(options.initOptions)
.success(function (authenticated) {
// _this.instance.onAuthSuccess = () => { console.log('************ LOGIN')};
return __awaiter(_this, void 0, void 0, function () {
from keycloak-angular.
Hi,
It's been a week since my last post so hopefully someone can find a little time to just confirm/deny what I'm asking.
I don't think it's possible to set onReady or onAuthSuccess correctly with the current KeycloakService implementation because you can only set them after keycloak has initialized?
Thanks.
from keycloak-angular.
Hi @angular101,
Sorry for the delay. You can only set the events after the keycloak-js initialization. I was working on an example to show you how to handle the events, but didn't finish it yet.
Don't know if it is clear, but onAuthSuccess will be called if there is a second tab opened and a success login happen. The login workflow should not be onLoad: 'login-required', because in this case, if the user is not logged in, he will be redirected to the keycloak login page.
You should instead use onLoad: 'check-sso' and add the route without authentication in the bearerExcludedUrls array, then if a log in happens in another tab you will be able to get the event.
I will try to add an example today, okay? You could also find me on slack.
from keycloak-angular.
Thanks @mauriciovigolo appreciate you creating an example.
from keycloak-angular.
@angular101 @mauriciovigolo By any chance you are able to create example as I am also facing the same issue for onAuthSuccess()
from keycloak-angular.
@mauriciovigolo Thanks !!!
from keycloak-angular.
Just found a bug in KeycloakService while doing the example, related to the order to register the events.
@angular101, during the keycloak-js events tests, I discover that the only propagated event between tabs is the onAuthLogout. All the others don't work between tabs. π
Thanks for reporting.
from keycloak-angular.
Related Issues (20)
- Angular v.17 update HOT 5
- KeycloakService#getUserRoles() filter by resource HOT 2
- Loop after keycloak redirect to angular website HOT 6
- Support for Pure Function-Based Guards in Angular HOT 2
- Support for Keycloak v23 HOT 9
- The JSDoc for getToken states it calls updateToken if necessary, but it does not HOT 1
- How I would know when the session is expired? HOT 1
- Problem with KeycloakService in Angular 17 HOT 1
- KeycloakAuthGuard example HOT 4
- Server-side rendering (SSR) crash with 'Document not found' error in Keycloak-angular with Angular 17 HOT 10
- keycloakBearerInterceptorFn example HOT 1
- Login method locale is not changing the user locale when the user logs in
- angular crashes with check-sso
- Support KC 24.x.x HOT 6
- Catch sign out event or redirect to ssop event
- keycloak-angular - next version improvements HOT 1
- Bug in package.json version 15.2.0 HOT 3
- Keycloak setup for Single SPA angular Project
- HttpClient Interceptor not working HOT 2
- Configure updateToken minValidity in HTTP Interceptor
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from keycloak-angular.