Verifying Roku Requests
InitClientCertificates() and GetDeviceAttestation() let your backend verify that the request is from a genuine Roku device.
They do not replace user login, subscription checks, or ordinary HTTPS server-certificate verification.
| API | What it supplies | Where verification happens |
|---|---|---|
InitClientCertificates() |
Roku’s built-in client certificate | In your backend’s TLS layer |
GetDeviceAttestation(nonce) |
A JWT signed in the Roku cloud | In your backend’s HTTP request handling |
with InitClientCertificates() — deprecated
The function sets Roku’s client certificate on the request. Mutual TLS (mTLS) handles connection verification.
⚠️ Deprecation Notice
Apps must remove InitClientCertificates() by April 1, 2027
- Roku will block publishing apps that use it.
- But you don’t need to add JWT checking if you don’t verify requests as coming from Roku.
- (it is recommended to verify requests though)
Frequently Asked Questions
How does it work?
- The server requests verification with the public Roku client certificate.
- The client proves possession of the certificate’s private key during the handshake.
- Copying the public certificate is not enough to authenticate another connection.
- The app does not need to implement its own nonce for this connection verification because it is performed on every connection.
What if my backend doesn't do anything?
If your backend does not verify the Roku client certificate, then calling InitClientCertificates() provides no security benefit.
Without an enforced Roku authenticity check, the backend cannot verify whether a request:
- came from a genuine Roku device/app
- or came from someone imitating its requests
Do I still need to call SetCertificatesFile()?
Yes. Roku’s documentation states that it is required for HTTPS requests with roUrlTransfer.
Despite the similar name, it covers the opposite direction:
InitClientCertificates()lets your server verify the Roku client.SetCertificatesFile()lets the Roku app verify your HTTPS server.
On OS 16 (tested on a Roku Ultra, OS 16.0.4)
- Without calling
SetCertificatesFile(), the device still verifies servers against its built-in public CA store, which was the same ascommon:/certs/ca-bundle.crt.- The call replaces that store rather than adding to it.
Example Code
app.brs
req = CreateObject("roUrlTransfer")
prepareRequest(req)
// Verify our server's HTTPS certificate.
req.SetCertificatesFile("common:/certs/ca-bundle.crt")
// Supply Roku's package Dev ID and client certificate.
req.AddHeader("x-roku-reserved-dev-id", "")
req.InitClientCertificates()
sendRequest(req)
server.js
// Add these options to our existing HTTPS server configuration.
configureHTTPS({
ca: ROKU_CLIENT_CA, // the trusted Roku client-certificate CA
requestCert: true, // requests the client's certificate
rejectUnauthorized: false
})
onRequest('/feed', (req) => {
// TLS checked the certificate; handler decides to reject it
if (!req.socket.authorized) return reject()
// (optional) make sure the request came from your dev id
if (req.headers['x-roku-reserved-dev-id'] !== ROKU_APP_DEV_ID) {
return reject()
}
return serveFeed()
})
with GetDeviceAttestation(nonce)
This function returns a signed JWT from the Roku Cloud that contains attestation data.
Frequently Asked Questions
How does it work?
- Your app asks Roku Cloud for a signed JWT that contains the App’s identity.
- Your app then forwards the signed attestation JWT to your backend.
- Your backend verifies the signature
- (optionally) checks the signed app/developer identifiers.
What is a JWT?
A JSON Web Token (JWT) contains claims: data such as an issuer, expiration time, app ID, and nonce.
Standard JWT’s are structured: HEADER.PAYLOAD.SIGNATURE
- each part is base-64 encoded.
- the header and payload are encoded, not encrypted. Anybody with the JWT can decode and read the data without a key.
What makes a JWT secure?
The signature is cryptographically signed over the preceding HEADER.PAYLOAD string.
- Roku signs with a private key.
- The backend verifies it using a trusted Roku public key.
- Because the signature is made using the header and payload, those details cannot be changed without invalidating the signature. That is what makes this secure, even while the data is all readable.
What is the nonce for?
A nonce is a value intended to be used once. In this tutorial, it is a fresh random string supplied to Roku’s attestation API.
Any signed JWT can be copied and replayed while it remains valid.
- The signature prevents modification; it does not prevent copying.
- Because the nonce is inside of the signed payload, an attacker cannot change it without invalidating the signature.
When the backend handles a JWT with a nonce, it should store the nonce and reject re-use of the nonce value until the JWT has expired.
Example Code
Roku Cloud createDeviceAttestation.js
Roku documents that the final JWT is generated and signed in its cloud.
The following explains the signing operation; it is not Roku’s implementation source.
- The app supplies only the nonce to
GetDeviceAttestation(). - Roku supplies the app/developer context and token metadata.
function createDeviceAttestationToken(req, nonce) {
const payload = {
'x-roku-attestation-data': {
nonce: nonce,
channelId: req.header['x-roku-reserved-channel-id'],
developerId: req.header['x-roku-reserved-dev-id'],
timestampMs: Date.now()
}
}
const data = [
toBase64Url(JSON.stringify(req.header)),
toBase64Url(JSON.stringify(payload))
].join('.')
const signature = sign({
algorithm: 'RSA',
hash: 'SHA-256',
key: ROKU_PRIVATE_JWT_KEY,
data: data
})
return data + '.' + toBase64Url(signature)
}
The example represents Roku’s trusted app context with constants rather than asserting a specific internal transport.
- Roku documents reserved HTTP headers, including
x-roku-reserved-channel-idfor Continue Watching andx-roku-reserved-dev-idin its HTTP API.- The documentation does not establish whether the attestation cloud service uses those headers to populate its JWT claims, or how it authenticates the internal device-to-cloud request.
app.brs
// Helper: generate a fresh random nonce.
nonce = GetRandomHexString(16)
store = CreateObject('roChannelStore')
token = store.GetDeviceAttestation(nonce)
req = CreateObject('roUrlTransfer')
prepareRequest(req)
// Still verify server's HTTPS certificate.
req.SetCertificatesFile('common:/certs/ca-bundle.crt')
// Set the attestation data for our own API.
// This can be under any header key.
req.AddHeader('x-roku-attestation-data', token)
sendRequest(req)
server.js
onRequest('/feed', (req) => {
token = req.headers['x-roku-attestation-data']
// validate the signing certificate's trust
payload = verifyRokuJWT(token, ROKU_ATTESTATION_CERT)
if (!payload) return reject()
claims = payload['x-roku-attestation-data']
if (!claims || !claims.nonce) return reject()
// reject invalid tokens rather than merely decoding them.
// they should match the signed token's actual app/developer identifiers.
if (claims.channelId !== ROKU_APP_ID) return reject()
if (claims.developerId !== ROKU_DEVELOPER_ID) return reject()
// shared store: atomically record first use and reject duplicates.
// payload.exp is the standard JWT expiration field, in Unix seconds.
if (!recordNonceOnce(claims.nonce, payload.exp)) return reject()
return serveFeed()
})
