任何使用 msal-node DistributedCachePlugin 的好文档?

问题描述 投票:0回答:0

我在互联网上搜索了有关 DistributedCachePlugin 的良好文档,但发现很少。连微软都难懂

有人知道如何实现它的简单示例吗?我不知道如何序列化令牌缓存以保留所有自定义类功能。

class MySQLCacheClient {
  constructor(config) {
    this.connection = mysql.createConnection(config);
    // this.promiseConnection = this.connection.promise()
  }

  async getkey(key) {
    console.log('getCache')
    console.log(key)
    // const [rows] = this.connection.query('SELECT * FROM token_cache WHERE key = ?', [key]);
    // return rows[0];
  }

  async setkey(key) {
    console.log('setCache')
    this.connection.query('INSERT INTO token_cache (key, value) VALUES (?, ?) ON DUPLICATE KEY UPDATE value = ?', [key, JSON.stringify(account), JSON.stringify(account)]);
  }
}

class MySQLPartitionManager {
  constructor(config) {
    this.connection = mysql.createConnection(config);
  }

  async getKey(key) {
    console.log('getPart')
    console.log(key)
    const query = 
    `SELECT 
      value 
    FROM token_cache 
    WHERE key = key`
    const rows = this.connection.query(query, [key])
    return rows[0];
  }

  async setKey(partition) {
    console.log('setPart')
    this.connection.query('INSERT INTO token_cache (key, value) VALUES (?, ?) ON DUPLICATE KEY                UPDATE value = ?', [partition.key, JSON.stringify(partition), JSON.stringify(partition)]);
  }
}

...

const cacheClient = new MySQLCacheClient(mysqlConfig);
const cachePartition = new MySQLPartitionManager(mysqlConfig);
const cachePlugin = new DistributedCachePlugin(cacheClient, cachePartition);

const config = {
  auth: {
    clientId: process.env.MICROSOFT_CLIENT_ID,
    authority: process.env.ATHORITY_URI,
    clientSecret: process.env.MICROSOFT_CLIENT_SECRET
  },
  cache: {
    cachePlugin: cachePlugin,
  },
}
node.js caching msal
© www.soinside.com 2019 - 2024. All rights reserved.