pl-api: Support session management on Mitra
Signed-off-by: nicole mikołajczyk <git@mkljczk.pl>
This commit is contained in:
@ -1475,11 +1475,23 @@ class PlApiClient {
|
|||||||
* Requires features{@link Features.sessions}.
|
* Requires features{@link Features.sessions}.
|
||||||
* @see {@link https://docs.pleroma.social/backend/development/API/pleroma_api/#get-apioauth_tokens}
|
* @see {@link https://docs.pleroma.social/backend/development/API/pleroma_api/#get-apioauth_tokens}
|
||||||
*/
|
*/
|
||||||
getOauthTokens: () => this.#paginatedGet(
|
getOauthTokens: () => {
|
||||||
this.features.version.software === GOTOSOCIAL ? '/api/v1/tokens' : '/api/oauth_tokens',
|
let url;
|
||||||
{},
|
|
||||||
oauthTokenSchema,
|
switch (this.features.version.software) {
|
||||||
),
|
case GOTOSOCIAL:
|
||||||
|
url = '/api/v1/tokens';
|
||||||
|
break;
|
||||||
|
case MITRA:
|
||||||
|
url = '/api/v1/settings/sessions';
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
url = '/api/oauth_tokens';
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.#paginatedGet(url, {}, oauthTokenSchema);
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Revoke a user session by its ID
|
* Revoke a user session by its ID
|
||||||
@ -1494,6 +1506,9 @@ class PlApiClient {
|
|||||||
case GOTOSOCIAL:
|
case GOTOSOCIAL:
|
||||||
response = await this.request(`/api/v1/tokens/${oauthTokenId}/invalidate`, { method: 'POST' });
|
response = await this.request(`/api/v1/tokens/${oauthTokenId}/invalidate`, { method: 'POST' });
|
||||||
break;
|
break;
|
||||||
|
case MITRA:
|
||||||
|
response = await this.request(`/api/v1/settings/sessions/${oauthTokenId}`, { method: 'DELETE' });
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
response = await this.request(`/api/oauth_tokens/${oauthTokenId}`, { method: 'DELETE' });
|
response = await this.request(`/api/oauth_tokens/${oauthTokenId}`, { method: 'DELETE' });
|
||||||
break;
|
break;
|
||||||
|
|||||||
@ -9,6 +9,13 @@ import { datetimeSchema } from './utils';
|
|||||||
const oauthTokenSchema = v.pipe(
|
const oauthTokenSchema = v.pipe(
|
||||||
v.any(),
|
v.any(),
|
||||||
v.transform((token: any) => {
|
v.transform((token: any) => {
|
||||||
|
if (token.client_name) {
|
||||||
|
return {
|
||||||
|
...token,
|
||||||
|
app_name: token.client_name,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
if (token.application) {
|
if (token.application) {
|
||||||
return {
|
return {
|
||||||
...token,
|
...token,
|
||||||
@ -31,6 +38,7 @@ const oauthTokenSchema = v.pipe(
|
|||||||
valid_until: v.fallback(v.nullable(datetimeSchema), null),
|
valid_until: v.fallback(v.nullable(datetimeSchema), null),
|
||||||
last_used: v.fallback(v.nullable(datetimeSchema), null),
|
last_used: v.fallback(v.nullable(datetimeSchema), null),
|
||||||
scopes: v.fallback(v.array(v.string()), []),
|
scopes: v.fallback(v.array(v.string()), []),
|
||||||
|
is_current: v.fallback(v.nullable(v.boolean()), null),
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@ -1696,6 +1696,7 @@ const getFeatures = (instance: Instance) => {
|
|||||||
sessions: any([
|
sessions: any([
|
||||||
v.software === AKKOMA,
|
v.software === AKKOMA,
|
||||||
v.software === ICESHRIMP_NET,
|
v.software === ICESHRIMP_NET,
|
||||||
|
v.software === MITRA && gt(v.version, '4.13.1'),
|
||||||
v.software === PLEROMA,
|
v.software === PLEROMA,
|
||||||
v.software === GOTOSOCIAL && gte(v.version, '0.18.2'),
|
v.software === GOTOSOCIAL && gte(v.version, '0.18.2'),
|
||||||
]),
|
]),
|
||||||
|
|||||||
Reference in New Issue
Block a user