Skip to content

Commit

Permalink
Merge pull request #83 from bwerquin/v2-develop
Browse files Browse the repository at this point in the history
remove keycloak conf reading
  • Loading branch information
NicoLaval authored Oct 21, 2021
2 parents 8dd4ce7 + e63747e commit b5f5c5e
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 120 deletions.
15 changes: 0 additions & 15 deletions configuration/build-oidc.json

This file was deleted.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "stromae",
"version": "2.1.15",
"version": "2.1.16",
"private": true,
"dependencies": {
"@axa-fr/react-oidc-context": "^3.1.6",
Expand Down
64 changes: 7 additions & 57 deletions src/components/auth/provider/oidc.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,7 @@ import {
InMemoryWebStorage,
} from '@axa-fr/react-oidc-context';
import { LoaderLogo } from 'components/shared/loader';
import {
buildOidcConfiguration,
buildOidcConfigurationFromKeycloak,
buildOidcConfigurationFromBuildConfig,
buildOidcConfigurationFromKeycloakWithOidc,
} from 'utils/oidc/build-configuration';
import { buildOidcConfiguration } from 'utils/oidc/build-configuration';
import { errorDictionary } from 'i18n';
import { ErrorFallback } from 'components/shared/error';

Expand All @@ -21,63 +16,18 @@ const AuthProviderOIDC = ({ children }) => {
const [error, setError] = useState(null);

useEffect(() => {
fetch(`${window.location.origin}/keycloak.json`)
fetch(`${window.location.origin}/oidc.json`)
.then(r => r.json())
.then(r => {
fetch(`${window.location.origin}/build-oidc.json`)
.then(r2 => r2.json())
.then(r2 => {
setOidcConf(
buildOidcConfigurationFromKeycloakWithOidc({
keycloakConf: r,
oidcConf: r2,
conf: conf,
})
);
setOidcConf(
buildOidcConfiguration({
oidcConf: r.config,
conf: conf,
})
.catch(() => {
setOidcConf(
buildOidcConfigurationFromKeycloak({
keycloakConf: r,
conf: conf,
})
);
});
);
setLoading(false);
})
.catch(() => {
fetch(`${window.location.origin}/build-oidc.json`)
.then(r => r.json())
.then(r => {
setOidcConf(
buildOidcConfigurationFromBuildConfig({
oidcConf: r.config,
conf: conf,
})
);
setLoading(false);
})
.catch(() => {
setLoading(false);
setError(new Error(errorDictionary.noAuthFile));
});
fetch(`${window.location.origin}/oidc.json`)
.then(r => r.json())
.then(r => {
setOidcConf(
buildOidcConfiguration({
oidcConf: r.config,
conf: conf,
})
);
setLoading(false);
})
.catch(() => {
setLoading(false);
setError(new Error(errorDictionary.noAuthFile));
});
})
.catch(e => {
setLoading(false);
setError(new Error(errorDictionary.noAuthFile));
});
Expand Down
47 changes: 0 additions & 47 deletions src/utils/oidc/build-configuration.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,54 +29,7 @@ export const buildOidcConfiguration = ({ oidcConf, conf }) => {
response_type: 'code',
post_logout_redirect_uri: `${portail}/${getCurrentSurvey(pathname)}`,
silent_redirect_uri: `${origin}/authentication/silent_callback`,
};
return config;
};

export const buildOidcConfigurationFromKeycloak = ({ keycloakConf, conf }) => {
const { origin, pathname } = window.location;
const { portail } = conf;
const { realm, 'auth-server-url': authServer, resource } = keycloakConf;
return {
authority: `${authServer}/realms/${realm}`,
client_id: resource,
redirect_uri: `${origin}/authentication/callback`,
response_type: 'code',
post_logout_redirect_uri: `${portail}/${getCurrentSurvey(pathname)}`,
scope: 'openid profile email',
silent_redirect_uri: `${origin}/authentication/silent_callback`,
extraQueryParams: `${getKc_idp_hintActive(pathname)}`,
automaticSilentRenew: true,
loadUserInfo: true,
};
};

export const buildOidcConfigurationFromBuildConfig = ({ oidcConf, conf }) => {
const config = {
...oidcConf,
client_id: conf.client_id,
};
return config;
};

export const buildOidcConfigurationFromKeycloakWithOidc = ({
keycloakConf,
conf,
oidcConf,
}) => {
const { origin, pathname } = window.location;
const { portail } = conf;
const { realm, 'auth-server-url': authServer } = keycloakConf;
return {
authority: `${authServer}/realms/${realm}`,
client_id: oidcConf.client_id,
redirect_uri: `${origin}/authentication/callback`,
response_type: 'code',
post_logout_redirect_uri: `${portail}/${getCurrentSurvey(pathname)}`,
scope: 'openid profile email',
silent_redirect_uri: `${origin}/authentication/silent_callback`,
extraQueryParams: `${getKc_idp_hintActive(pathname)}`,
automaticSilentRenew: true,
loadUserInfo: true,
};
};

0 comments on commit b5f5c5e

Please sign in to comment.