mirror of
https://github.com/ets-cfuhrman-pfe/EvalueTonSavoir.git
synced 2025-08-11 21:23:54 -04:00
Merge pull request #126 from MathieuSevignyLavallee/main
Configuration authentification - docker-compose
This commit is contained in:
commit
75ebcff4e0
7 changed files with 207 additions and 0 deletions
83
.github/workflows/create-branch-images.yml
vendored
Normal file
83
.github/workflows/create-branch-images.yml
vendored
Normal file
|
|
@ -0,0 +1,83 @@
|
||||||
|
name: create-branch-images
|
||||||
|
|
||||||
|
on:
|
||||||
|
workflow_call:
|
||||||
|
workflow_dispatch:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- 'main'
|
||||||
|
- 'dev'
|
||||||
|
tags:
|
||||||
|
- '**'
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
docker:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
packages: write
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Set up QEMU
|
||||||
|
uses: docker/setup-qemu-action@v2
|
||||||
|
|
||||||
|
- name: Set up Docker Buildx
|
||||||
|
uses: docker/setup-buildx-action@v2
|
||||||
|
|
||||||
|
- name: Log in to the Container registry
|
||||||
|
uses: docker/login-action@v2
|
||||||
|
with:
|
||||||
|
registry: ghcr.io
|
||||||
|
username: ${{ github.actor }}
|
||||||
|
password: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
||||||
|
- name: Extract metadata (tags, labels) for Docker
|
||||||
|
id: meta
|
||||||
|
uses: docker/metadata-action@v4
|
||||||
|
with:
|
||||||
|
images: |
|
||||||
|
ghcr.io/${{ github.repository }}/frontend
|
||||||
|
ghcr.io/${{ github.repository }}/backend
|
||||||
|
ghcr.io/${{ github.repository }}/router
|
||||||
|
tags: |
|
||||||
|
type=schedule
|
||||||
|
type=ref,event=branch
|
||||||
|
type=ref,event=pr
|
||||||
|
type=semver,pattern={{version}}
|
||||||
|
type=semver,pattern={{major}}.{{minor}}
|
||||||
|
type=semver,pattern={{major}}
|
||||||
|
|
||||||
|
- name: Build and push frontend Docker image
|
||||||
|
uses: docker/build-push-action@v3
|
||||||
|
with:
|
||||||
|
context: ./client
|
||||||
|
push: ${{ github.event_name != 'pull_request' }}
|
||||||
|
platforms: linux/amd64
|
||||||
|
tags: ${{ steps.meta.outputs.tags }}
|
||||||
|
labels: ${{ steps.meta.outputs.labels }}
|
||||||
|
cache-from: type=gha
|
||||||
|
cache-to: type=gha,mode=max
|
||||||
|
|
||||||
|
- name: Build and push backend Docker image
|
||||||
|
uses: docker/build-push-action@v3
|
||||||
|
with:
|
||||||
|
context: ./server
|
||||||
|
push: ${{ github.event_name != 'pull_request' }}
|
||||||
|
platforms: linux/amd64
|
||||||
|
tags: ${{ steps.meta.outputs.tags }}
|
||||||
|
labels: ${{ steps.meta.outputs.labels }}
|
||||||
|
cache-from: type=gha
|
||||||
|
cache-to: type=gha,mode=max
|
||||||
|
|
||||||
|
- name: Build and push router Docker image
|
||||||
|
uses: docker/build-push-action@v3
|
||||||
|
with:
|
||||||
|
context: ./nginx
|
||||||
|
push: ${{ github.event_name != 'pull_request' }}
|
||||||
|
platforms: linux/amd64
|
||||||
|
tags: ${{ steps.meta.outputs.tags }}
|
||||||
|
labels: ${{ steps.meta.outputs.labels }}
|
||||||
|
cache-from: type=gha
|
||||||
|
cache-to: type=gha,mode=max
|
||||||
32
auth_config.json
Normal file
32
auth_config.json
Normal file
|
|
@ -0,0 +1,32 @@
|
||||||
|
{
|
||||||
|
"auth": {
|
||||||
|
"passportjs": [
|
||||||
|
{
|
||||||
|
"provider1": {
|
||||||
|
"OAUTH_AUTHORIZATION_URL": "https://www.testurl.com/oauth2/authorize",
|
||||||
|
"OAUTH_TOKEN_URL": "https://www.testurl.com/oauth2/token",
|
||||||
|
"OAUTH_CLIENT_ID": "your_oauth_client_id",
|
||||||
|
"OAUTH_CLIENT_SECRET": "your_oauth_client_secret",
|
||||||
|
"OAUTH_CALLBACK_URL": "https://localhost:3000/auth/provider/callback",
|
||||||
|
"OAUTH_ADD_SCOPE": "scopes",
|
||||||
|
"OAUTH_ROLE_TEACHER_VALUE": "teacher-claim-value",
|
||||||
|
"OAUTH_ROLE_STUDENT_VALUE": "student-claim-value"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"provider2": {
|
||||||
|
"type": "oidc",
|
||||||
|
"OIDC_CLIENT_ID": "your_oidc_client_id",
|
||||||
|
"OIDC_CLIENT_SECRET": "your_oidc_client_secret",
|
||||||
|
"OIDC_ISSUER_URL": "https://your-issuer.com",
|
||||||
|
"OIDC_CALLBACK_URL": "http://localhost:3000/auth/oidc/callback"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"simple-login": {
|
||||||
|
"enabled": true,
|
||||||
|
"name": "provider3",
|
||||||
|
"SESSION_SECRET": "your_session_secret"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -23,6 +23,8 @@ services:
|
||||||
EMAIL_PSW: 'vvml wmfr dkzb vjzb'
|
EMAIL_PSW: 'vvml wmfr dkzb vjzb'
|
||||||
JWT_SECRET: haQdgd2jp09qb897GeBZyJetC8ECSpbFJe
|
JWT_SECRET: haQdgd2jp09qb897GeBZyJetC8ECSpbFJe
|
||||||
FRONTEND_URL: "http://localhost:5173"
|
FRONTEND_URL: "http://localhost:5173"
|
||||||
|
volumes:
|
||||||
|
- ./auth_config.json:/usr/src/app/serveur/config/auth_config.json
|
||||||
depends_on:
|
depends_on:
|
||||||
- mongo
|
- mongo
|
||||||
restart: always
|
restart: always
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@ const userRouter = require('./routers/users.js');
|
||||||
const folderRouter = require('./routers/folders.js');
|
const folderRouter = require('./routers/folders.js');
|
||||||
const quizRouter = require('./routers/quiz.js');
|
const quizRouter = require('./routers/quiz.js');
|
||||||
const imagesRouter = require('./routers/images.js')
|
const imagesRouter = require('./routers/images.js')
|
||||||
|
const authRouter = require('./routers/auth.js')
|
||||||
|
|
||||||
// Setup environement
|
// Setup environement
|
||||||
dotenv.config();
|
dotenv.config();
|
||||||
|
|
@ -48,6 +49,7 @@ app.use('/api/user', userRouter);
|
||||||
app.use('/api/folder', folderRouter);
|
app.use('/api/folder', folderRouter);
|
||||||
app.use('/api/quiz', quizRouter);
|
app.use('/api/quiz', quizRouter);
|
||||||
app.use('/api/image', imagesRouter);
|
app.use('/api/image', imagesRouter);
|
||||||
|
app.use('/api/auth', authRouter);
|
||||||
|
|
||||||
app.use(errorHandler)
|
app.use(errorHandler)
|
||||||
|
|
||||||
|
|
|
||||||
53
server/config/auth.js
Normal file
53
server/config/auth.js
Normal file
|
|
@ -0,0 +1,53 @@
|
||||||
|
const fs = require('fs');
|
||||||
|
const path = require('path');
|
||||||
|
const pathAuthConfig = './auth_config.json';
|
||||||
|
|
||||||
|
class AuthConfig {
|
||||||
|
|
||||||
|
constructor(configPath) {
|
||||||
|
this.configPath = configPath;
|
||||||
|
this.config = this.loadConfig();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Méthode pour lire le fichier de configuration JSON
|
||||||
|
loadConfig() {
|
||||||
|
try {
|
||||||
|
const configData = fs.readFileSync(this.configPath, 'utf-8');
|
||||||
|
return JSON.parse(configData);
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Erreur lors de la lecture du fichier de configuration :", error);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Méthode pour retourner la configuration des fournisseurs PassportJS
|
||||||
|
getPassportJSConfig() {
|
||||||
|
if (this.config && this.config.auth && this.config.auth.passportjs) {
|
||||||
|
const passportConfig = {};
|
||||||
|
|
||||||
|
this.config.auth.passportjs.forEach(provider => {
|
||||||
|
const providerName = Object.keys(provider)[0];
|
||||||
|
passportConfig[providerName] = provider[providerName];
|
||||||
|
});
|
||||||
|
|
||||||
|
return passportConfig;
|
||||||
|
} else {
|
||||||
|
return { error: "Aucune configuration PassportJS disponible." };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Méthode pour retourner la configuration de Simple Login
|
||||||
|
getSimpleLoginConfig() {
|
||||||
|
if (this.config && this.config.auth && this.config.auth["simple-login"]) {
|
||||||
|
return this.config.auth["simple-login"];
|
||||||
|
} else {
|
||||||
|
return { error: "Aucune configuration Simple Login disponible." };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Utilisation de la classe ConfigManager
|
||||||
|
const configPath = path.join(__dirname, pathAuthConfig);
|
||||||
|
const instance = new AuthConfig(configPath);
|
||||||
|
module.exports = instance;
|
||||||
|
|
||||||
26
server/controllers/auth.js
Normal file
26
server/controllers/auth.js
Normal file
|
|
@ -0,0 +1,26 @@
|
||||||
|
const authConfig = require('../config/auth.js');
|
||||||
|
|
||||||
|
class authController {
|
||||||
|
|
||||||
|
async getActive(req, res, next) {
|
||||||
|
|
||||||
|
try {
|
||||||
|
|
||||||
|
const passportConfig = authConfig.getPassportJSConfig();
|
||||||
|
const simpleLoginConfig = authConfig.getSimpleLoginConfig();
|
||||||
|
|
||||||
|
const response = {
|
||||||
|
passportConfig,
|
||||||
|
simpleLoginConfig
|
||||||
|
};
|
||||||
|
|
||||||
|
return res.json(response);
|
||||||
|
}
|
||||||
|
catch (error) {
|
||||||
|
return next(error); // Gérer l'erreur
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = new authController;
|
||||||
9
server/routers/auth.js
Normal file
9
server/routers/auth.js
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
const express = require('express');
|
||||||
|
const router = express.Router();
|
||||||
|
const jwt = require('../middleware/jwtToken.js');
|
||||||
|
|
||||||
|
const authController = require('../controllers/auth.js')
|
||||||
|
|
||||||
|
router.get("/getActiveAuth",jwt.authenticate, authController.getActive);
|
||||||
|
|
||||||
|
module.exports = router;
|
||||||
Loading…
Reference in a new issue