12 KiB
Authentication
Overview
API Calls regarding authentication for Plex Media Server
Available Operations
- getTransientToken - Get a Transient Token
- getSourceConnectionInformation - Get Source Connection Information
- getTokenDetails - Get Token Details
- 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
declare(strict_types=1);
require 'vendor/autoload.php';
use LukeHagar\Plex_API;
use LukeHagar\Plex_API\Models\Components;
use LukeHagar\Plex_API\Models\Operations;
$security = new Components\Security(
accessToken: "<YOUR_API_KEY_HERE>",
);
$sdk = Plex_API\PlexAPI::builder()
->setClientID('gcgzw5rz2xovp84b4vha3a40')
->setClientName('Plex Web')
->setClientVersion('4.133.0')
->setClientPlatform('Chrome')
->setDeviceName('Linux')
->setSecurity($security)->build();
try {
$response = $sdk->authentication->getTransientToken(Operations\GetTransientTokenQueryParamType::Delegation, Operations\Scope::All);
if ($response->statusCode === 200) {
// handle response
}
} catch (Throwable $e) {
// handle exception
}
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
type |
Operations\GetTransientTokenQueryParamType | ✔️ | delegation - This is the only supported type parameter. |
scope |
Operations\Scope | ✔️ | all - This is the only supported scope parameter. |
Response
?Operations\GetTransientTokenResponse
Errors
| Error Object | Status Code | Content Type |
|---|---|---|
| Errors\GetTransientTokenBadRequest | 400 | application/json |
| Errors\GetTransientTokenUnauthorized | 401 | application/json |
| LukeHagar\Plex_API\Models\Errors.SDKException | 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
declare(strict_types=1);
require 'vendor/autoload.php';
use LukeHagar\Plex_API;
use LukeHagar\Plex_API\Models\Components;
$security = new Components\Security(
accessToken: "<YOUR_API_KEY_HERE>",
);
$sdk = Plex_API\PlexAPI::builder()
->setClientID('gcgzw5rz2xovp84b4vha3a40')
->setClientName('Plex Web')
->setClientVersion('4.133.0')
->setClientPlatform('Chrome')
->setDeviceName('Linux')
->setSecurity($security)->build();
try {
$response = $sdk->authentication->getSourceConnectionInformation('provider://provider-identifier');
if ($response->statusCode === 200) {
// handle response
}
} catch (Throwable $e) {
// handle exception
}
Parameters
| Parameter | Type | Required | Description | Example |
|---|---|---|---|---|
source |
string | ✔️ | The source identifier with an included prefix. | server://client-identifier |
Response
?Operations\GetSourceConnectionInformationResponse
Errors
| Error Object | Status Code | Content Type |
|---|---|---|
| Errors\GetSourceConnectionInformationBadRequest | 400 | application/json |
| Errors\GetSourceConnectionInformationUnauthorized | 401 | application/json |
| LukeHagar\Plex_API\Models\Errors.SDKException | 4xx-5xx | / |
getTokenDetails
Get the User data from the provided X-Plex-Token
Example Usage
declare(strict_types=1);
require 'vendor/autoload.php';
use LukeHagar\Plex_API;
use LukeHagar\Plex_API\Models\Components;
$security = new Components\Security(
accessToken: "<YOUR_API_KEY_HERE>",
);
$sdk = Plex_API\PlexAPI::builder()
->setClientID('gcgzw5rz2xovp84b4vha3a40')
->setClientName('Plex Web')
->setClientVersion('4.133.0')
->setClientPlatform('Chrome')
->setDeviceName('Linux')
->setSecurity($security)->build();
try {
$response = $sdk->authentication->getTokenDetails();
if ($response->userPlexAccount !== null) {
// handle response
}
} catch (Throwable $e) {
// handle exception
}
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
$serverURL |
string | ➖ | An optional server URL to use. |
Response
?Operations\GetTokenDetailsResponse
Errors
| Error Object | Status Code | Content Type |
|---|---|---|
| Errors\GetTokenDetailsBadRequest | 400 | application/json |
| Errors\GetTokenDetailsUnauthorized | 401 | application/json |
| LukeHagar\Plex_API\Models\Errors.SDKException | 4xx-5xx | / |
postUsersSignInData
Sign in user with username and password and return user data with Plex authentication token
Example Usage
declare(strict_types=1);
require 'vendor/autoload.php';
use LukeHagar\Plex_API;
use LukeHagar\Plex_API\Models\Operations;
$sdk = Plex_API\PlexAPI::builder()
->setClientID('gcgzw5rz2xovp84b4vha3a40')
->setClientName('Plex Web')
->setClientVersion('4.133.0')
->setClientPlatform('Chrome')
->setDeviceName('Linux')
->build();
try {
$request = new Operations\PostUsersSignInDataRequestBody(
login: 'username@email.com',
password: 'password123',
verificationCode: '123456',
);
$response = $sdk->authentication->postUsersSignInData($request);
if ($response->userPlexAccount !== null) {
// handle response
}
} catch (Throwable $e) {
// handle exception
}
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
$request |
Operations\PostUsersSignInDataRequestBody | ✔️ | The request object to use for the request. |
$serverURL |
string | ➖ | An optional server URL to use. |
Response
?Operations\PostUsersSignInDataResponse
Errors
| Error Object | Status Code | Content Type |
|---|---|---|
| Errors\PostUsersSignInDataBadRequest | 400 | application/json |
| Errors\PostUsersSignInDataUnauthorized | 401 | application/json |
| LukeHagar\Plex_API\Models\Errors.SDKException | 4xx-5xx | / |