mirror of
https://github.com/sct/overseerr.git
synced 2025-09-17 17:24:35 +02:00
feat(api): initial implementation of the auth system (#30)
Adds the auth system but does not add all required features. They will be handled in other tickets
This commit is contained in:
62
server/api/plextv.ts
Normal file
62
server/api/plextv.ts
Normal file
@@ -0,0 +1,62 @@
|
||||
import axios, { AxiosInstance } from 'axios';
|
||||
|
||||
interface PlexAccountResponse {
|
||||
user: PlexUser;
|
||||
}
|
||||
|
||||
interface PlexUser {
|
||||
id: number;
|
||||
uuid: string;
|
||||
email: string;
|
||||
joined_at: string;
|
||||
username: string;
|
||||
title: string;
|
||||
thumb: string;
|
||||
hasPassword: boolean;
|
||||
authToken: string;
|
||||
subscription: {
|
||||
active: boolean;
|
||||
status: string;
|
||||
plan: string;
|
||||
features: string[];
|
||||
};
|
||||
roles: {
|
||||
roles: string[];
|
||||
};
|
||||
entitlements: string[];
|
||||
}
|
||||
|
||||
class PlexTvAPI {
|
||||
private authToken: string;
|
||||
private axios: AxiosInstance;
|
||||
|
||||
constructor(authToken: string) {
|
||||
this.authToken = authToken;
|
||||
this.axios = axios.create({
|
||||
baseURL: 'https://plex.tv',
|
||||
headers: {
|
||||
'X-Plex-Token': this.authToken,
|
||||
'Content-Type': 'application/json',
|
||||
Accept: 'application/json',
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
public async getUser(): Promise<PlexUser> {
|
||||
try {
|
||||
const account = await this.axios.get<PlexAccountResponse>(
|
||||
'/users/account.json'
|
||||
);
|
||||
|
||||
return account.data.user;
|
||||
} catch (e) {
|
||||
console.error(
|
||||
'Something broke when getting account from plex.tv',
|
||||
e.message
|
||||
);
|
||||
throw new Error('Invalid auth token');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default PlexTvAPI;
|
Reference in New Issue
Block a user