'Azure Token Question About Backend Authentication
I seem to find in every part of stack overflow, any tutorial
that azure must be log in, before I get the code to access the refresh token
const config = {
auth: {
clientId: process.env.CLIENT_ID,
authority: process.env.AUTHORITY,
clientSecret: process.env.CLIENT_SECRET
},
system: {
loggerOptions: {
loggerCallback(loglevel, message, containsPii) {
console.log(message);
},
piiLoggingEnabled: false,
logLevel: msal.LogLevel.Verbose,
}
}
};
const authCodeUrlParameters = {
scopes: ["user.read","user.write"],
redirectUri: process.env.REDIRECT_URL,
};
pca.getAuthCodeUrl(authCodeUrlParameters).then((response) => {
// res.redirect(response);
console.log(response);
}).catch((error) => console.log(JSON.stringify(error)));
console.log(authCodeUrlParameters);
const pca = new msal.ConfidentialClientApplication(config);
app.get('/redirect', (req, res) => {
const tokenRequest = {
code: req.query.code,
scopes: ["user.read"],
redirectUri: REDIRECT_URI,
};
pca.acquireTokenByCode(tokenRequest).then((response) => {
console.log("\nResponse: \n:", response);
res.sendStatus(200);
}).catch((error) => {
console.log(error);
res.status(500).send(error);
});
});
getAuthCodeUrl returns a link which I would need to login to get my code which then would I need to use to get the tokens and have my refresh token there.
but I don't want to access the link since I'm using console not GUI,
My Mind is at the breaking point I don't know what to do. I just need the API for One Drive, so I can Upload my file.
majority in the stackoverflow, has a code that requires a refresh token
I can't get the refresh token without accessing the link.
Any help?
Solution 1:[1]
I manage to find it, you should find the Client Credentials,
I use request headers https://login.microsoftonline.com/{tenant id}/oauth2/v2.0/token
tenant id is located in app registration in azure
then make sure the grant type is grant_type: 'client_credentials', scope: 'https://graph.microsoft.com/.default' //not sure if this is changeable yet
either use request lib or axios get put post head
hope it helps other people when they find this issue
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | ayami asakura |
