我似乎在堆栈溢出的每个部分都发现, 任何教程
在我获取访问刷新 token 的代码之前,必须先登录 azure
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 返回一个链接,我需要登录该链接才能获取我的代码 然后我需要使用它来获取 token 并在那里放置我的刷新 token 。
但我不想访问该链接,因为我使用的是控制台而不是 GUI,
我的心已经崩溃了,我不知道该怎么办。 我只需要 One Drive 的 API, 这样我就可以上传我的文件。
stackoverflow 中的大多数, 有一个需要刷新 token 的代码
如果不访问链接,我无法获取刷新 token 。
有什么帮助吗?
最佳答案
我终于找到了, 您应该找到客户凭据,
我使用请求 header https://login.microsoftonline.com/{tenant id}/oauth2/v2.0/token
租户 ID 位于 azure 中的应用注册中
然后确保资助类型是 grant_type: 'client_credentials', range: 'https://graph.microsoft.com/.default'//不确定这是否可以更改
使用请求库或 axios 获取帖子头
希望其他人发现这个问题时能有所帮助
关于javascript - 如何在不使用普通 Azure Auth2 提供的登录链接的情况下访问 Azure 登录 Api,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71486841/