Skip to content

Commit a3ae2dc

Browse files
GMishxheliocastro
authored andcommitted
fix(env)!: Make oauth vars server side only
!BREAKING: Update the variables `NEXT_PUBLIC_SW360_REST_CLIENT_ID` and `NEXT_PUBLIC_SW360_REST_CLIENT_SECRET` to server side variables only. This would require updating existing `.env` files. Signed-off-by: Gaurav Mishra <mishra.gaurav@siemens.com>
1 parent d8d27c2 commit a3ae2dc

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

src/app/api/auth/[...nextauth]/keycloakAuthOption.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,12 @@ import KeycloakProvider from "next-auth/providers/keycloak"
1111
import { NextAuthOptions } from 'next-auth'
1212
import { jwtDecode } from 'jwt-decode'
1313
import { UserGroupType } from '@/object-types'
14+
import { SW360_KEYCLOAK_CLIENT_ID, SW360_KEYCLOAK_CLIENT_SECRET, AUTH_ISSUER } from '@/utils/env'
1415

1516
const keycloakProvider = KeycloakProvider({
16-
clientId: `${process.env.SW360_KEYCLOAK_CLIENT_ID}`,
17-
clientSecret: `${process.env.SW360_KEYCLOAK_CLIENT_SECRET}`,
18-
issuer: `${process.env.AUTH_ISSUER}`,
17+
clientId: SW360_KEYCLOAK_CLIENT_ID,
18+
clientSecret: SW360_KEYCLOAK_CLIENT_SECRET,
19+
issuer: AUTH_ISSUER,
1920
checks: 'state',
2021
authorization: { params: { scope: "openid READ WRITE" } },
2122
})
@@ -79,4 +80,4 @@ function getUserGroup(tokenDetails: { userGroup?: string[] }): UserGroupType[] {
7980
}) : [UserGroupType.USER];
8081
}
8182

82-
export default keycloakAuthOption;
83+
export default keycloakAuthOption;

src/utils/env.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,13 @@
99
// SPDX-License-Identifier: EPL-2.0
1010
// License-Filename: LICENSE
1111

12-
export const SW360_API_URL: string | undefined = process.env.NEXT_PUBLIC_SW360_API_URL;
13-
export const AUTH_TOKEN : string | undefined = process.env.NEXT_PUBLIC_AUTH_TOKEN;
14-
export const SW360_REST_CLIENT_ID: string | undefined = process.env.NEXT_PUBLIC_SW360_REST_CLIENT_ID;
15-
export const SW360_REST_CLIENT_SECRET: string | undefined = process.env.NEXT_PUBLIC_SW360_REST_CLIENT_SECRET;
12+
// Server/Client side env
13+
export const SW360_API_URL: string | undefined = process.env.NEXT_PUBLIC_SW360_API_URL;
1614
export const AUTH_PROVIDER: string | undefined = process.env.NEXT_PUBLIC_SW360_AUTH_PROVIDER;
15+
16+
// Server side env
17+
export const SW360_REST_CLIENT_ID: string | undefined = process.env.SW360_REST_CLIENT_ID;
18+
export const SW360_REST_CLIENT_SECRET: string | undefined = process.env.SW360_REST_CLIENT_SECRET;
19+
export const SW360_KEYCLOAK_CLIENT_ID = `${process.env.SW360_KEYCLOAK_CLIENT_ID}`;
20+
export const SW360_KEYCLOAK_CLIENT_SECRET = `${process.env.SW360_KEYCLOAK_CLIENT_SECRET}`;
21+
export const AUTH_ISSUER: string | undefined = process.env.AUTH_ISSUER;

0 commit comments

Comments
 (0)