carnet api
This commit is contained in:
parent
a892c07b9b
commit
32ac30631d
@ -5,7 +5,11 @@ import { DOMParser } from '@xmldom/xmldom';
|
||||
|
||||
async function getNextcloudAccessToken(clientId: string, clientSecret: string) {
|
||||
const nextcloudUrl = process.env.NEXTCLOUD_URL;
|
||||
const tokenEndpoint = `${nextcloudUrl}/apps/oauth2/api/v1/token`;
|
||||
if (!nextcloudUrl) {
|
||||
throw new Error('NEXTCLOUD_URL is not defined');
|
||||
}
|
||||
|
||||
const tokenEndpoint = `${nextcloudUrl}/index.php/apps/oauth2/api/v1/token`;
|
||||
|
||||
const params = new URLSearchParams({
|
||||
grant_type: 'client_credentials',
|
||||
@ -17,15 +21,22 @@ async function getNextcloudAccessToken(clientId: string, clientSecret: string) {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/x-www-form-urlencoded',
|
||||
'Accept': 'application/json',
|
||||
},
|
||||
body: params.toString(),
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error('Failed to get Nextcloud access token');
|
||||
const errorText = await response.text();
|
||||
console.error('Nextcloud token response:', errorText);
|
||||
throw new Error(`Failed to get Nextcloud access token: ${response.status} ${errorText}`);
|
||||
}
|
||||
|
||||
const data = await response.json();
|
||||
if (!data.access_token) {
|
||||
throw new Error('No access token in response');
|
||||
}
|
||||
|
||||
return data.access_token;
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user