Adds debuging informations + fixes url

This commit is contained in:
Gabriel Matte 2024-10-22 13:04:29 -04:00
parent ccce303693
commit ba270db019
5 changed files with 20 additions and 6 deletions

7
.vscode/launch.json vendored
View file

@ -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/"
}
]
}

View file

@ -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 };

View file

@ -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<ButtonAuthContainerProps> = ({ providerName, providerType }) => {

View file

@ -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)`)
}
}

View file

@ -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)`)
}
}