diff --git a/README.md b/README.md index ba8c2f3..0fd8a73 100644 --- a/README.md +++ b/README.md @@ -23,3 +23,4 @@ Gestion de friendship dans POSTGRESQL: Ressource: https://www.postgresql.org/docs/ + https://docs.github.com/en/apps/oauth-apps/building-oauth-apps/authorizing-oauth-apps \ No newline at end of file diff --git a/srcs/backend/routes/auth.js b/srcs/backend/routes/auth.js index 4b1b960..2e42b28 100644 --- a/srcs/backend/routes/auth.js +++ b/srcs/backend/routes/auth.js @@ -1,6 +1,7 @@ const express = require('express'); const router = express.Router(); const authService = require('../services/auth'); +const fetch = require('node-fetch'); router.post('/register', async(req, res) => { @@ -20,4 +21,13 @@ router.post('/login', async(req, res) => res.status(result.status).json(result.data); }); +router.get('/github', (req, res) => { + const githubAuthUrl = `https://github.com/login/oauth/authorize?` + + `client_id=${process.env.GITHUB_CLIENT_ID}&` + + `redirect_uri=${encodeURIComponent(process.env.GITHUB_REDIRECT_URI)}&` + + `scope=user:email`; + + res.redirect(githubAuthUrl); +}); + module.exports = router; \ No newline at end of file diff --git a/srcs/backend/services/github.js b/srcs/backend/services/github.js new file mode 100644 index 0000000..e69de29 diff --git a/srcs/frontend/src/login.js b/srcs/frontend/src/login.js index 19bcb91..0d61945 100644 --- a/srcs/frontend/src/login.js +++ b/srcs/frontend/src/login.js @@ -4,7 +4,7 @@ export class LoginWindow extends fenetre { constructor() { super(320, 240, "Connexion"); - this.mode = "login"; // login | register + this.mode = "login"; this.username = document.createElement("input"); this.username.placeholder = "Username"; @@ -33,6 +33,19 @@ export class LoginWindow extends fenetre { this.applyStyles(); this.bindEvents(); + // **** AJOUT FONCTION GITHUB **** + // Dans constructor() de LoginWindow + this.githubBtn = document.createElement("button"); + this.githubBtn.innerText = "Se connecter avec GitHub"; + this.githubBtn.style.backgroundColor = "#24292e"; + this.githubBtn.style.color = "white"; + this.githubBtn.onclick = () => { + window.location.href = "/api/auth/github"; + }; + this.body.appendChild(this.githubBtn); + + + this.checkIfAlreadyLoggedIn(); //verifie si l'utilisateur est connecté au démarrage }