ict-architecture
Labo 10: Autorisatie en Authenticatie (OAuth)
Login implementatie via GitHub OAuth.
Setup & Installatie
npm install express axios dotenvInstalleer de nodige packages voor Node.js.
node index.jsStart de OAuth Express server.
Bestanden & Configuraties
.env
ini
GITHUB_CLIENT_ID=jouw_client_id GITHUB_CLIENT_SECRET=jouw_client_secret GITHUB_CALLBACK_URL=http://localhost:3000/callback Omgevingsvariabelen voor GitHub OAuth.
oauth.js
javascript
const tokenResponse = await axios.post('https://github.com/login/oauth/access_token', { client_id: process.env.GITHUB_CLIENT_ID, client_secret: process.env.GITHUB_CLIENT_SECRET, code: req.query.code}, { headers: { Accept: 'application/json' }}); const accessToken = tokenResponse.data.access_token;Snippet voor het inwisselen van een code voor een token.