Skip to content
Commits on Source (2)
  • Reiter, Christoph's avatar
    api-docs: extract the keycloak settings from the generic oidc config · 1569747b
    Reiter, Christoph authored
    In the future we plan to replace the keycloak specific web component used
    in the API docs with a generic OIDC one. For this the auth bundle has now
    started to set new global twig variables containing OIDC config and the keycloak
    variabels are now deprecated.
    
    In case we find the keycloak variables we will still use them, but if not
    we will extract them from the OIDC url. This depends on the URL containing
    a "/realms/" path element.
    
    Once we move away from keycloak in the core we can remove this hack.
    1569747b
  • Reiter, Christoph's avatar
    release · 05266632
    Reiter, Christoph authored
    05266632
# v0.1.59
* api-docs: compatibility fixes for relay-auth-bundle v0.1.12
# v0.1.52
* new Locale service for setting a locale from a requests and forwarding
......
......@@ -26,7 +26,7 @@
<script id="swagger-data" type="application/json">{{ swagger_data|merge(oauth_data)|json_encode(65)|raw }}</script>
{# insert auth web component, use token in Swagger UI #}
{% if keycloak_server_url and keycloak_realm and keycloak_frontend_client_id %}
{% if (keycloak_server_url or oidc_server_url) and (keycloak_realm or oidc_server_url) and (keycloak_frontend_client_id or oidc_frontend_client_id) %}
<style>
/* Hide the builtin auth key button in case we have a keycloak setup */
.swagger-ui .auth-wrapper .authorize {
......@@ -34,10 +34,12 @@
}
</style>
<script>
var keycloakConfig = {
url: "{{ keycloak_server_url }}",
realm: "{{ keycloak_realm }}",
clientId: "{{ keycloak_frontend_client_id }}"
var oidcConfig = {
oidcServer: "{{ oidc_server_url }}",
oidcFrontendClientId: "{{ oidc_frontend_client_id }}",
keycloakUrl: "{{ keycloak_server_url }}",
keycloakRealm: "{{ keycloak_realm }}",
keycloakClientId: "{{ keycloak_frontend_client_id }}"
};
</script>
<script type="module" src="{{ asset('bundles/dbprelaycore/index.js', assetPackage) }}"></script>
......
......@@ -36,6 +36,54 @@ function useToken(token) {
var delayInsertTimer = 0;
function getKeycloakServerUrl() {
let config = window.oidcConfig;
if (config.keycloakUrl.length) {
// deprecated config value, remove once removed in the auth/oidc bundle
return config.keycloakUrl;
} else if (config.oidcServer.length) {
let url = config.oidcServer;
// XXX: extract the base url from the server url, hacky put works..
// In the future we might want to use a non-keycloak specific component here,
// and fetch .well-known/openid-configuration
let match = url.match(/(?<base>.*)\/realms\/(?<realm>[^/]*)/);
if (match !== null) {
return match.groups.base;
}
}
return '';
}
function getKeycloakRealm()
{
let config = window.oidcConfig;
if (config.keycloakRealm.length) {
// deprecated config value, remove once removed in the auth/oidc bundle
return config.keycloakRealm;
} else if (config.oidcServer.length) {
let url = config.oidcServer;
// XXX: extract the realm from the server url, hacky put works..
// In the future we might want to use a non-keycloak specific component here,
// and fetch .well-known/openid-configuration
let match = url.match(/(?<base>.*)\/realms\/(?<realm>[^/]*)/);
if (match !== null) {
return match.groups.realm;
}
}
return '';
}
function getKeycloakClientId() {
let config = window.oidcConfig;
if (config.keycloakClientId.length) {
// deprecated config value, remove once removed in the auth/oidc bundle
return config.keycloakClientId;
} else if (config.oidcFrontendClientId.length) {
return config.oidcFrontendClientId;
}
return '';
}
function insertDBPContainer() {
let target = document.getElementsByClassName('scheme-container')[0];
if (target === undefined)
......@@ -43,12 +91,11 @@ function insertDBPContainer() {
// see ../auth/README.md
var element = document.createElement('api-platform-auth');
let config = window.keycloakConfig;
element.setAttribute('lang', 'en');
element.setAttribute('url', config.url);
element.setAttribute('realm', config.realm);
element.setAttribute('client-id', config.clientId);
element.setAttribute('url', getKeycloakServerUrl());
element.setAttribute('realm', getKeycloakRealm());
element.setAttribute('client-id', getKeycloakClientId());
element.setAttribute('silent-check-sso-redirect-uri', new URL("auth/silent-check-sso.html", import.meta.url).href);
element.setAttribute('entry-point-url', new URL('../..', import.meta.url).href);
element.setAttribute('auth', '');
......