diff --git a/.vscode/launch.json b/.vscode/launch.json index 96242b0..3f9be17 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -13,6 +13,13 @@ ], "program": "${workspaceFolder}/server/app.js", "cwd":"${workspaceFolder}/server/" - } + }, + { + "type": "msedge", + "request": "launch", + "name": "Debug frontend", + "url": "http://localhost:5173", + "webRoot": "${workspaceFolder}/client/" + } ] } \ No newline at end of file diff --git a/client/src/constants.tsx b/client/src/constants.tsx index 15f9199..8644aad 100644 --- a/client/src/constants.tsx +++ b/client/src/constants.tsx @@ -1,7 +1,9 @@ // constants.tsx const ENV_VARIABLES = { MODE: 'production', - VITE_BACKEND_URL: process.env.VITE_BACKEND_URL || "" + VITE_BACKEND_URL: process.env.VITE_BACKEND_URL || "", + BACKEND_URL: process.env.SITE_URL != undefined ? `${process.env.SITE_URL}${process.env.USE_PORTS ? `:${process.env.BACKEND_PORT}`:''}` : process.env.VITE_BACKEND_URL || '', + FRONTEND_URL: process.env.SITE_URL != undefined ? `${process.env.SITE_URL}${process.env.USE_PORTS ? `:${process.env.PORT}`:''}` : '' }; export { ENV_VARIABLES }; diff --git a/client/src/pages/AuthManager/providers/OAuth-Oidc/ButtonAuth.tsx b/client/src/pages/AuthManager/providers/OAuth-Oidc/ButtonAuth.tsx index 8c3fe57..c8f4efc 100644 --- a/client/src/pages/AuthManager/providers/OAuth-Oidc/ButtonAuth.tsx +++ b/client/src/pages/AuthManager/providers/OAuth-Oidc/ButtonAuth.tsx @@ -1,4 +1,5 @@ import React from 'react'; +import { ENV_VARIABLES } from '../../../../constants'; import '../css/buttonAuth.css'; interface ButtonAuthContainerProps { @@ -7,7 +8,7 @@ interface ButtonAuthContainerProps { } const handleAuthLogin = (provider: string) => { - window.location.href = `/api/auth/` + provider; + window.location.href = `${ENV_VARIABLES.BACKEND_URL}/api/auth/${provider}`; }; const ButtonAuth: React.FC = ({ providerName, providerType }) => { diff --git a/server/auth/modules/passport-providers/oauth.js b/server/auth/modules/passport-providers/oauth.js index 188d8a6..fe76922 100644 --- a/server/auth/modules/passport-providers/oauth.js +++ b/server/auth/modules/passport-providers/oauth.js @@ -13,6 +13,7 @@ class PassportOAuth { register(app, passport, endpoint, name, provider) { const cb_url = `${process.env['BACKEND_URL']}${endpoint}/${name}/callback` const self = this + const scope = 'openid profile email offline_access' + ` ${provider.OAUTH_ADD_SCOPE}`; passport.use(name, new OAuth2Strategy({ authorizationURL: provider.OAUTH_AUTHORIZATION_URL, @@ -76,7 +77,7 @@ class PassportOAuth { app.get(`${endpoint}/${name}`, (req, res, next) => { passport.authenticate(name, { - scope: 'openid profile email offline_access' + ` ${provider.OAUTH_ADD_SCOPE}`, + scope: scope, prompt: 'consent' })(req, res, next); }); @@ -93,6 +94,7 @@ class PassportOAuth { } } ); + console.info(`Ajout de la connexion : ${name}(OAuth)`) } } diff --git a/server/auth/modules/passport-providers/oidc.js b/server/auth/modules/passport-providers/oidc.js index 019ccac..77a557c 100644 --- a/server/auth/modules/passport-providers/oidc.js +++ b/server/auth/modules/passport-providers/oidc.js @@ -24,6 +24,7 @@ class PassportOpenIDConnect { const config = await this.getConfigFromConfigURL(name, provider) const cb_url = `${process.env['BACKEND_URL']}${endpoint}/${name}/callback` const self = this + const scope = 'openid profile email ' + `${provider.OIDC_ADD_SCOPE}` passport.use(name, new OpenIDConnectStrategy({ issuer: config.issuer, @@ -34,7 +35,7 @@ class PassportOpenIDConnect { clientSecret: provider.OIDC_CLIENT_SECRET, callbackURL: cb_url, passReqToCallback: true, - scope: 'openid profile email ' + `${provider.OIDC_ADD_SCOPE}`, + scope: scope, }, // patch pour la librairie permet d'obtenir les groupes, PR en cours mais "morte" : https://github.com/jaredhanson/passport-openidconnect/pull/101 async function (req, issuer, profile, times, tok, done) { @@ -78,7 +79,7 @@ class PassportOpenIDConnect { app.get(`${endpoint}/${name}`, (req, res, next) => { passport.authenticate(name, { - scope: 'openid profile email offline_access' + ` ${provider.OAUTH_ADD_SCOPE}`, + scope: scope, prompt: 'consent' })(req, res, next); }); @@ -95,6 +96,7 @@ class PassportOpenIDConnect { } } ); + console.info(`Ajout de la connexion : ${name}(OIDC)`) } }