I have the following NodeJS code
async onedrive (
addon: AddOn,
app: express.Application,
req: any,
res: any
) {
const storageType = req.query.storageType; // Get the selected storage type from the query parameter
const selectedScopes = scopes[storageType];
if (!selectedScopes) {
return res.status(400).send('Invalid storage type');
}
const authUrl = `https://login.microsoftonline.com/common/oauth2/v2.0/authorize?client_id=${CLIENT_ID}&scope=${encodeURIComponent(selectedScopes)}&response_type=code&response_mode=query&redirect_uri=${encodeURIComponent(REDIRECT_URI)}&prompt=consent&state=${encodeURIComponent(storageType)}`;
res.json({ authUrl }); // Send the URL as a JSON response
}
async callback (
addon: AddOn,
app: express.Application,
req: any,
res: any
) {
const code = req.query.code;
const storageType = req.query.state;
// const filePath = path.join(__dirname, 'profile_picture.jpg'); // Define the path where you want to save the image
try {
const selectedScopes = scopes[storageType];
if (!selectedScopes) {
return res.status(400).send('Invalid storage type');
}
const params = new URLSearchParams();
params.append('client_id', CLIENT_ID);
params.append('scope', selectedScopes);
params.append('redirect_uri', REDIRECT_URI);
params.append('client_secret', CLIENT_SECRET);
params.append('code', code);
params.append('grant_type', 'authorization_code');
// Exchange the authorization code for an access token
const tokenResponse = await axios.post(`https://login.microsoftonline.com/common/oauth2/v2.0/token`, params, {
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
});
const accessToken = tokenResponse.data.access_token;
const refreshToken = tokenResponse.data.refresh_token;
const expiryDate = tokenResponse.data.expires_in;
const returnData = {
access_token: accessToken,
refresh_token: refreshToken,
};
var io = req.app.get('socketio');
var sessionId = req.app.get('sessionId');
io.to(sessionId).emit("response", returnData);
res.sendFile(path.resolve("./loginSuccess.html"));
}
catch (error: any) {
console.error('Error authenticating with OneDrive:', error.response ? error.response.data : error.message);
res.status(500).send('Authentication failed.');
}
}
when i am redirected to get a token from https://login.microsoftonline.com/common/oauth2
i am getting the following admin request approval
i asked my admin and he approved my request but yet nothing happened and i am not being redirected to the callback URL, what may be the issue? am i missing something?
although the call back URL is valid and working from azure side as if i click on go back to app i got the authorization failed message that i am setting
1