widget email 11
This commit is contained in:
parent
89028f3852
commit
5babc300b0
@ -11,46 +11,17 @@ export async function GET(req: NextRequest) {
|
||||
}
|
||||
|
||||
const nextcloudUrl = process.env.NEXTCLOUD_URL;
|
||||
const clientId = process.env.NEXTCLOUD_CLIENT_ID;
|
||||
const clientSecret = process.env.NEXTCLOUD_CLIENT_SECRET;
|
||||
|
||||
if (!nextcloudUrl || !clientId || !clientSecret) {
|
||||
console.error('Missing Nextcloud configuration');
|
||||
if (!nextcloudUrl) {
|
||||
console.error('Missing Nextcloud URL');
|
||||
return NextResponse.json(
|
||||
{ error: 'Nextcloud configuration is missing' },
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
|
||||
// First, get a Nextcloud OIDC token using client credentials
|
||||
const tokenResponse = await fetch(`${nextcloudUrl}/index.php/apps/oauth2/api/v1/token`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/x-www-form-urlencoded',
|
||||
'Authorization': `Basic ${Buffer.from(`${clientId}:${clientSecret}`).toString('base64')}`,
|
||||
},
|
||||
body: new URLSearchParams({
|
||||
grant_type: 'client_credentials',
|
||||
scope: 'ocs',
|
||||
}),
|
||||
});
|
||||
|
||||
if (!tokenResponse.ok) {
|
||||
const errorData = await tokenResponse.json();
|
||||
console.error('Failed to get Nextcloud token:', {
|
||||
status: tokenResponse.status,
|
||||
statusText: tokenResponse.statusText,
|
||||
error: errorData
|
||||
});
|
||||
return NextResponse.json({ error: 'Nextcloud authentication failed' }, { status: 401 });
|
||||
}
|
||||
|
||||
const { access_token } = await tokenResponse.json();
|
||||
|
||||
// Now try to access the Mail app using the Nextcloud token
|
||||
// Try to access the Mail app directly
|
||||
const response = await fetch(`${nextcloudUrl}/ocs/v2.php/apps/mail/api/v1/accounts`, {
|
||||
headers: {
|
||||
'Authorization': `Bearer ${access_token}`,
|
||||
'Accept': 'application/json',
|
||||
'OCS-APIRequest': 'true',
|
||||
'Content-Type': 'application/json',
|
||||
@ -58,10 +29,20 @@ export async function GET(req: NextRequest) {
|
||||
},
|
||||
});
|
||||
|
||||
let responseData;
|
||||
try {
|
||||
responseData = await response.json();
|
||||
} catch (error) {
|
||||
const text = await response.text();
|
||||
console.error('Failed to parse response:', text);
|
||||
return NextResponse.json({ error: 'Invalid response format' }, { status: 500 });
|
||||
}
|
||||
|
||||
if (!response.ok) {
|
||||
console.error('Mail app check failed:', {
|
||||
status: response.status,
|
||||
statusText: response.statusText,
|
||||
error: responseData,
|
||||
url: response.url,
|
||||
});
|
||||
|
||||
@ -75,8 +56,7 @@ export async function GET(req: NextRequest) {
|
||||
);
|
||||
}
|
||||
|
||||
const data = await response.json();
|
||||
const accounts = data?.ocs?.data || [];
|
||||
const accounts = responseData?.ocs?.data || [];
|
||||
|
||||
// For now, return a success response with an empty array
|
||||
return NextResponse.json([]);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user