Skip to content

Commit 079953b

Browse files
fix: fix pwa public environment variables
1 parent 26c840d commit 079953b

File tree

9 files changed

+31
-31
lines changed

9 files changed

+31
-31
lines changed

compose.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,12 @@ services:
3636
image: ${IMAGES_PREFIX:-}app-pwa
3737
environment:
3838
NEXT_PUBLIC_ENTRYPOINT: http://php
39+
NEXT_PUBLIC_OIDC_CLIENT_ID: ${OIDC_CLIENT_ID:-api-platform-pwa}
40+
NEXT_PUBLIC_OIDC_SERVER_URL: ${OIDC_SERVER_URL:-https://localhost/oidc/realms/demo}
41+
NEXT_PUBLIC_OIDC_SERVER_URL_INTERNAL: ${OIDC_SERVER_URL_INTERNAL:-http://keycloak:8080/oidc/realms/demo}
42+
NEXT_PUBLIC_OIDC_AUTHORIZATION_CLIENT_ID: ${OIDC_AUTHORIZATION_CLIENT_ID:-api-platform-api}
3943
AUTH_SECRET: ${AUTH_SECRET:-!ChangeThisNextAuthSecret!}
4044
AUTH_URL: ${AUTH_URL:-https://localhost/api/auth}
41-
OIDC_CLIENT_ID: ${OIDC_CLIENT_ID:-api-platform-pwa}
42-
OIDC_SERVER_URL: ${OIDC_SERVER_URL:-https://localhost/oidc/realms/demo}
43-
OIDC_SERVER_URL_INTERNAL: ${OIDC_SERVER_URL_INTERNAL:-http://keycloak:8080/oidc/realms/demo}
44-
OIDC_AUTHORIZATION_CLIENT_ID: ${OIDC_AUTHORIZATION_CLIENT_ID:-api-platform-api}
4545
NEXT_SHARP_PATH: /srv/app/node_modules/sharp
4646

4747
###> doctrine/doctrine-bundle ###

helm/api-platform/templates/pwa-deployment.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,22 +46,22 @@ spec:
4646
secretKeyRef:
4747
name: {{ include "api-platform.fullname" . }}
4848
key: next-auth-secret
49-
- name: OIDC_SERVER_URL
49+
- name: NEXT_PUBLIC_OIDC_SERVER_URL
5050
valueFrom:
5151
configMapKeyRef:
5252
name: {{ include "api-platform.fullname" . }}
5353
key: oidc-server-url
54-
- name: OIDC_SERVER_URL_INTERNAL
54+
- name: NEXT_PUBLIC_OIDC_SERVER_URL_INTERNAL
5555
valueFrom:
5656
configMapKeyRef:
5757
name: {{ include "api-platform.fullname" . }}
5858
key: oidc-server-url-internal
59-
- name: OIDC_CLIENT_ID
59+
- name: NEXT_PUBLIC_OIDC_CLIENT_ID
6060
valueFrom:
6161
configMapKeyRef:
6262
name: {{ include "api-platform.fullname" . }}
6363
key: pwa-client-id
64-
- name: OIDC_AUTHORIZATION_CLIENT_ID
64+
- name: NEXT_PUBLIC_OIDC_AUTHORIZATION_CLIENT_ID
6565
valueFrom:
6666
configMapKeyRef:
6767
name: {{ include "api-platform.fullname" . }}

pwa/app/auth.tsx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { type TokenSet } from "@auth/core/types";
22
import NextAuth, { type Session as DefaultSession, type User } from "next-auth";
33
import KeycloakProvider from "next-auth/providers/keycloak";
44

5-
import { OIDC_CLIENT_ID, OIDC_SERVER_URL, OIDC_SERVER_URL_INTERNAL } from "../config/keycloak";
5+
import { NEXT_PUBLIC_OIDC_CLIENT_ID, NEXT_PUBLIC_OIDC_SERVER_URL, NEXT_PUBLIC_OIDC_SERVER_URL_INTERNAL } from "../config/keycloak";
66

77
export interface Session extends DefaultSession {
88
error?: "RefreshAccessTokenError"
@@ -45,10 +45,10 @@ export const { handlers: { GET, POST }, auth } = NextAuth({
4545
} else {
4646
// If the access token has expired, try to refresh it
4747
try {
48-
const response = await fetch(`${OIDC_SERVER_URL_INTERNAL}/protocol/openid-connect/token`, {
48+
const response = await fetch(`${NEXT_PUBLIC_OIDC_SERVER_URL_INTERNAL}/protocol/openid-connect/token`, {
4949
headers: { "Content-Type": "application/x-www-form-urlencoded" },
5050
body: new URLSearchParams({
51-
client_id: OIDC_CLIENT_ID,
51+
client_id: NEXT_PUBLIC_OIDC_CLIENT_ID,
5252
grant_type: "refresh_token",
5353
refresh_token: token.refreshToken,
5454
}),
@@ -96,8 +96,8 @@ export const { handlers: { GET, POST }, auth } = NextAuth({
9696
providers: [
9797
KeycloakProvider({
9898
id: 'keycloak',
99-
clientId: OIDC_CLIENT_ID,
100-
issuer: OIDC_SERVER_URL,
99+
clientId: NEXT_PUBLIC_OIDC_CLIENT_ID,
100+
issuer: NEXT_PUBLIC_OIDC_SERVER_URL,
101101

102102
// user information will be extracted from the `id_token` claims, instead of making a request to the `userinfo` endpoint
103103
// https://next-auth.js.org/configuration/providers/oauth
@@ -113,10 +113,10 @@ export const { handlers: { GET, POST }, auth } = NextAuth({
113113
// would love to use discovery, but can't because since next-auth:v5 token endpoint is called internally
114114
// also, discovery doesn't seem to work properly: https://github.com/nextauthjs/next-auth/pull/9718
115115
// wellKnown: `${OIDC_SERVER_URL}/.well-known/openid-configuration`,
116-
token: `${OIDC_SERVER_URL_INTERNAL}/protocol/openid-connect/token`,
117-
userinfo: `${OIDC_SERVER_URL}/protocol/openid-connect/token`,
116+
token: `${NEXT_PUBLIC_OIDC_SERVER_URL_INTERNAL}/protocol/openid-connect/token`,
117+
userinfo: `${NEXT_PUBLIC_OIDC_SERVER_URL}/protocol/openid-connect/token`,
118118
authorization: {
119-
url: `${OIDC_SERVER_URL}/protocol/openid-connect/auth`,
119+
url: `${NEXT_PUBLIC_OIDC_SERVER_URL}/protocol/openid-connect/auth`,
120120
// https://authjs.dev/guides/basics/refresh-token-rotation#jwt-strategy
121121
params: {
122122
access_type: "offline",

pwa/components/admin/AppBar.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import DocContext from "../../components/admin/DocContext";
1010
import HydraLogo from "../../components/admin/HydraLogo";
1111
import OpenApiLogo from "../../components/admin/OpenApiLogo";
1212
import Logo from "../../components/admin/Logo";
13-
import {OIDC_SERVER_URL} from "../../config/keycloak";
13+
import {NEXT_PUBLIC_OIDC_SERVER_URL} from "../../config/keycloak";
1414

1515
const DocTypeMenuButton = () => {
1616
const [anchorEl, setAnchorEl] = useState(null);
@@ -75,7 +75,7 @@ const Logout = forwardRef((props, ref: ForwardedRef<any>) => {
7575

7676
const handleClick = () => signOut({
7777
// @ts-ignore
78-
callbackUrl: `${OIDC_SERVER_URL}/protocol/openid-connect/logout?id_token_hint=${session.idToken}&post_logout_redirect_uri=${window.location.origin}`,
78+
callbackUrl: `${NEXT_PUBLIC_OIDC_SERVER_URL}/protocol/openid-connect/logout?id_token_hint=${session.idToken}&post_logout_redirect_uri=${window.location.origin}`,
7979
});
8080

8181
return (

pwa/components/admin/authProvider.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { AuthProvider } from "react-admin";
22
import { signIn, signOut, useSession } from "next-auth/react";
33

4-
import { OIDC_SERVER_URL } from "../../config/keycloak";
4+
import { NEXT_PUBLIC_OIDC_SERVER_URL } from "../../config/keycloak";
55

66
const authProvider: AuthProvider = {
77
// Nothing to do here, this function will never be called
@@ -15,7 +15,7 @@ const authProvider: AuthProvider = {
1515

1616
await signOut({
1717
// @ts-ignore
18-
callbackUrl: `${OIDC_SERVER_URL}/protocol/openid-connect/logout?id_token_hint=${session.idToken}&post_logout_redirect_uri=${window.location.origin}`,
18+
callbackUrl: `${NEXT_PUBLIC_OIDC_SERVER_URL}/protocol/openid-connect/logout?id_token_hint=${session.idToken}&post_logout_redirect_uri=${window.location.origin}`,
1919
});
2020
},
2121
checkError: async (error) => {

pwa/components/common/Header.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import Link from "next/link";
66
import PersonOutlineIcon from "@mui/icons-material/PersonOutline";
77
import FavoriteBorderIcon from "@mui/icons-material/FavoriteBorder";
88

9-
import { OIDC_SERVER_URL } from "../../config/keycloak";
9+
import { NEXT_PUBLIC_OIDC_SERVER_URL } from "../../config/keycloak";
1010

1111
export const Header = () => {
1212
const pathname = usePathname();
@@ -33,7 +33,7 @@ export const Header = () => {
3333
e.preventDefault();
3434
signOut({
3535
// @ts-ignore
36-
callbackUrl: `${OIDC_SERVER_URL}/protocol/openid-connect/logout?id_token_hint=${session.idToken}&post_logout_redirect_uri=${window.location.origin}/books`,
36+
callbackUrl: `${NEXT_PUBLIC_OIDC_SERVER_URL}/protocol/openid-connect/logout?id_token_hint=${session.idToken}&post_logout_redirect_uri=${window.location.origin}/books`,
3737
});
3838
}}>
3939
Sign out

pwa/components/review/Item.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export const Item: FunctionComponent<Props> = ({ review, onDelete, onEdit }) =>
5757
)}
5858
<div key={data["@id"]} className="mb-5 flex" data-testid="review">
5959
<div className="font-semibold text-gray-600 text-xl w-[50px] h-[50px] px-3 py-1 mr-3 rounded-full bg-gray-200 flex items-center justify-center">
60-
{data["user"]["name"].substring(0, 1)}
60+
{data.user?.name?.substring(0, 1) ?? "John Doe"}
6161
</div>
6262
<div className="w-full">
6363
{edit && (
@@ -74,7 +74,7 @@ export const Item: FunctionComponent<Props> = ({ review, onDelete, onEdit }) =>
7474
) || (
7575
<>
7676
<p>
77-
<span className="text-lg font-semibold">{data["user"]["name"]}</span>
77+
<span className="text-lg font-semibold">{data.user?.name ?? "John Doe"}</span>
7878
<span className="text-xs text-gray-400 ml-3">
7979
<span className="mr-2"></span>
8080
{new Date(data["publishedAt"]).toLocaleDateString()}

pwa/config/keycloak.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export const OIDC_CLIENT_ID: string = process.env.OIDC_CLIENT_ID || 'api-platform-pwa';
2-
export const OIDC_SERVER_URL: string = process.env.OIDC_SERVER_URL || 'https://localhost/oidc/realms/demo';
3-
export const OIDC_SERVER_URL_INTERNAL: string = process.env.OIDC_SERVER_URL_INTERNAL || 'http://keycloak:8080/oidc/realms/demo';
4-
export const OIDC_AUTHORIZATION_CLIENT_ID: string = process.env.OIDC_AUTHORIZATION_CLIENT_ID || 'api-platform-api';
1+
export const NEXT_PUBLIC_OIDC_CLIENT_ID: string = process.env.NEXT_PUBLIC_OIDC_CLIENT_ID || 'api-platform-pwa';
2+
export const NEXT_PUBLIC_OIDC_SERVER_URL: string = process.env.NEXT_PUBLIC_OIDC_SERVER_URL || 'https://localhost/oidc/realms/demo';
3+
export const NEXT_PUBLIC_OIDC_SERVER_URL_INTERNAL: string = process.env.NEXT_PUBLIC_OIDC_SERVER_URL_INTERNAL || 'http://keycloak:8080/oidc/realms/demo';
4+
export const NEXT_PUBLIC_OIDC_AUTHORIZATION_CLIENT_ID: string = process.env.NEXT_PUBLIC_OIDC_AUTHORIZATION_CLIENT_ID || 'api-platform-api';

pwa/utils/review.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { useEffect, useState } from "react";
22

33
import { type Session } from "../app/auth";
44
import { type Review } from "../types/Review";
5-
import { OIDC_AUTHORIZATION_CLIENT_ID, OIDC_SERVER_URL } from "../config/keycloak";
5+
import { NEXT_PUBLIC_OIDC_AUTHORIZATION_CLIENT_ID, NEXT_PUBLIC_OIDC_SERVER_URL } from "../config/keycloak";
66

77
interface Permission {
88
result: boolean;
@@ -18,14 +18,14 @@ export const usePermission = (review: Review, session: Session|null): boolean =>
1818

1919
(async () => {
2020
try {
21-
const response = await fetch(`${OIDC_SERVER_URL}/protocol/openid-connect/token`, {
21+
const response = await fetch(`${NEXT_PUBLIC_OIDC_SERVER_URL}/protocol/openid-connect/token`, {
2222
headers: {
2323
"Content-Type": "application/x-www-form-urlencoded",
2424
Authorization: `Bearer ${session?.accessToken}`,
2525
},
2626
body: new URLSearchParams({
2727
grant_type: "urn:ietf:params:oauth:grant-type:uma-ticket",
28-
audience: OIDC_AUTHORIZATION_CLIENT_ID,
28+
audience: NEXT_PUBLIC_OIDC_AUTHORIZATION_CLIENT_ID,
2929
response_mode: "decision",
3030
permission_resource_format: "uri",
3131
permission_resource_matching_uri: "true",

0 commit comments

Comments
 (0)