I need to programmatically upload files to OneDrive. I won't have a front-end to generate the keys, because of that I need to generate them without user interaction and that's my problem. I've already managed to do this with a simple POC, but it necessarily needs user interaction because it uses the login and password credentials to authenticate to the Microsoft account, and only after that it uses clientId and clientSecret
When I try to generate a token using @msal-node, it doesn't use the scopes defined in Azure.
const msal = require('@azure/msal-node')
const config = require('../config')
const azConfig = {
auth: {
clientId: config.azureAppId,
authority: `https://login.microsoftonline.com/${config.azureTenantId}`,
clientSecret: config.azureAuthSecret
}
}
const pca = new msal.ConfidentialClientApplication(azConfig)
return await pca.acquireTokenByClientCredential({
scopes: [`${config.azureAppId}/.default`]
})
And I also can't pass new scopes through the acquireTokenByClientCredential() function because it thrown a error.
const msal = require('@azure/msal-node')
const config = require('../config')
const azConfig = {
auth: {
clientId: config.azureAppId,
authority: `https://login.microsoftonline.com/${config.azureTenantId}`,
clientSecret: config.azureAuthSecret
}
}
const pca = new msal.ConfidentialClientApplication(azConfig)
return await pca.acquireTokenByClientCredential({
scopes: [
`${config.azureAppId}/.default`,
'Files.Read'
]
})
ServerError: invalid_scope: 70011 - [2021-12-30 01:02:11Z]: AADSTS70011: The provided request must include a 'scope' input parameter. The provided value for the input parameter 'scope' is not valid. The scope api://<azureAppId>/.default Files.Read openid profile offline_access is not valid.
The only scope supported by the function is /.default, which doesn't use the permissions added in Azure and when I try to add scopes into the function code, it returns an error saying the scopes parameter is not valid.
But when I generate a token using Postman with the same credentials, it works and adds the scopes I need to access OneDrive