OpenPass Roku SDK
The OpenPass Roku SDK makes it easier to integrate OpenPass directly on your Roku channels.
Installation
ropm
The preferred installation method is via ropm
ropm install @openpass/openpass-roku-sdk
Manually
Copy openpass_openpassrokusdk
files inside your source folder
Requirements
In order to use this SDK you will need the following requirements
-
Install Node.JS from here
-
Install the Roku Package Manager node module globally
npm i ropm -g
-
Install BrighterScript module globally
npm install brighterscript -g
-
At project root level run
ropm install
-
Enable Developer Mode on you Roku device, you can see more here
-
In order to use npm scripts
to run the project locally, you will need to add the following ENV VARS to your system:
ROKU_HOST
: This is the IP Address of your Roku device.ROKU_DEV_PASSWORD
: This is the password you set for your Roku device when Developer Mode
was enabled.
To add the variables to your system for Mac or Linux:
-
If using zsh
as your shell
echo 'export ROKU_DEV_PASSWORD=<YOUR_DEVICE_PASSWORD>' >> ~/.zshrc
echo 'export ROKU_HOST=<YOUR_DEVICE_HOST_IP>' >> ~/.zshrc
-
If using bash
as your shell
echo 'export ROKU_DEV_PASSWORD=<YOUR_DEVICE_PASSWORD>' >> ~/.bash_profile
echo 'export ROKU_HOST=<YOUR_DEVICE_HOST_IP>' >> ~/.bash_profile
To add the variables to your system if using Windows
```bash
setx ROKU_DEV_PASSWORD "<YOUR_DEVICE_PASSWORD>"
setx ROKU_HOST "<ROKU_HOST>"
```
Usage
- Install the package via ropm
ropm install @openpass/openpass-roku-sdk
- You will need to create 2 tasks nodes that will allow for specify a functions to be spawned in a different thread, you can do that like the following example:
create a task for Authorize Device flow: tasks/AuthorizeDeviceTask.brs
sub Init()
m.top.functionName = "AuthorizeDevice"
end sub
sub AuthorizeDevice()
' Your client Id
clientId = "CLIENT_ID"
' Attach Device response from SDK, returning an object node that looks like:
'{
' device_code: "SOME_CODE_STRING"
' expires_in: 500 'Expiration time in seconds
' interval: 5 ' Polling interval in seconds
' user_code: "SOME_CODE_STRING"
' verification_uri: "https://myopenpass.com/code"
' verification_uri_complete: "https://myopenpass.com/code?user_code=WI9BFFAY"
'}
m.top.authDevice = openpass_openpassrokusdk_AuthorizeDevice(clientId)
end sub
and tasks/AuthorizeDeviceTask.xml
<?xml version="1.0" encoding="utf-8"?>
<component name="AuthorizeDeviceTask" extends="Task">
<interface>
<field id="authDevice" type="node" />
</interface>
<script type="text/brightscript"
uri="pkg:/source/roku_modules/openpass_openpassrokusdk/AuthorizeDeviceTask.brs" />
<script type="text/brightscript" uri="AuthorizeDeviceTask.brs" />
</component>
create a task for Authenticate Device flow: tasks/AuthenticateDeviceTask.brs
sub Init()
m.top.functionName = "CheckDeviceAuthenticated"
end sub
sub CheckDeviceAuthenticated()
' options = { polling_timeout: 200}
' options = { authenticate_url: "www.differenturl.com/authenticate", polling_timeout: 4000}
' options = { authenticate_url: "www.differenturl.com/authenticate", enable_polling: false}
' options = { enable_polling: false }
options = {}
result = openpass_openpassrokusdk_DeviceToken(m.top.clientId, m.top.deviceCode, options)
' The response will look like this
'{
' access_token: "SOME_LONG_STRING_WITH_AUTH_TOKEN"
' expires_in: 86400
' id_token: "SOME_LONG_STRING_WITH_ID_TOKEN"
' id_token_expires_in: 2592000
' refresh_token: "SOME_LONG_STRING_WITH_REFRESH_TOKEN"
' refresh_token_expires_in: 15552000
' token_type: "Bearer"
'}
m.top.authUser = result
end sub
and tasks/AuthenticateDeviceTask.xml
<?xml version="1.0" encoding="utf-8"?>
<component name="AuthenticateDeviceTask" extends="Task">
<interface>
<field id="authUser" type="node" />
</interface>
<script type="text/brightscript"
uri="pkg:/source/roku_modules/openpass_openpassrokusdk/AuthenticateDeviceTask.brs" />
<script type="text/brightscript" uri="AuthenticateDeviceTask.brs" />
</component>
- Implement your recently created tasks where you need:
sub DeviceAuthorization()
m.authTask = CreateObject("roSGNode", "AuthorizeDeviceTask")
m.authTask.ObserveField("authDevice", "OnAuthDeviceCompleted")
m.authTask.control = "run"
end sub
sub OnAuthDeviceCompleted()
' this will hold the response from AuthorizeDeviceTask and get you the user_code for the device
m.SigningScreen.authDevice = m.authTask.authDevice
' After we get the device authorization, we can start doing the polling
CheckAuthToken()
end sub
sub CheckAuthToken()
m.authenticateDeviceTask = CreateObject("roSGNode", "AuthenticateDeviceTask")
' attach device code to task
m.authenticateDeviceTask.addFields({
deviceCode: m.authTask.authDevice.device_code,
clientId: m.authTask.authDevice.client_id
})
m.authenticateDeviceTask.ObserveField("authUser", "OnAuthenticateTaskCompleted")
m.authenticateDeviceTask.control = "run"
end sub
sub OnAuthenticateTaskCompleted()
' Do what you need with the response
end sub
Development
The OpenPass SDK is a standalone headless library defined and managed by the Roku Package Manager. As such the OpenPass SDK
is the primary way for developing the SDK. Use VSCode to open openpass-roku-sdk
to begin development.
-
Start your dev Server: yarn start
or bsc --watch --deploy --host <YOUR_DEVICE_HOST_IP> --password <YOUR_DEVICE_PASSWORD>
-
Lint the project: yarn start
or bsc --create-package false --copy-to-staging false
Tests
See Tests README.
Generate Docs
Project Documentation
License
OpenPass is released under the MIT license. See LICENSE for details.