Implement OIDC authentication
This commit is contained in:
committed by
Aditya Chandel
parent
548e09ae2c
commit
817b572c08
@@ -1,6 +1,6 @@
|
||||
import {RxStompConfig} from '@stomp/rx-stomp';
|
||||
import {API_CONFIG} from '../../config/api-config';
|
||||
import {AuthService} from '../../core/service/auth.service';
|
||||
import {API_CONFIG} from '../../config/api-config';
|
||||
|
||||
export function createRxStompConfig(authService: AuthService): RxStompConfig {
|
||||
return {
|
||||
@@ -9,10 +9,17 @@ export function createRxStompConfig(authService: AuthService): RxStompConfig {
|
||||
heartbeatOutgoing: 20000,
|
||||
reconnectDelay: 200,
|
||||
beforeConnect: (stomp) => {
|
||||
stomp.stompClient.connectHeaders = {'Authorization': `Bearer ${authService.getToken()}`};
|
||||
const oidcToken = authService.getOidcAccessToken();
|
||||
const internalToken = authService.getInternalAccessToken();
|
||||
const token = oidcToken || internalToken;
|
||||
if (token) {
|
||||
stomp.stompClient.connectHeaders = {
|
||||
'Authorization': `Bearer ${token}`,
|
||||
};
|
||||
}
|
||||
},
|
||||
debug: (msg: string): void => {
|
||||
//console.log(new Date(), msg);
|
||||
// console.log(new Date(), msg);
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { RxStomp } from '@stomp/rx-stomp';
|
||||
import {RxStomp, RxStompConfig} from '@stomp/rx-stomp';
|
||||
import { AuthService } from '../../core/service/auth.service';
|
||||
import { createRxStompConfig } from './rx-stomp.config';
|
||||
|
||||
@@ -7,9 +7,14 @@ import { createRxStompConfig } from './rx-stomp.config';
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class RxStompService extends RxStomp {
|
||||
|
||||
constructor(private authService: AuthService) {
|
||||
super();
|
||||
const stompConfig = createRxStompConfig(this.authService);
|
||||
this.configure(stompConfig);
|
||||
}
|
||||
|
||||
public updateConfig(config: RxStompConfig) {
|
||||
this.configure(config);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user