Agenda Sync refactor Mig Graph
This commit is contained in:
parent
c859068e87
commit
dbbc2ff59a
@ -17,8 +17,21 @@ const GRAPH_API_BASE = 'https://graph.microsoft.com/v1.0';
|
|||||||
* Get a configured Axios instance for Microsoft Graph API
|
* Get a configured Axios instance for Microsoft Graph API
|
||||||
*/
|
*/
|
||||||
async function getMicrosoftGraphClient(mailCredentialId: string): Promise<AxiosInstance> {
|
async function getMicrosoftGraphClient(mailCredentialId: string): Promise<AxiosInstance> {
|
||||||
// Get fresh access token
|
// Look up the mail credential to get userId and email for token refresh
|
||||||
const tokenResult = await ensureFreshToken(mailCredentialId);
|
const account = await prisma.mailCredentials.findUnique({
|
||||||
|
where: { id: mailCredentialId },
|
||||||
|
select: {
|
||||||
|
userId: true,
|
||||||
|
email: true,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!account) {
|
||||||
|
throw new Error('Mail credential not found for Microsoft Graph client');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get fresh access token using userId + email
|
||||||
|
const tokenResult = await ensureFreshToken(account.userId, account.email);
|
||||||
|
|
||||||
if (!tokenResult || !tokenResult.accessToken) {
|
if (!tokenResult || !tokenResult.accessToken) {
|
||||||
throw new Error('Failed to obtain valid access token for Microsoft Graph API. The account may need to be re-authenticated with Mail.Read and Mail.Send permissions.');
|
throw new Error('Failed to obtain valid access token for Microsoft Graph API. The account may need to be re-authenticated with Mail.Read and Mail.Send permissions.');
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user