A simpler MSAL.js auth like Google? (without using the caching system)

Viewed 94

I'm really struggling with the Microsoft Graph authentication system (compared to Google Auth API).

I just want to use the stored tokens to make API calls (without managing a caching system or whatever).

Here is a simple example with Google that I want to replicate with Microsoft Graph:

  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);

I'm looking to accomplish a similar flow with the Microsoft Authentification Library (@azure/msal-node) without having to manage the complexity of maintaing a cache within the ConfidentialClientApplication.

Why can't we just use the result of msalClient.acquireTokenByCode(tokenRequest) to set the credentials and start using the Microsoft Graph API?

I looked on all the docs/FAQ of MSAL and couldn't find a single example with a simple implementation!

0 Answers
Related