From 35e689a1e3e07f4d8c3b30b6654ef7c6d169cb81 Mon Sep 17 00:00:00 2001 From: Alma Date: Wed, 9 Apr 2025 23:51:21 +0200 Subject: [PATCH] update widget token mail 10 --- app/api/rocket-chat/messages/route.ts | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/app/api/rocket-chat/messages/route.ts b/app/api/rocket-chat/messages/route.ts index a71a10ce..2430107f 100644 --- a/app/api/rocket-chat/messages/route.ts +++ b/app/api/rocket-chat/messages/route.ts @@ -58,16 +58,18 @@ export async function GET() { // Get Rocket.Chat OAuth token const rocketChatAuthResponse = await fetch( - 'https://parole.slm-lab.net/api/v1/login', + 'https://parole.slm-lab.net/api/v1/oauth/token', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ - serviceName: 'keycloak', - accessToken: session.accessToken, - expiresIn: 3600 + grant_type: 'urn:ietf:params:oauth:grant-type:token-exchange', + client_id: process.env.ROCKET_CHAT_CLIENT_ID, + client_secret: process.env.ROCKET_CHAT_CLIENT_SECRET, + subject_token: session.accessToken, + subject_token_type: 'urn:ietf:params:oauth:token-type:access_token' }) } ); @@ -86,15 +88,13 @@ export async function GET() { const rocketChatAuth = await rocketChatAuthResponse.json(); console.log('Rocket.Chat auth success:', { - userId: rocketChatAuth.data?.userId, - hasToken: !!rocketChatAuth.data?.authToken + hasToken: !!rocketChatAuth.access_token }); // Now get user info from Rocket.Chat using the obtained token const meResponse = await fetch('https://parole.slm-lab.net/api/v1/me', { headers: { - 'X-Auth-Token': rocketChatAuth.data.authToken, - 'X-User-Id': rocketChatAuth.data.userId + 'Authorization': `Bearer ${rocketChatAuth.access_token}` }, cache: 'no-store', }); @@ -122,8 +122,7 @@ export async function GET() { 'https://parole.slm-lab.net/api/v1/subscriptions.get', { headers: { - 'X-Auth-Token': rocketChatAuth.data.authToken, - 'X-User-Id': rocketChatAuth.data.userId + 'Authorization': `Bearer ${rocketChatAuth.access_token}` }, cache: 'no-store', } @@ -155,8 +154,7 @@ export async function GET() { `https://parole.slm-lab.net/api/v1/chat.getMessage?msgId=${room.lastMessage._id}`, { headers: { - 'X-Auth-Token': rocketChatAuth.data.authToken, - 'X-User-Id': rocketChatAuth.data.userId + 'Authorization': `Bearer ${rocketChatAuth.access_token}` }, cache: 'no-store', }