首页 > 解决方案 > 像 Google 这样的更简单的 MSAL.js 身份验证?(不使用缓存系统)

问题描述

我真的在努力使用 Microsoft Graph 身份验证系统(与 Google Auth API 相比)。

我只想使用存储的令牌进行 API 调用(无需管理缓存系统或其他)。

这是我想用 Microsoft Graph 复制的一个简单的 Google 示例:

  const { google } = require('googleapis');

  const oauth2Client = new google.auth.OAuth2(
    process.env.GOOGLE_CLIENT_ID,
    process.env.GOOGLE_CLIENT_SECRET,
    process.env.GOOGLE_CLIENT_REDIRECT_URI,
  );

  const auth = oauth2Client.setCredentials(googleOauthTokens);
  // googleOauthTokens is stored on my DB and doesn't need to change,
  // I got it from the oauth redirect callback using oauth2Client.getToken(req.query.code)

  const calendar = google.calendar({ version: 'v3', auth });
  const { data: calendarData } = await calendar.calendarList.list();
  console.log(calendarData);

我希望使用 Microsoft 身份验证库 ( @azure/msal-node) 完成类似的流程,而无需管理在ConfidentialClientApplication.

为什么我们不能只使用结果msalClient.acquireTokenByCode(tokenRequest)来设置凭据并开始使用 Microsoft Graph API?

我查看了 MSAL 的所有文档/常见问题解答,但找不到具有简单实现的单个示例!

标签: microsoft-graph-apigoogle-oauthmsalmsal.js

解决方案


推荐阅读