mirror of
https://github.com/LukeHagar/plexjs.git
synced 2025-12-06 12:37:46 +00:00
84 lines
2.9 KiB
TypeScript
84 lines
2.9 KiB
TypeScript
import BaseService from '../../BaseService';
|
|
|
|
import Response from '../../http/Response';
|
|
|
|
import { SecurityType } from './models/SecurityType';
|
|
import { Scope } from './models/Scope';
|
|
|
|
import { serializeQuery } from '../../http/QuerySerializer';
|
|
|
|
export class SecurityService extends BaseService {
|
|
/**
|
|
* @summary Get a Transient Token.
|
|
* @description This endpoint provides the caller with a temporary token with the same access level as the caller's token. These tokens are valid for up to 48 hours and are destroyed if the server instance is restarted.
|
|
|
|
|
|
* @param type_ `delegation` - This is the only supported `type` parameter.
|
|
* @param scope `all` - This is the only supported `scope` parameter.
|
|
* @returns {Promise<any>} - The promise with the result
|
|
*/
|
|
async getTransientToken(type_: SecurityType, scope: Scope): Promise<any> {
|
|
if (type_ === undefined || scope === undefined) {
|
|
throw new Error(
|
|
'The following are required parameters: type_,scope, cannot be empty or blank',
|
|
);
|
|
}
|
|
const queryParams: string[] = [];
|
|
if (type_) {
|
|
queryParams.push(serializeQuery('form', true, 'type', type_));
|
|
}
|
|
if (scope) {
|
|
queryParams.push(serializeQuery('form', true, 'scope', scope));
|
|
}
|
|
const urlEndpoint = '/security/token';
|
|
const finalUrl = encodeURI(`${this.baseUrl + urlEndpoint}?${queryParams.join('&')}`);
|
|
const response: any = await this.httpClient.get(
|
|
finalUrl,
|
|
{},
|
|
{
|
|
...this.getAuthorizationHeader(),
|
|
},
|
|
true,
|
|
);
|
|
const responseModel = {
|
|
data: response.data,
|
|
headers: response.headers,
|
|
};
|
|
return responseModel;
|
|
}
|
|
|
|
/**
|
|
* @summary Get Source Connection Information
|
|
* @description If a caller requires connection details and a transient token for a source that is known to the server, for example a cloud media provider or shared PMS, then this endpoint can be called. This endpoint is only accessible with either an admin token or a valid transient token generated from an admin token.
|
|
Note: requires Plex Media Server >= 1.15.4.
|
|
|
|
|
|
* @param source The source identifier with an included prefix.
|
|
* @returns {Promise<any>} - The promise with the result
|
|
*/
|
|
async getSourceConnectionInformation(source: string): Promise<any> {
|
|
if (source === undefined) {
|
|
throw new Error('The following parameter is required: source, cannot be empty or blank');
|
|
}
|
|
const queryParams: string[] = [];
|
|
if (source) {
|
|
queryParams.push(serializeQuery('form', true, 'source', source));
|
|
}
|
|
const urlEndpoint = '/security/resources';
|
|
const finalUrl = encodeURI(`${this.baseUrl + urlEndpoint}?${queryParams.join('&')}`);
|
|
const response: any = await this.httpClient.get(
|
|
finalUrl,
|
|
{},
|
|
{
|
|
...this.getAuthorizationHeader(),
|
|
},
|
|
true,
|
|
);
|
|
const responseModel = {
|
|
data: response.data,
|
|
headers: response.headers,
|
|
};
|
|
return responseModel;
|
|
}
|
|
}
|