github_auth presque integre (implementation pas finis)
This commit is contained in:
@@ -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
|
||||
@@ -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;
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user