Hi everyone,
I'm working on a web app and attempting to integrate Microsoft Drive for the first time. I've added the following code in my backend to authenticate:
const MicrosoftStrategy = require('passport-microsoft').Strategy;
passport.use(
new MicrosoftStrategy(
{
authorizationURL: `${process.env.MICROSOFT_URL}/authorize`,
callbackURL: `${process.env.CALLBACK_URL}/oauth/microsoft/callback`,
clientID: process.env.MICROSOFT_CLIENT_ID,
clientSecret: process.env.MICROSOFT_CLIENT_SECRET,
tokenURL: `${process.env.MICROSOFT_URL}/token`
},
(accessToken, refreshToken, profile, cb) => {
profile.tokens = { microsoft: { accessToken, refreshToken } };
cb(null, profile);
}
)
);
router.get(
'/auth/microsoft',
passport.authenticate('microsoft', { scope: ['user.read', 'offline_access', 'Files.Read.All', 'Files.Read', 'Files.ReadWrite.All', 'Sites.Read.All', 'Sites.ReadWrite.All', 'consent'] })
);
The connection is established successfully, and I receive both the accessToken
and refreshToken
. However, when I try to list the files using the following cURL command:
curl -X GET \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
-H "Content-Type: application/json" \
"https://graph.microsoft.com/v1.0/me/drive/root/children"
It returns:
{"@odata.context":"https://graph.microsoft.com/v1.0/$metadata#Collection(driveItem)","value":[]}
Despite having several folders and one file in the root directory (as shown in the attached screenshot), no items are listed.
Could anyone help me resolve this issue? Thank you!