Roku Developer Program

Developers and content creators—a complete solution for growing an audience directly.
cancel
Showing results for 
Search instead for 
Did you mean: 
johnny_g
Level 7

Samples or Help establishing api token auth via User/Pass to a backend service

Just curious if there are samples out there or any writeups on how one could do this.  Also, to be noted I am a very green roku dev.

I am trying to establish connectivity to a backend api service and the auth piece will be 2-fold.  First establish server connection to pull available users.  So the first call will be something like GET https://hostname/api/Users/

The second piece will be either selecting a user, or manually typing in the username (users can be hidden from being returned by the aforementioned api) and then entering their password.  The call would then be a post to the server which would return user info plus a long-lasting authentication token to be used with all future api calls.

There could be multiple users and thus I'd like to store multiple auth tokens and call the api using an auth token depending on which user "logs in" - as in the login will be remembered on the device unless the user decides to log out or until the token expires.

I followed this guide but its very simple and im having trouble reverse engineering: 

https://github.com/rokudev/samples/blob/master/roku%20pay/ChannelStore_SignupFlow.zip

0 Kudos
3 Replies
joetesta
Level 10

Re: Samples or Help establishing api token auth via User/Pass to a backend service

Your post didn't mention anything about Rokupay but the app you're working from is Rokupay? 

What you want to do is totally possible.  You'll want to use a task for connecting to the API and returning the data to your render thread, then another (or reuse the same) task for submitting the user entered-password.  Store the credentials in the local registry. Not trivial but all very doable.  You (probably) don't want to use the channelstore stuff.

It seems like it used to be a lot easier to find the SceneGraph sample apps, I can't even find an appropriate one, but this page may be useful if you haven't looked at it yet

https://developer.roku.com/docs/developer-program/core-concepts/downloading-server-content.md

I can also suggest the rokudevelopers slack where you can get more help faster.

best,

Joe

aspiring
0 Kudos
johnny_g
Level 7

Re: Samples or Help establishing api token auth via User/Pass to a backend service

Thank you for your reply.  Your feedback makes sense and gives me some terminology to help search on my quest.  I have already gone through the sample from your link in some depth.  That one helps me for the latter part, for sure.  I'll go research tasks and local registry to delve in further (did i mention im new at this roku thing Smiley Tongue).

Having already looked at local registry a bit, are there best practices or ready-made functions/tasks which take care of writing to local registry, or is it more of a simple write when you need read when you need?  Trying to consider sanity when keeping local data.  I'd think there would be some functions which first check if the data already exists locally to prevent overwriting, or validating the data was written etc..  though now i feel as i just opened another can of worms, lol.

Thanks again, Joe.

Johnny

EDIT: oh, and no the service is not integrated with RokuPay.  I'm working to try and connect to an opensource app (Jellyfin) which will not have any type of payment/permissions checking - all of that happens internally on the Jellyfin server and is returned via the api calls itself.

0 Kudos
Highlighted
joetesta
Level 10

Re: Samples or Help establishing api token auth via User/Pass to a backend service

There aren't ready-made functions for interfacing with the registry that I'm aware of. Oh wow there are some new ones; I don't remember hearing about `WriteMulti` and `ReadMulti` - 

https://developer.roku.com/docs/references/brightscript/interfaces/ifregistrysection.md

those seem like good ones to use!  Create an AA with the user as the key and the password as the value.

 

 

aspiring
0 Kudos