REFACTOR: Adicionado o parametro source no post para a API, e refatorado callback de autenticação.
This commit is contained in:
parent
2542bb1f44
commit
e5b530f9a4
@ -9,6 +9,7 @@ const path = require('path');
|
||||
async function consultarViabilidadeController(req, res) {
|
||||
try {
|
||||
const data = req.body;
|
||||
data.source = 'viabiliza.sothis.com.br';
|
||||
const result = await consultarViabilidade(data);
|
||||
res.json(result);
|
||||
} catch (error) {
|
||||
|
||||
@ -1,14 +1,15 @@
|
||||
const express = require('express');
|
||||
const router = express.Router();
|
||||
const dotenv = require('dotenv');
|
||||
|
||||
dotenv.config();
|
||||
|
||||
/**
|
||||
* Página simples de login
|
||||
*/
|
||||
router.get('/login', (req, res) => {
|
||||
res.send(`
|
||||
<h2>Login necessário</h2>
|
||||
<a href="/auth/microsoft">Entrar com Microsoft</a>
|
||||
`);
|
||||
// Redirect straight to Microsoft OAuth start to avoid an extra click/page
|
||||
return res.redirect('/auth/microsoft');
|
||||
});
|
||||
|
||||
/**
|
||||
@ -31,7 +32,8 @@ router.get('/auth/microsoft', (req, res) => {
|
||||
/**
|
||||
* Callback do Azure
|
||||
*/
|
||||
router.get('/auth/microsoft/callback', async (req, res) => {
|
||||
// shared handler so we accept both /auth/microsoft/callback and /auth/callback
|
||||
async function oauthCallbackHandler(req, res) {
|
||||
const code = req.query.code;
|
||||
// Verbose logging for debugging the OAuth callback flow
|
||||
console.log('[OAuth callback] incoming query:', {
|
||||
@ -50,7 +52,7 @@ router.get('/auth/microsoft/callback', async (req, res) => {
|
||||
console.log('[OAuth callback] exchanging code for tokens (will not log secrets)');
|
||||
|
||||
const tokenRespRaw = await fetch(
|
||||
`https://login.microsoftonline.com/${process.env.AZURE_TENANT_ID}/oauth2/v2.0/token`,
|
||||
`https://login.microsoftonline.com/${process.env.OAUTH_TENANT_ID}/oauth2/v2.0/token`,
|
||||
{
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
||||
@ -113,7 +115,11 @@ router.get('/auth/microsoft/callback', async (req, res) => {
|
||||
console.error('[OAuth callback] unexpected error during token exchange or session creation:', err && (err.stack || err.message || err));
|
||||
res.redirect('/login');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
router.get('/auth/microsoft/callback', oauthCallbackHandler);
|
||||
// some Azure app registrations (or tooling like ngrok) may use /auth/callback — accept that too
|
||||
router.get('/auth/callback', oauthCallbackHandler);
|
||||
|
||||
router.get('/logout', (req, res) => {
|
||||
req.session.destroy(() => res.redirect('/login'));
|
||||
|
||||
Loading…
Reference in New Issue
Block a user