从命令行,我可以使用生成访问令牌
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/.default
尝试删除.default
更正,删除.default并尝试