我正在尝试在我的反应应用程序中使用adal-node实现客户端凭据流
我正在尝试的代码
var AuthenticationContext = require('adal-node').AuthenticationContext;
const authenticate = (): any =>{
var authorityHostUrl = 'https://login.microsoftonline.com';
var tenant = 'xxxx.onmicrosoft.com';
var authorityUrl = authorityHostUrl + '/' + tenant;
var applicationId = '2sdsdwewe-232jkdksdsdsadfsfdsdf';
var clientSecret = 'sdfer245dwfsfw3rt345r342fwfwefwf';
var resource = 'api://sdfwerwerwrwerwerwrewrwer';
var context = new AuthenticationContext(authorityUrl);
context.acquireTokenWithClientCredentials(resource, applicationId, clientSecret, (err: { stack: string; }, tokenResponse: any)=> {
if (err) {
console.log('well that didn\'t work: ' + err.stack);
} else {
console.log(tokenResponse);
}
});
}
我已经从我的本地运行http://localhost:3000/
因此,在应用程序的 Azure 活动目录应用程序注册中,我已http://localhost:3000/
在 Web 重定向 URI 下添加。还尝试在 SPA 下添加它
但是当我运行它时会出现 CORS 错误
Access to fetch at 'https://login.microsoftonline.com/xxxx.onmicrosoft.com/oauth2/token?api-version=1.0' from origin 'http://localhost:3000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
我在这里遗漏了一些东西
当我运行 Chrome 时chrome.exe --user-data-dir="C:/Chrome dev session" --disable-web-security
这有效并生成有效令牌