# Authentication (*authentication*) ## Overview API Calls regarding authentication for Plex Media Server ### Available Operations * [getTransientToken](#gettransienttoken) - Get a Transient Token * [getSourceConnectionInformation](#getsourceconnectioninformation) - Get Source Connection Information * [getTokenDetails](#gettokendetails) - Get Token Details * [postUsersSignInData](#postuserssignindata) - Get User Sign In Data ## getTransientToken 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. ### Example Usage ```typescript import { PlexAPI } from "@lukehagar/plexjs"; import { GetTransientTokenQueryParamType, Scope } from "@lukehagar/plexjs/sdk/models/operations"; const plexAPI = new PlexAPI({ accessToken: "", }); async function run() { const result = await plexAPI.authentication.getTransientToken(GetTransientTokenQueryParamType.Delegation, Scope.All); // Handle the result console.log(result); } run(); ``` ### Standalone function The standalone function version of this method: ```typescript import { PlexAPICore } from "@lukehagar/plexjs/core.js"; import { authenticationGetTransientToken } from "@lukehagar/plexjs/funcs/authenticationGetTransientToken.js"; import { GetTransientTokenQueryParamType, Scope } from "@lukehagar/plexjs/sdk/models/operations"; // Use `PlexAPICore` for best tree-shaking performance. // You can create one instance of it to use across an application. const plexAPI = new PlexAPICore({ accessToken: "", }); async function run() { const res = await authenticationGetTransientToken(plexAPI, GetTransientTokenQueryParamType.Delegation, Scope.All); if (!res.ok) { throw res.error; } const { value: result } = res; // Handle the result console.log(result); } run(); ``` ### Parameters | Parameter | Type | Required | Description | | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | | `type` | [operations.GetTransientTokenQueryParamType](../../sdk/models/operations/gettransienttokenqueryparamtype.md) | :heavy_check_mark: | `delegation` - This is the only supported `type` parameter. | | `scope` | [operations.Scope](../../sdk/models/operations/scope.md) | :heavy_check_mark: | `all` - This is the only supported `scope` parameter. | | `options` | RequestOptions | :heavy_minus_sign: | Used to set various options for making HTTP requests. | | `options.fetchOptions` | [RequestInit](https://developer.mozilla.org/en-US/docs/Web/API/Request/Request#options) | :heavy_minus_sign: | Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All `Request` options, except `method` and `body`, are allowed. | | `options.retries` | [RetryConfig](../../lib/utils/retryconfig.md) | :heavy_minus_sign: | Enables retrying HTTP requests under certain failure conditions. | ### Response **Promise\<[operations.GetTransientTokenResponse](../../sdk/models/operations/gettransienttokenresponse.md)\>** ### Errors | Error Type | Status Code | Content Type | | ------------------------------------ | ------------------------------------ | ------------------------------------ | | errors.GetTransientTokenBadRequest | 400 | application/json | | errors.GetTransientTokenUnauthorized | 401 | application/json | | errors.SDKError | 4XX, 5XX | \*/\* | ## getSourceConnectionInformation 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. ### Example Usage ```typescript import { PlexAPI } from "@lukehagar/plexjs"; const plexAPI = new PlexAPI({ accessToken: "", }); async function run() { const result = await plexAPI.authentication.getSourceConnectionInformation("provider://provider-identifier"); // Handle the result console.log(result); } run(); ``` ### Standalone function The standalone function version of this method: ```typescript import { PlexAPICore } from "@lukehagar/plexjs/core.js"; import { authenticationGetSourceConnectionInformation } from "@lukehagar/plexjs/funcs/authenticationGetSourceConnectionInformation.js"; // Use `PlexAPICore` for best tree-shaking performance. // You can create one instance of it to use across an application. const plexAPI = new PlexAPICore({ accessToken: "", }); async function run() { const res = await authenticationGetSourceConnectionInformation(plexAPI, "provider://provider-identifier"); if (!res.ok) { throw res.error; } const { value: result } = res; // Handle the result console.log(result); } run(); ``` ### Parameters | Parameter | Type | Required | Description | Example | | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | | `source` | *string* | :heavy_check_mark: | The source identifier with an included prefix. | [object Object] | | `options` | RequestOptions | :heavy_minus_sign: | Used to set various options for making HTTP requests. | | | `options.fetchOptions` | [RequestInit](https://developer.mozilla.org/en-US/docs/Web/API/Request/Request#options) | :heavy_minus_sign: | Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All `Request` options, except `method` and `body`, are allowed. | | | `options.retries` | [RetryConfig](../../lib/utils/retryconfig.md) | :heavy_minus_sign: | Enables retrying HTTP requests under certain failure conditions. | | ### Response **Promise\<[operations.GetSourceConnectionInformationResponse](../../sdk/models/operations/getsourceconnectioninformationresponse.md)\>** ### Errors | Error Type | Status Code | Content Type | | ------------------------------------------------- | ------------------------------------------------- | ------------------------------------------------- | | errors.GetSourceConnectionInformationBadRequest | 400 | application/json | | errors.GetSourceConnectionInformationUnauthorized | 401 | application/json | | errors.SDKError | 4XX, 5XX | \*/\* | ## getTokenDetails Get the User data from the provided X-Plex-Token ### Example Usage ```typescript import { PlexAPI } from "@lukehagar/plexjs"; const plexAPI = new PlexAPI({ accessToken: "", }); async function run() { const result = await plexAPI.authentication.getTokenDetails(); // Handle the result console.log(result); } run(); ``` ### Standalone function The standalone function version of this method: ```typescript import { PlexAPICore } from "@lukehagar/plexjs/core.js"; import { authenticationGetTokenDetails } from "@lukehagar/plexjs/funcs/authenticationGetTokenDetails.js"; // Use `PlexAPICore` for best tree-shaking performance. // You can create one instance of it to use across an application. const plexAPI = new PlexAPICore({ accessToken: "", }); async function run() { const res = await authenticationGetTokenDetails(plexAPI); if (!res.ok) { throw res.error; } const { value: result } = res; // Handle the result console.log(result); } run(); ``` ### Parameters | Parameter | Type | Required | Description | | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | | `options` | RequestOptions | :heavy_minus_sign: | Used to set various options for making HTTP requests. | | `options.fetchOptions` | [RequestInit](https://developer.mozilla.org/en-US/docs/Web/API/Request/Request#options) | :heavy_minus_sign: | Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All `Request` options, except `method` and `body`, are allowed. | | `options.retries` | [RetryConfig](../../lib/utils/retryconfig.md) | :heavy_minus_sign: | Enables retrying HTTP requests under certain failure conditions. | | `options.serverURL` | *string* | :heavy_minus_sign: | An optional server URL to use. | ### Response **Promise\<[operations.GetTokenDetailsResponse](../../sdk/models/operations/gettokendetailsresponse.md)\>** ### Errors | Error Type | Status Code | Content Type | | ---------------------------------- | ---------------------------------- | ---------------------------------- | | errors.GetTokenDetailsBadRequest | 400 | application/json | | errors.GetTokenDetailsUnauthorized | 401 | application/json | | errors.SDKError | 4XX, 5XX | \*/\* | ## postUsersSignInData Sign in user with username and password and return user data with Plex authentication token ### Example Usage ```typescript import { PlexAPI } from "@lukehagar/plexjs"; const plexAPI = new PlexAPI(); async function run() { const result = await plexAPI.authentication.postUsersSignInData({ clientID: "3381b62b-9ab7-4e37-827b-203e9809eb58", clientName: "Plex for Roku", deviceNickname: "Roku 3", clientVersion: "2.4.1", platform: "Roku", requestBody: { login: "username@email.com", password: "password123", verificationCode: "123456", }, }); // Handle the result console.log(result); } run(); ``` ### Standalone function The standalone function version of this method: ```typescript import { PlexAPICore } from "@lukehagar/plexjs/core.js"; import { authenticationPostUsersSignInData } from "@lukehagar/plexjs/funcs/authenticationPostUsersSignInData.js"; // Use `PlexAPICore` for best tree-shaking performance. // You can create one instance of it to use across an application. const plexAPI = new PlexAPICore(); async function run() { const res = await authenticationPostUsersSignInData(plexAPI, { clientID: "3381b62b-9ab7-4e37-827b-203e9809eb58", clientName: "Plex for Roku", deviceNickname: "Roku 3", clientVersion: "2.4.1", platform: "Roku", requestBody: { login: "username@email.com", password: "password123", verificationCode: "123456", }, }); if (!res.ok) { throw res.error; } const { value: result } = res; // Handle the result console.log(result); } run(); ``` ### Parameters | Parameter | Type | Required | Description | | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | | `request` | [operations.PostUsersSignInDataRequest](../../sdk/models/operations/postuserssignindatarequest.md) | :heavy_check_mark: | The request object to use for the request. | | `options` | RequestOptions | :heavy_minus_sign: | Used to set various options for making HTTP requests. | | `options.fetchOptions` | [RequestInit](https://developer.mozilla.org/en-US/docs/Web/API/Request/Request#options) | :heavy_minus_sign: | Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All `Request` options, except `method` and `body`, are allowed. | | `options.retries` | [RetryConfig](../../lib/utils/retryconfig.md) | :heavy_minus_sign: | Enables retrying HTTP requests under certain failure conditions. | | `options.serverURL` | *string* | :heavy_minus_sign: | An optional server URL to use. | ### Response **Promise\<[operations.PostUsersSignInDataResponse](../../sdk/models/operations/postuserssignindataresponse.md)\>** ### Errors | Error Type | Status Code | Content Type | | -------------------------------------- | -------------------------------------- | -------------------------------------- | | errors.PostUsersSignInDataBadRequest | 400 | application/json | | errors.PostUsersSignInDataUnauthorized | 401 | application/json | | errors.SDKError | 4XX, 5XX | \*/\* |