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) {
|
async function getNextcloudAccessToken(clientId: string, clientSecret: string) {
|
||||||
const nextcloudUrl = process.env.NEXTCLOUD_URL;
|
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({
|
const params = new URLSearchParams({
|
||||||
grant_type: 'client_credentials',
|
grant_type: 'client_credentials',
|
||||||
@ -17,15 +21,22 @@ async function getNextcloudAccessToken(clientId: string, clientSecret: string) {
|
|||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/x-www-form-urlencoded',
|
'Content-Type': 'application/x-www-form-urlencoded',
|
||||||
|
'Accept': 'application/json',
|
||||||
},
|
},
|
||||||
body: params.toString(),
|
body: params.toString(),
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!response.ok) {
|
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();
|
const data = await response.json();
|
||||||
|
if (!data.access_token) {
|
||||||
|
throw new Error('No access token in response');
|
||||||
|
}
|
||||||
|
|
||||||
return data.access_token;
|
return data.access_token;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user