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 // Get Rocket.Chat OAuth token
const rocketChatAuthResponse = await fetch( const rocketChatAuthResponse = await fetch(
'https://parole.slm-lab.net/api/v1/login', 'https://parole.slm-lab.net/api/v1/oauth/token',
{ {
method: 'POST', method: 'POST',
headers: { headers: {
'Content-Type': 'application/json' 'Content-Type': 'application/json'
}, },
body: JSON.stringify({ body: JSON.stringify({
serviceName: 'keycloak', grant_type: 'urn:ietf:params:oauth:grant-type:token-exchange',
accessToken: session.accessToken, client_id: process.env.ROCKET_CHAT_CLIENT_ID,
expiresIn: 3600 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(); const rocketChatAuth = await rocketChatAuthResponse.json();
console.log('Rocket.Chat auth success:', { console.log('Rocket.Chat auth success:', {
userId: rocketChatAuth.data?.userId, hasToken: !!rocketChatAuth.access_token
hasToken: !!rocketChatAuth.data?.authToken
}); });
// Now get user info from Rocket.Chat using the obtained token // Now get user info from Rocket.Chat using the obtained token
const meResponse = await fetch('https://parole.slm-lab.net/api/v1/me', { const meResponse = await fetch('https://parole.slm-lab.net/api/v1/me', {
headers: { headers: {
'X-Auth-Token': rocketChatAuth.data.authToken, 'Authorization': `Bearer ${rocketChatAuth.access_token}`
'X-User-Id': rocketChatAuth.data.userId
}, },
cache: 'no-store', cache: 'no-store',
}); });
@ -122,8 +122,7 @@ export async function GET() {
'https://parole.slm-lab.net/api/v1/subscriptions.get', 'https://parole.slm-lab.net/api/v1/subscriptions.get',
{ {
headers: { headers: {
'X-Auth-Token': rocketChatAuth.data.authToken, 'Authorization': `Bearer ${rocketChatAuth.access_token}`
'X-User-Id': rocketChatAuth.data.userId
}, },
cache: 'no-store', cache: 'no-store',
} }
@ -155,8 +154,7 @@ export async function GET() {
`https://parole.slm-lab.net/api/v1/chat.getMessage?msgId=${room.lastMessage._id}`, `https://parole.slm-lab.net/api/v1/chat.getMessage?msgId=${room.lastMessage._id}`,
{ {
headers: { headers: {
'X-Auth-Token': rocketChatAuth.data.authToken, 'Authorization': `Bearer ${rocketChatAuth.access_token}`
'X-User-Id': rocketChatAuth.data.userId
}, },
cache: 'no-store', cache: 'no-store',
} }