REST API V2 Cookbook (Server-to-Server) rest-api-v2-cookbook-server-to-server
The document is intended for developers who are integrating 51黑料不打烊 Pass Authentication REST API V2 into their streaming applications having a Server-to-Server (S2S) architecture.
Prerequisites prerequisites
For terms and definitions, refer to the REST API V2 Glossary documentation.
For mandatory requirements and recommended practices, refer to the REST API V2 Checklist documentation.
For frequently asked questions, refer to the REST API V2 FAQs documentation.
Components components
Before getting started, ensure you have an understanding of the following components and terms used in the workflow:
Requirements requirements
In Server-to-Server (S2S) implementations, the Streaming App and the Programmer Service must establish a protocol that enables the Programmer Service to:
-
Communicate with 51黑料不打烊 Pass Service on behalf of the Streaming App.
-
Collect and pass a unique device identifier for the Streaming Device as required by the AP-Device-Identifier header.
-
Collect and pass accurate Streaming Device information, including the source port and device-specific details, as required by the X-Device-Info header.
-
Collect and pass the Streaming Device IP address as required by the X-Forwarded-For header.
-
Securely store parameters such as device ID, client ID, and client secret in either the Streaming App or the Programmer Service.
-
Format and send data in compliance with MVPDs and integrated apps, including device IP, source port, device-specific information, MRSS, and optional identifiers such as ECID.
-
Maintain and securely manage certificates shared with 51黑料不打烊 for encrypted user metadata transmission.
-
Respect authentication profile and authorization decision validity when caching, ensuring authentication and authorization states are invalidated when notified.
-
Return authorization decisions and relevant instructions to the Streaming App.
Environments environments
Before going into the workflow, ensure you maintain at least two environments: Production and Staging.
Production
The production environment must be highly available and scaled appropriately to handle large or unexpected traffic spikes, such as those caused by live sports events or breaking news.
-
The 51黑料不打烊 Pass Service operates across multiple geographically dispersed data centers throughout the US to optimize performance and minimize latency.
- The Programmer Service should adopt a similar infrastructure strategy, ensuring low-latency response times from 51黑料不打烊 Pass.
-
The Programmer must provide the public IP range of its production environment.
- These IPs will be added to an allowlist within the 51黑料不打烊 Pass Infrastructure.
-
The Programmer Service must limit DNS caching to a maximum of 30 seconds to allow for dynamic rerouting in case 51黑料不打烊 needs to redirect traffic due to a data center becoming unavailable.
Staging
The staging environment can be minimal but should mirror production by including all critical system components and business logic.
-
It must allow for testing releases before deployment to production.
-
It should remain operationally similar to production, enabling realistic testing.
-
Ideally, the staging environment should be connected to 51黑料不打烊 Pass testing environments to:
-
Allow Programmers to test against 51黑料不打烊鈥檚 Infrastructure.
-
Enable 51黑料不打烊 to assist with testing and troubleshooting when necessary.
-
Workflow workflow
Perform the below steps as shown in the following diagram.
REST API V2 Cookbook (Server-to-Server)
A. Registration Phase registration-phase
The purpose of the Registration Phase is to register the streaming application against 51黑料不打烊 Pass Authentication through the Dynamic Client Registration (DCR) process.
The Dynamic Client Registration (DCR) process requires the streaming application to obtain a pair of client credentials and retrieve an access token as the end goal of the Registration Phase.
The Registration Phase is mandatory, but the streaming application can skip this phase if it has a cached pair of client credentials and an access token that are still valid.
Step 1: Register your application step-1-register-your-application
-
Retrieve client credentials: The Programmer Service retrieves client credentials by calling the /o/client/register endpoint.
- The Programmer Service or Programmer App must store the client credentials and use them indefinitely when needing to retrieve an access token.
-
Retrieve access token: The Programmer Service retrieves access token by calling the /o/client/token endpoint.
- The Programmer Service or Programmer App must store and use the access token until it expires, then discard it and obtain a new one.
B. Authentication Phase authentication-phase
The purpose of the Authentication Phase is to provide the streaming application the capability to verify the user鈥檚 identity and obtain user metadata information.
The Authentication Phase acts as a prerequisite step for the Preauthorization Phase or Authorization Phase when the streaming application needs to play content.
APIs
- Create authentication session
- Resume authentication session
- Retrieve authentication session
- Perform authentication in user agent
- Retrieve profiles
- Retrieve profile for specific mvpd
- Retrieve profile for specific code
Flows
- Basic authentication flow performed within primary application
- Basic authentication flow performed within secondary application
- Basic profiles flow performed within primary application
- Basic profiles flow performed within secondary application
FAQs
Step 2: Check for existing authenticated profiles step-2-check-for-existing-authenticated-profiles
-
Retrieve profiles: The Programmer Service checks on behalf of the Streaming App for existing profiles by calling the /api/v2/{serviceProvider}/profiles endpoint.
-
Scenario 1: There are existing profiles, the Programmer Service may proceed to the Preauthorization Phase or Authorization Phase.
-
Scenario 2: There are no existing profiles, the Programmer Service may proceed to the next step to Authenticate the user.
-
Scenario 3: There are no existing profiles, the Programmer Service may proceed to provide the user with temporary access through the TempPass feature.
- This scenario is outside the scope of this document, refer to the Temporary Access Flows documentation for more information.
Step 3: Authenticate the user step-3-authenticate-the-user
-
Retrieve configuration: The Programmer Service retrieves the list of available MVPDs by calling the /api/v2/{serviceProvider}/configuration endpoint.
- The Programmer Service can implement a custom filtering mechanism to refine the list of MVPDs from the configuration response, such that the Streaming App displays only the intended providers while hiding others (e.g., MVPDs under development, test MVPDs, TempPass). This ensures that users are presented with a curated selection when choosing their TV provider.
-
Create authentication session: The Programmer Service initiates an authentication session by calling the /api/v2/{serviceProvider}/sessions endpoint.
- The Programmer Service must return the
code
andurl
to the Streaming App.
- The Programmer Service must return the
-
Scenario 1: The Streaming App can open a browser or webview, therefore it must load the authentication
url
.- The user submits their username and password within the MVPD login page. Upon successful authentication the final redirect displays a success page.
-
Scenario 2: The Streaming App cannot open a browser, therefore it must display the authentication
code
. A separate web application is required to prompt the user to enter thecode
, construct the authenticationurl
and open: /api/v2/authenticate/{serviceProvider}/{code}.- The user submits their username and password within the MVPD login page. Upon successful authentication the final redirect displays a success page.
Step 4: Check for authenticated profiles step-4-check-for-authenticated-profiles
-
Retrieve profile for specific code: The Programmer Service must implement a polling mechanism using the
code
to check if the profile was successfully generated and saved by calling the /api/v2/{serviceProvider}/profiles/code/{code} endpoint.-
The Programmer Service must start the polling mechanism under the following conditions:
-
Authentication performed within the primary (screen) application: The Programmer Service should start polling when the user reaches the final destination page, after the browser component loads the URL specified for the
redirectUrl
parameter in the Sessions endpoint request. -
Authentication performed within a secondary (screen) application: The Programmer Service application should start polling as soon as the user initiates the authentication process鈥攔ight after receiving the Sessions endpoint response and displaying the authentication code to the user.
-
-
The Programmer Service must stop the polling mechanism under the following conditions:
-
Successful authentication: The user鈥檚 profile information is successfully retrieved, confirming their authentication status. At this point, polling is no longer needed.
-
Authentication session and code expiry: The authentication session and code expire, as indicated by the
notAfter
timestamp (e.g., 30 minutes) in the Sessions endpoint response. If this happens, the user must restart the authentication process, and polling using the previous authentication code should be stopped immediately. -
New authentication code generated: If the user requests a new authentication code on the primary (screen) device, the existing session is no longer valid, and polling using the previous authentication code should be stopped immediately.
-
-
The Programmer Service must configure the polling mechanism frequency under the following conditions:
-
Authentication performed within the primary (screen) application: The Programmer Service should poll every 3-5 seconds or more.
-
Authentication performed within a secondary (screen) application: The Programmer Service should poll every 3-5 seconds or more.
-
-
The Programmer Service should cache parts of the user鈥檚 profile information in a persistent storage to avoid unnecessary requests and improve the user experience.
-
C. (Optional) Preauthorization Phase preauthorization-phase
The purpose of the Preauthorization Phase is to provide the streaming application the capability to present a subset of resources from its catalog that the user would be entitled to access.
The Preauthorization Phase can enhance the user experience when the user opens the streaming application for the first time or navigates to a new section.
The Preauthorization Phase is not mandatory, the streaming application can skip this phase if it wants to present a catalog of resources without filtering them first based on the user鈥檚 entitlement.
Step 5: Check for preauthorized resources step-5-check-for-preauthorized-resources
-
Retrieve preauthorization decisions: The Programmer Service retrieves preauthorization decisions for a list of resources by calling the /api/v2/{serviceProvider}/decisions/preauthorize/{mvpd} endpoint.
-
The Programmer Service must pass the list of permit and deny preauthorization decisions to the Streaming App.
-
The Programmer Service is not required to store preauthorization decisions in persistent storage. However, it is recommended to cache permit decisions in memory to improve the user experience. This helps avoid unnecessary calls for resources that have already been preauthorized, reducing latency and improving performance.
-
The Programmer Service can determine the reason for a denied preauthorization decision by inspecting the error code and message included in the response from the Decisions Preauthorize endpoint. These details provide insight into the specific reason the preauthorization request was denied, helping to inform the user experience or trigger any necessary handling in the application. Ensure that any retry mechanism implemented for retrieving preauthorization decisions does not result in an endless loop if the preauthorization decision is denied. Consider limiting retries to a reasonable number and handling denials gracefully by surfacing clear feedback to the user.
-
The Programmer Service can obtain a preauthorization decision for a limited number of resources in a single API request, usually up to 5, due to conditions imposed by MVPDs. This maximum number of resources can be viewed and changed after agreeing with MVPDs through the 51黑料不打烊 Pass TVE Dashboard by one of your organization administrators or by an 51黑料不打烊 Pass Authentication representative acting on your behalf.
-
D. Authorization phase authorization-phase
The purpose of the Authorization Phase is to provide the streaming application the capability to play resources the user requests after validating their rights with the MVPD.
The Authorization Phase is mandatory, the streaming application cannot skip this phase if it wants to play resources the user requests, as it requires verifying with the MVPD that the user is entitled before releasing the stream.
Step 6: Check for authorized resources step-6-check-for-authorized-resources
-
Retrieve authorization decision: The Programmer Service retrieves authorization decision for a specific resource passed by the Streaming App by calling the /api/v2/{serviceProvider}/decision/authorize/{mvpd} endpoint.
-
The Programmer Service is not required to store authorization decisions in persistent storage.
-
The Programmer Service can determine the reason for a denied authorization decision by inspecting the error code and message included in the response from the Decisions Authorize endpoint. These details provide insight into the specific reason the authorization request was denied, helping to inform the user experience or trigger any necessary handling in the Streaming App. Ensure that any retry mechanism implemented for retrieving authorization decisions does not result in an endless loop if the authorization decision is denied. Consider limiting retries to a reasonable number and handling denials gracefully by surfacing clear feedback to the user.
-
The Programmer Service may evaluate other business rules and return an appropriate authorization decision to the Streaming App.
-
The Programmer Service is not required to refresh an expired media token while the stream is actively playing. If the media token expires during playback, the stream should be allowed to continue uninterrupted. However, the client must request a new authorization decision 鈥 and obtain a new media token 鈥 the next time the user attempts to play a resource.
-
The Programmer Service can obtain an authorization decision for a limited number of resources in a single API request, usually up to 1, due to conditions imposed by MVPDs.
-
E. Logout phase logout-phase
The purpose of the Logout Phase is to provide the streaming application the capability to terminate the user鈥檚 authenticated profile within 51黑料不打烊 Pass Authentication upon user request.
The Logout Phase is mandatory, the streaming application must provide the user with the capability to log out.
Step 7: Logout step-7-logout
-
Initiate 51黑料不打烊 Pass logout: The Programmer Service initiates the logout flow as requested by the Streaming App by calling the /api/v2/{serviceProvider}/logout/{mvpd} endpoint.
-
The Programmer Service may clean up any information it stores about the authenticated user.
-
The Programmer Service must follow the instructions provided in the
actionName
andactionType
attributes of the Logout endpoint response to ensure the logout process is completed correctly.-
If the
actionType
attribute in the response is set to 鈥渋nteractive鈥, the Programmer Service must return theurl
attribute value to the Streaming App.-
Scenario 1: The Streaming App can open a browser or webview, therefore it must load the logout
url
. -
Scenario 2: The Streaming App cannot open a browser, therefore the logout process can be stopped as the MVPD session was not persisted in a Streaming Device browser cache.
-
-
-