Introduction
This guide demonstrates the authentication and authorization process for Camera to Cloud (C2C) devices on a Frame.io project. We'll explore both the standard manual code entry method and the enhanced QR code pairing approach for optimal user experience.
What Will I Need?
Please review the Before We Start Implementing guide if you haven't already.
You should have received a client_secret
from our team to identify your integration. If not, please consult this introduction to the C2C ecosystem and contact our team.
Prerequisites for URL & QR Code Pairing
To implement URL & QR code pairing, ensure you meet these requirements:
- Device Compatibility: Verify your device supports URL/QR code generation during the pairing process.
Walking Through the Auth Flow
To understand the authorization flow from a user perspective, please reference these resources:
- Support Article for adding new devices.
- Training video on authorizing a Teradek Cube.
This authorization process minimizes implementation requirements. You won't need to:
- Redirect to web browsers (unless using URL Code Pairing)
- Handle Frame.io user authentication
- Present account/project selection interfaces
- Develop complex UI components beyond basic information displays
Enhancing the User Experience with URL Code Pairing
Modern users expect efficient device interactions. While the current manual pairing process functions adequately, it can be optimized.
By implementing URL & QR code pairing—similar to streaming services like Netflix or Disney+—we can significantly streamline the process, minimize input errors, and reduce pairing time.
Device Identification (client_id)
Each physical device requires a unique identifier for connection tracking within a user's project.
For devices, this identifier is the client_id
, which is essential during authorization. When implementing, consider appropriate identifier sources such as device serial numbers, UUIDs, or other unique strings. If you are integrating on an Apple device, we recommend using a unique persistent UUID that is consistent across device reboots.
Exercise caution regarding personally identifiable information. User email addresses are not appropriate client_id
values.
Additionally, ensure you control the identifier. Device MAC addresses are unsuitable as they aren't owned by your software and may constitute personally identifiable information.
If you need guidance on selecting an appropriate identifier, our team can assist in determining a suitable value that simplifies integration.
Step 1: Requesting a Device Code
To begin implementation, request a device code through the /v2/auth/device/code
endpoint:
Traditional Pairing Method
curl -X POST https://api.frame.io/v2/auth/device/code \
--form 'client_id=[client_id]' \
--form 'client_secret=[client_secret]' \
--form 'scope=asset_create offline' \
| python -m json.tool
Enabling URL Code Pairing
For URL code pairing, modify the API call with additional headers:
curl -X POST https://api.frame.io/v2/auth/device/code \
--header "x-client-version: 2.0.0" \
--header "x-client-platypus-enabled: true" \ # New header to enable URL pairing
--form 'client_id=[client_id]' \
--form 'client_secret=[client_secret]' \
--form 'scope=asset_create offline' \
| python -m json.tool
Note: These authentication endpoints accept form data exclusively, not JSON. Post-authentication, other endpoints will accept JSON payloads, but authentication endpoints will reject JSON requests.
Payload Parameters
- client_id: The unique identifier for your physical device. This must be guaranteed unique, such as a serial number or UUID.
- client_secret: Provided by Frame.io support to identify your device model. This confidential value should remain protected from users and encrypted when stored.
-
scope: The requested permissions, separated by spaces. Devices may request:
asset_create
: Enables asset creation and uploading.offline
: Permits authorization refreshing via refresh token. Without this scope, users would need to re-authorize their device every 8 hours as authorization tokens expire.
In practical implementations, devices typically request both scopes.
Understanding the API Response
The request generates a response similar to:
Traditional Pairing Response
{
"device_code": "[device_code]",
"expires_in": 120,
"interval": 5,
"name": "MyDevice-[client_id]",
"user_code": "573131"
}
URL Pairing Response
{
"device_code": "[device_code]",
"expires_in": 120,
"interval": 5,
"name": "MyDevice-[client_id]",
"user_code": "573131",
"verification_uri": "https://next.frame.io/pair",
"verification_uri_complete": "https://next.frame.io/pair/573131"
}
Response Breakdown
- device_code: This internal identifier should remain hidden from users and identifies the authorization request during polling.
- expires_in: The code's validity period in seconds.
- interval: The recommended polling interval in seconds.
- name: The connecting device's identifier.
- user_code: The six-digit code for manual entry into Frame.io for device pairing.
- verification_uri: The base URL for manual entry if QR scanning is unavailable.
- verificationuricomplete: The full URL containing the pairing code, intended for hyperlinking within a mobile app or QR code generation to streamline user navigation to the pairing interface.
Putting the Steps Together
Now let's implement these API calls in Python-like pseudocode, handling potential device code expiration:
def authorize_with_frame():
"""
Handles authorizing our device with Frame.io.
"""
# Our client ID can be a serial number, UUID, or some other unique string.
client_id = THIS_DEVICE.get_serial_number()
while True:
# Make the call to Frame.io to get our device codes.
pairing_codes = c2c.get_device_codes(client_id)
# We need to keep track of how long we have been polling for
polling_started = datetime.now()
# Now we are going to poll for authorization until the user enters the code.
while True:
# Re-write this output each time we poll. Note: This message will only update once
# per `interval` (e.g., 5 seconds), so if a smooth countdown is desired, that will
# need a different implementation.
print(
f"\rPAIRING CODE: {pairing_codes.user_code}, "
f"EXPIRES IN: {pairing_codes.expires_in - (datetime.now() - polling_started).seconds} seconds"
)
# Wait for `interval` before polling each time.
sleep(pairing_codes.interval)
# Make a call to Frame.io to see if the user has entered the code and authorized
# the device.
authorization, error = c2c.poll_for_authorization(
client_id, pairing_codes.device_code
)
if error and error.message == "authorization_pending":
# If the authorization is pending, try again.
continue
elif error and error.message == "expired_token":
# If the pairing codes have expired, break to generate new codes.
break
elif error:
# If there was some other error, raise it.
raise error
else:
# If there was no error, we have our authorization!
return authorization
# If we get here, our pairing codes expired. Let's try again.
print("\nPairing code expired. Generating a new one...")
Note: The outer loop handles cases where pairing codes expire and new codes are required.
As a final step, retrieve and display project information from Frame.io to confirm successful pairing to the intended project. We'll cover this in the next tutorial.
Best Practices for QR Code Display
When implementing QR code pairing, consider these guidelines for the best user experience:
- Optimal Size: Display QR codes at least 200-250 pixels square for reliable scanning.
- Contrast: Ensure high contrast between QR code and background (black on white is ideal).
- Error Correction: Use moderate error correction levels (L or M) to balance code density and reliability.
- Clear Instructions: Provide clear guidance on how to scan the code, such as "Scan this code with your smartphone camera to pair your device."
-
Multiple Options: Always provide the manual pairing code alongside the QR code as a fallback:
Scan to pair: [QR CODE] Or enter code manually: 573131
- Hyperlink for Mobile Apps: If your integration is a mobile application, include the
verification_uri_complete
as a tappable link since users cannot scan a QR code from the same device. - Testing: Test your QR codes with various devices and lighting conditions to ensure reliable scanning.
Troubleshooting
If you encounter issues, consult these common scenarios and solutions:
-
"Connect Device" Button Not Visible: When accessing the C2C management panel, this could indicate:
- Insufficient Permissions: If you see a permissions message, contact your account manager to adjust permissions or assign an appropriate role.
- Existing Device Connection: After connecting one device, the primary "Add New Device" button is replaced by a three-dot menu in the upper-right corner of the C2C Connections panel.
- Invalid Client Error: An
invalid_client
response indicates device information mismatch, typically due to an incorrectclient_secret
. - Bad Request Error: A
bad_request
response indicates malformed request data. Verify field names and ensure all required fields are included.
If your issue isn't addressed here, please share your experience so we can enhance this troubleshooting section.