Skip to content

Commit f5be867

Browse files
authored
feat: Fix secure development of companion (#3783)
* add workarounds to improve secure development * add gitignore * fix credentials * improve code * use require instead of import * fix lint * another attempt * fix reading * revert changes
1 parent cb0a5db commit f5be867

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

backend/companion/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
credentials.json

backend/companion/getKcpToken.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
export async function getKcpToken() {
22
const tokenUrl = 'https://kymatest.accounts400.ondemand.com/oauth2/token';
33
const grantType = 'client_credentials';
4-
const clientId = process.env.COMPANION_KCP_AUTH_CLIENT_ID;
5-
const clientSecret = process.env.COMPANION_KCP_AUTH_CLIENT_SECRET;
4+
const clientId =
5+
process.env.COMPANION_KCP_AUTH_CLIENT_SECRET ??
6+
getLocalCredentials()?.clientId;
7+
const clientSecret =
8+
process.env.COMPANION_KCP_AUTH_CLIENT_ID ??
9+
getLocalCredentials()?.clientSecret;
610

711
if (!clientId) {
812
throw new Error('COMPANION_KCP_AUTH_CLIENT_ID is not set');
@@ -40,3 +44,8 @@ export async function getKcpToken() {
4044
throw new Error(`Failed to fetch token: ${error.message}`);
4145
}
4246
}
47+
48+
function getLocalCredentials() {
49+
const fs = require('fs');
50+
return JSON.parse(fs.readFileSync('companion/credentials.json', 'utf8'));
51+
}

src/hooks/useCheckSAPUser.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ import { AuthDataState, authDataState } from 'state/authDataAtom';
44

55
export function useCheckSAPUser() {
66
const authData: AuthDataState = useRecoilValue(authDataState);
7+
if (window.location.host.includes('localhost')) {
8+
return true;
9+
}
710
try {
811
if (authData && 'token' in authData) {
912
const decoded = jwtDecode(authData?.token);

0 commit comments

Comments
 (0)