Skip to content

Commit

Permalink
Merge branch 'main' into enterprise-features
Browse files Browse the repository at this point in the history
  • Loading branch information
HarishGangula committed Dec 2, 2024
2 parents c1a591d + 4e1fd22 commit 183803e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
18 changes: 10 additions & 8 deletions src/main/helpers/proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Request, Response } from "express";
import _ from 'lodash'
import { incrementApiCalls, incrementFailedApiCalls, setQueryResponseTime } from "./prometheus";
import appConfig from "../../shared/resources/appConfig";
import promEntities from '../resources/prometheusEntities';

const authenticationType = appConfig.AUTHENTICATION_TYPE;

Expand All @@ -23,14 +24,15 @@ export const onProxyRes = ({ entity }: any) => (proxyReq: any, req: any, res: Re
export const onProxyReq = ({ entity }: any) => (proxyReq: any, req: any, res: Response) => {
const startTime = Date.now();
req.startTime = startTime;
if(authenticationType === 'keycloak'){
const keycloakToken = JSON.parse(req?.session['keycloak-token']);
const access_token: string = keycloakToken.access_token;
proxyReq.setHeader('x-user-token', `${access_token}`);
}else if(authenticationType === 'basic'){
const jwtToken: string = req.session?.token;
proxyReq.setHeader('x-user-token', `${jwtToken}`);

if (entity !== promEntities.alerts) {
if(authenticationType === 'keycloak'){
const keycloakToken = JSON.parse(req?.session['keycloak-token']);
const access_token: string = keycloakToken.access_token;
proxyReq.setHeader('Authorization', `Bearer ${access_token}`);
}else if(authenticationType === 'basic'){
const jwtToken: string = req.session?.token;
proxyReq.setHeader('Authorization', `Bearer ${jwtToken}`);
}
}
incrementApiCalls({ entity, endpoint: req.url });
}
2 changes: 1 addition & 1 deletion src/main/middlewares/passportAuthenticate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const private_key: string = appConfig.USER_TOKEN_PRIVATE_KEY;
const generateToken = (user: User) => {
const payload = _.pick(user, ['id', 'user_name', 'email_address', 'roles']);
return new Promise((resolve, reject) => {
jwt.sign(payload, private_key, { algorithm: 'RS512' }, (err, token) => {
jwt.sign(payload, private_key, { algorithm: 'RS256' }, (err, token) => {
if (err) {
return reject(err);
}
Expand Down
1 change: 0 additions & 1 deletion web-console-v2/src/services/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ const checkForSessionExpiry = (config: any) => {
if (getSystemSetting("AUTHENTICATION_TYPE") !== 'basic') {
window.location.href = '/console/logout';
} else {
// alert('Unauthorized access !!');
navigate(`/login`);
}
}
Expand Down

0 comments on commit 183803e

Please sign in to comment.