import * as msal from '@azure/msal-node';
const msalClient = new msal.ConfidentialClientApplication({
auth: {
clientId: CONFIG.ONE_DRIVE_CLIENT_ID,
authority: `https://login.microsoftonline.com/${CONFIG.ONE_DRIVE_TENANT_ID}`,
clientSecret: CONFIG.ONE_DRIVE_CLIENT_SECRET,
},
})
const accessData = await msalClient.acquireTokenByClientCredential({
scopes: ['https://graph.microsoft.com/.default'],
});
const sharedLink =
'https://1drv.ms/f/s!PIBLIC_SHARED_LINK_DATA?e=
PIBLIC_SHARE_LINK_DATA
'; // has access to edit for everyone with a link
const base64Value = Buffer.from(sharedLink, 'utf-8').toString('base64');
const encodedUrl =
'u!' +
base64Value.replace(/=+$/, '').replace(/\//g, '_').replace(/\+/g, '-');
const response = await fetch(
`https://graph.microsoft.com/v1.0/shares/${encodedUrl}/`,
{
headers: {
Authorization: `${accessData.tokenType} ${accessData.accessToken}`,
},
},
);
if (response.ok) {
const data = await response.json();
console.log('Shared folder items:', data);
} else {
console.error(
'Error retrieving shared items:',
response.status,
response.statusText,
);
}
I get access token but GET /shares response error 403
I have created an application for my OneDrive business account, and register it by Microsoft Entra and Azure. I tried to activate trial for my directory.
I already granted all the necessary permisions and allow external sharing here: Microsoft 365 Admin Center > Settings > Org Settings > SharePoint
And it still doesn't work, even through https://developer.microsoft.com/en-us/graph/graph-explorer