【发布时间】:2021-06-09 00:38:59
【问题描述】:
我可以从命令行生成访问令牌:
az account get-access-token
但是,此访问令牌不适用于 kusto,因为该令牌尚未确定范围。
az account get-access-token --resource https://{name}.{location}.kusto.windows.net
这提供了一个被kusto 接受的访问令牌。
我的问题与@azure/msal-browser 库有关,以及我如何将访问令牌限定为特定的resource。在下面的示例中,我使用了@azure/msal-react,它只是底层@azure/msal-browser 库之上的一个抽象层。
import { useMsal, useAccount } from '@azure/msal-react';
const ControllerRequester = () => {
const { accounts, instance } = useMsal();
const account = useAccount(accounts[0] || {});
if (Object.keys(accounts).length) {
instance.acquireSilentToken({
account,
// What other properties do I need to include to scope the access token to kusto
}).then(accessToken => doSomething(accessToken))
}
return <div>...</div>
}
我尝试了几个不同的选项,例如scopes: ['https://{name}.{location}.kusto.windows.net/.default'],但都没有成功。我还阅读了与 msal 库相关的其他答案,但它们没有帮助。任何帮助将不胜感激!
【问题讨论】:
-
您是否尝试过使用
https://{name}{location}.kusto.windows.net获取令牌?
标签: reactjs azure active-directory msal msal.js