关于后端认证的 Azure Token 问题
Azure Token Question About Backend Authentication
我似乎在堆栈溢出的每个部分都发现了,
任何教程
在我获取访问刷新令牌的代码之前,必须先登录 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 returns a link 我需要登录才能获取我的代码
然后我需要使用它来获取令牌并在那里放置我的刷新令牌。
但我不想访问 link,因为我使用的是控制台而不是 GUI,
我的思想处于崩溃的边缘,我不知道该怎么办。
我只需要 One Drive 的 API,
这样我就可以上传我的文件了。
Whosebug 中的多数,
有一个需要刷新令牌的代码
我无法在不访问 link 的情况下获取刷新令牌。
有什么帮助吗?
我设法找到了,
您应该找到客户端凭据,
我使用请求headers
https://login.microsoftonline.com/{tenantid}/oauth2/v2.0/token
租户 ID 位于 Azure 中的应用注册中
然后确保授权类型是
grant_type: 'client_credentials',
范围:'https://graph.microsoft.com/.default' //不确定这是否可以更改
使用请求库或 axios
放 post 头
希望它能帮助其他人发现这个问题
我似乎在堆栈溢出的每个部分都发现了, 任何教程
在我获取访问刷新令牌的代码之前,必须先登录 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 returns a link 我需要登录才能获取我的代码 然后我需要使用它来获取令牌并在那里放置我的刷新令牌。
但我不想访问 link,因为我使用的是控制台而不是 GUI,
我的思想处于崩溃的边缘,我不知道该怎么办。 我只需要 One Drive 的 API, 这样我就可以上传我的文件了。
Whosebug 中的多数, 有一个需要刷新令牌的代码
我无法在不访问 link 的情况下获取刷新令牌。
有什么帮助吗?
我设法找到了, 您应该找到客户端凭据,
我使用请求headers https://login.microsoftonline.com/{tenantid}/oauth2/v2.0/token
租户 ID 位于 Azure 中的应用注册中
然后确保授权类型是 grant_type: 'client_credentials', 范围:'https://graph.microsoft.com/.default' //不确定这是否可以更改
使用请求库或 axios 放 post 头
希望它能帮助其他人发现这个问题