Use correct environment variables in Account Console v3 (#19934)

This commit is contained in:
Jon Koops 2023-04-25 13:11:20 +02:00 committed by GitHub
parent e21fc968e2
commit 48354a1bb8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 19 additions and 30 deletions

View file

@ -77,10 +77,10 @@
<![CDATA[ <![CDATA[
<script id="environment" type="application/json"> <script id="environment" type="application/json">
{ {
"loginRealm": "${loginRealm!"master"}", "authUrl": "${authUrl}",
"authServerUrl": "${authUrl}", "isRunningAsTheme": true,
"resourceUrl": "${resourceUrl}", "realm": "${realm.name}",
"isRunningAsTheme": true "resourceUrl": "${resourceUrl}"
} }
</script> </script>
</body> </body>

View file

@ -67,9 +67,9 @@ function checkResponse<T>(response: T) {
async function get(path: string, params: RequestInit): Promise<Response> { async function get(path: string, params: RequestInit): Promise<Response> {
const url = joinPath( const url = joinPath(
environment.authServerUrl, environment.authUrl,
"realms", "realms",
environment.loginRealm, environment.realm,
"account", "account",
path path
); );

View file

@ -103,12 +103,7 @@ export async function unLinkAccount(account: LinkedAccountRepresentation) {
export async function linkAccount(account: LinkedAccountRepresentation) { export async function linkAccount(account: LinkedAccountRepresentation) {
const redirectUri = encodeURIComponent( const redirectUri = encodeURIComponent(
joinPath( joinPath(environment.authUrl, "realms", environment.realm, "account")
environment.authServerUrl,
"realms",
environment.loginRealm,
"account"
)
); );
const response = await request("/linked-accounts/" + account.providerName, { const response = await request("/linked-accounts/" + account.providerName, {
searchParams: { providerId: account.providerName, redirectUri }, searchParams: { providerId: account.providerName, redirectUri },

View file

@ -15,13 +15,7 @@ export async function request(
{ signal, method, searchParams, body }: RequestOptions = {} { signal, method, searchParams, body }: RequestOptions = {}
): Promise<Response> { ): Promise<Response> {
const url = new URL( const url = new URL(
joinPath( joinPath(environment.authUrl, "realms", environment.realm, "account", path)
environment.authServerUrl,
"realms",
environment.loginRealm,
"account",
path
)
); );
if (searchParams) { if (searchParams) {

View file

@ -1,20 +1,20 @@
export type Environment = { export type Environment = {
/** The realm which should be used when signing into the application. */
loginRealm: string;
/** The URL to the root of the auth server. */ /** The URL to the root of the auth server. */
authServerUrl: string; authUrl: string;
/** The URL to resources such as the files in the `public` directory. */
resourceUrl: string;
/** Indicates if the application is running as a Keycloak theme. */ /** Indicates if the application is running as a Keycloak theme. */
isRunningAsTheme: boolean; isRunningAsTheme: boolean;
/** The realm used to sign into. */
realm: string;
/** The URL to resources such as the files in the `public` directory. */
resourceUrl: string;
}; };
// The default environment, used during development. // The default environment, used during development.
const defaultEnvironment: Environment = { const defaultEnvironment: Environment = {
loginRealm: "master", authUrl: "http://localhost:8180",
authServerUrl: "http://localhost:8180",
resourceUrl: "http://localhost:8080",
isRunningAsTheme: false, isRunningAsTheme: false,
realm: "master",
resourceUrl: "http://localhost:8080",
}; };
// Merge the default and injected environment variables together. // Merge the default and injected environment variables together.

View file

@ -2,8 +2,8 @@ import Keycloak from "keycloak-js";
import { environment } from "./environment"; import { environment } from "./environment";
export const keycloak = new Keycloak({ export const keycloak = new Keycloak({
url: environment.authServerUrl, url: environment.authUrl,
realm: environment.loginRealm, realm: environment.realm,
clientId: environment.isRunningAsTheme clientId: environment.isRunningAsTheme
? "account-console" ? "account-console"
: "security-admin-console-v2", : "security-admin-console-v2",

View file

@ -26,7 +26,7 @@ async function startServer() {
[ [
"start-dev", "start-dev",
"--http-port=8180", "--http-port=8180",
"--features=admin2,admin-fine-grained-authz,declarative-user-profile", "--features=account3,admin-fine-grained-authz,declarative-user-profile",
...args, ...args,
], ],
{ {