刚接触Typescript,但仍在习惯Microsoft Azure,所以请原谅这个基本问题。
我已经创建了一个企业应用程序,它应该能够登录到Graph API并读取用户配置文件。我有客户端id/secret,租户id,但我需要知道如何在TypeScript中初始化这个客户端。
我应该初始化一个GraphClient
还是有一个通用的Client
我可以使用?
一个关于如何做到这一点的教程/示例或文档的链接将是惊人的。
对于上下文,我希望能够编写一个函数来初始化客户端,然后编写查询-所有文档都谈到了多个我无法使用的文件,因为我是作为第三方集成编写的。
我发现了这个,但它看起来很复杂,我真的无法理解。
有类似的打字稿吗
client_credential = ClientSecretCredential(tenant_id, client_id, client_secret)
client = GraphClient(credential=self.client_credential,
scopes=['https://graph.microsoft.com/.default']
)
这就是我成功做到的方法。不幸的是,我只能使用一个非常旧的微软图形模块版本。
const qs = require('qs');
const MicrosoftGraphClient = require('@microsoft/microsoft-graph-client@1.0.0');
const axios = require('axios@0.27.2');
const getToken = async () => {
try{
const response = await axios.post(
`https://login.microsoftonline.com/${tenantId}/oauth2/v2.0/token`,
qs.stringify(
{
client_id : clientId,
client_secret: clientSecret,
scope: 'https://graph.microsoft.com/.default',
grant_type: 'client_credentials'
}
))
let tokenSet = response.data;
return tokenSet.access_token;
} catch (error){
console.log(error)
};
}
var client = MicrosoftGraphClient.Client.init({
authProvider: async (done) => {
const token = await getToken()
done(null, token);
}
});