update widget token mail 10

This commit is contained in:
Alma 2025-04-09 23:51:21 +02:00
parent ed072f5794
commit 35e689a1e3

View File

@ -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',
}