diff --git a/docker/init_react_envs.sh b/docker/init_react_envs.sh index bbcbc45..f6c05b1 100644 --- a/docker/init_react_envs.sh +++ b/docker/init_react_envs.sh @@ -44,6 +44,8 @@ fi export AUTH_AUTHORITY=${AUTH_AUTHORITY:-https://$AUTH0_DOMAIN} export AUTH_CLIENT_ID=${AUTH_CLIENT_ID:-$AUTH0_CLIENT_ID} export AUTH_AUDIENCE=${AUTH_AUDIENCE:-$AUTH0_AUDIENCE} +export AUTH_REDIRECT_URI=${AUTH_REDIRECT_URI} +export AUTH_SILENT_REDIRECT_URI=${AUTH_SILENT_REDIRECT_URI} export USE_AUTH0=${USE_AUTH0:-true} export AUTH_SUPPORTED_SCOPES=${AUTH_SUPPORTED_SCOPES:-openid profile email api offline_access email_verified} @@ -57,7 +59,8 @@ export NETBIRD_LATEST_VERSION=$(basename $(curl -fs -o/dev/null -w %{redirect_ur echo "NetBird latest version: ${NETBIRD_LATEST_VERSION}" # replace ENVs in the config -ENV_STR="\$\$USE_AUTH0 \$\$AUTH_AUDIENCE \$\$AUTH_AUTHORITY \$\$AUTH_CLIENT_ID \$\$AUTH_SUPPORTED_SCOPES \$\$NETBIRD_MGMT_API_ENDPOINT \$\$NETBIRD_MGMT_GRPC_API_ENDPOINT \$\$NETBIRD_LATEST_VERSION \$\$NETBIRD_HOTJAR_TRACK_ID" +ENV_STR="\$\$USE_AUTH0 \$\$AUTH_AUDIENCE \$\$AUTH_AUTHORITY \$\$AUTH_CLIENT_ID \$\$AUTH_SUPPORTED_SCOPES \$\$NETBIRD_MGMT_API_ENDPOINT \$\$NETBIRD_MGMT_GRPC_API_ENDPOINT \$\$NETBIRD_LATEST_VERSION \$\$NETBIRD_HOTJAR_TRACK_ID \$\$AUTH_REDIRECT_URI \$\$AUTH_SILENT_REDIRECT_URI" + MAIN_JS=$(find /usr/share/nginx/html/static/js/main.*js) OIDC_TRUSTED_DOMAINS="/usr/share/nginx/html/OidcTrustedDomains.js" cp "$MAIN_JS" "$MAIN_JS".copy diff --git a/src/config.json b/src/config.json index 98ebc84..8913a0c 100644 --- a/src/config.json +++ b/src/config.json @@ -8,5 +8,7 @@ "apiOrigin": "$NETBIRD_MGMT_API_ENDPOINT", "grpcApiOrigin": "$NETBIRD_MGMT_GRPC_API_ENDPOINT", "latestVersion": "$NETBIRD_LATEST_VERSION", - "hotjarTrackID": "$NETBIRD_HOTJAR_TRACK_ID" + "hotjarTrackID": "$NETBIRD_HOTJAR_TRACK_ID", + "redirectURI": "$AUTH_REDIRECT_URI", + "silentRedirectURI": "$AUTH_SILENT_REDIRECT_URI" } \ No newline at end of file diff --git a/src/config.ts b/src/config.ts index 2de5bea..1c08168 100644 --- a/src/config.ts +++ b/src/config.ts @@ -7,7 +7,19 @@ if (process.env.NODE_ENV !== 'production') { configJson = require("./config.json"); } +const defaultRedirectURI = '/#callback'; +const defaultSilentRedirectURI = '/#silent-callback' + export function getConfig() { + let redirectURI = defaultRedirectURI + if (configJson.redirectURI) { + redirectURI = configJson.redirectURI + } + + let silentRedirectURI = defaultSilentRedirectURI + if (configJson.silentRedirectURI) { + silentRedirectURI = configJson.silentRedirectURI + } return { auth0Auth: configJson.auth0Auth == "true", //due to substitution we can't use boolean in the config @@ -19,5 +31,7 @@ export function getConfig() { latestVersion: configJson.latestVersion, audience: configJson.authAudience, hotjarTrackID: configJson.hotjarTrackID, + redirectURI: redirectURI, + silentRedirectURI: silentRedirectURI, }; } diff --git a/src/index.tsx b/src/index.tsx index 3457d76..f19eafc 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -26,9 +26,9 @@ const auth0AuthorityConfig: AuthorityConfiguration = { const providerConfig = { authority: config.authority, client_id: config.clientId, - redirect_uri: window.location.origin + '/#callback', + redirect_uri: window.location.origin + config.redirectURI, refresh_time_before_tokens_expiration_in_second: 30, - silent_redirect_uri: window.location.origin + '/#silent-callback', + silent_redirect_uri: window.location.origin + config.silentRedirectURI, scope: config.scopesSupported, // disabling service worker // service_worker_relative_url:'/OidcServiceWorker.js',