The key to registration and linking is to save a "deviceToken" in the registry for your Roku application on the Roku box. This deviceToken is mapped to a user account on your web server, so that when your Roku application send urls with this deviceToken your web server can customize responses according to the user account mapped to that deviceToken.
The regCode in Rendezvou style registration enables the assignment of this deviceToken dynamically so that a factory reset on the Roku box will delete the registry for you application and the deviceToken stored in it. This way a user is assured that no private data is passed on through a factory reset. This protection of private data is the reason Roku does NOT recommend storing Roku box serial numbers on your website.
The Device Registration and Linking guide walks you through an example message flow between your Roku channel app and your web server. The "registration" sdk example shows you an example Roku channel app implementation. The server side implemenation will be unique to your website with the objective of mapping a deviceToken to a user account.
Some example psuedo code for the web server piece:
http://yourserver.com/restfulUrl/preLinkhttp://yourserver.com/restfulUrl/linkAccountpreLink: (Called by your Roku DVP App)
------------------------------------------
<% deviceID=Request.deviceID;
regCode=CreateUniqueRegCode();
GlobalAssociativeArray[regCode] = "Not Activated";
response='<result>
<status>success</status>
<regCode>'
+regCode+'
</regCode>
<retryInterval> 30 </retryInterval>
<retryDuration> 900</retryDuration>
</result>';
return response;
%>
Activate Form on your website:
http://yourserver.com/roku------------------------------------------
<form> /* on your website you will have a form that creates a mapping from deviceToken to userID */
regcode = request.regcode;
if (GlobalAssociativeArray[regCode] != null && GlobalAssociativeArray[regCode] == "Activated")
{
userid = GetCurrentUserid();
deviceToken = CreateDeviceToken();
GlobalAssociativeArray[deviceToken] = userid;
GlobalAssociativeArray[regCode] = deviceToken;
persistDevicetokenToUserIDRelationInDB();
}
else
{
return BadRegCode;
}
</form>
linkAccount: (Called by a form on your website)
------------------------------------------
<%
deviceID=Request.deviceID;
regCode=Request.regCode;
if (GlobalAssociativeArray[regCode] != "Not Activated")
{
userid = GlobalAssociativeArray[deviceToken];
response='<result>
<status>success</status>
<deviceToken>'
+deviceToken+'
</deviceToken>
<userid>'
+userid+'
</userid>
</result>';
}
else
{
response='<result>
<status>failure:NotActivated</status>'
</result>';
}
return response;
%>