I am using a function to authenticate SSO with Azure. I continue to have issues with users being able to log in and redirect or pass the authentication (which is successful in azure logs) back to the site. Any help would be greatly appreciated.
From the provided logs, it is clear that the code
and state
query parameters are not being received or processed correctly by your function. Here are the key points from the logs:
- No Response from Redirect: The message “No response received from redirect” indicates that the expected parameters were not found.
- Console Logs:
INFO Raw query string: {}
: This indicates that the query string is empty when it reaches your serverless function.
- Extracted Values:
INFO Extracted code: undefined
INFO Extracted state: undefined
Here is the autoCallback.js function:
const querystring = require(‘querystring’);
exports.handler = async function(event, context) {
console.log(“Received event:”, JSON.stringify(event, null, 2));
const rawQuery = event.queryStringParameters;
console.log("Raw query string:", rawQuery);
if (!rawQuery) {
return {
statusCode: 400,
body: 'No query string in request'
};
}
const authorizationCode = rawQuery.code;
const state = rawQuery.state;
console.log("Extracted code:", authorizationCode);
console.log("Extracted state:", state);
if (!authorizationCode) {
return {
statusCode: 400,
body: 'Authorization code not found in request',
};
}
return {
statusCode: 200,
body: 'Authorization code received',
};
};
netlify.toml
[build]
publish = “.”
functions = “functions”
command = “npm install && npm run build”
[context.production]
environment = { NODE_ENV = “production” }
[[redirects]]
from = “/.auth/*”
to = “/.auth/:splat”
status = 200
[[redirects]]
from = “/.auth/login/aad/callback”
to = “/.netlify/functions/authCallback”
status = 200
[[redirects]]
from = “/auth-callback”
to = “/.netlify/functions/authCallback”
status = 200
query = {code = “:code”, state = “:state”}
[[redirects]]
from = “/.netlify/functions/authCallback”
to = “/?code=:code&state=:state”
status = 302
force = true
query = {code = “:code”, state = “:state”}