Roku Developer Program

Join our online forum to talk to Roku developers and fellow channel creators. Ask questions, share tips with the community, and find helpful resources.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
evilmax17
Visitor

RSS feed with Basic HTTP Authentication using roUrlTransfer?

I'm trying to access an RSS feed that requires Basic HTTP Authentication, but I can't seem to get it to work. I've also created an equivalent example in Python that works correctly, and returns my expected results.

My BrightScript code:


'BrightScript example to retrieve a protected RSS feed with Basic HTTP Authentication.
'This does NOT work for me. http.GetToString() doesn't return anything.

http = CreateObject("roUrlTransfer")
http.SetUrl("http://www.my-restricted-site.com/")

ba = CreateObject("roByteArray")
ba.FromAsciiString("username:password")
http.AddHeader("Authorization", "Basic " + ba.ToBase64String())

print "Results: "; http.GetToString()

This equivalent example in Python works as expected:


#Python example to retrieve a protected RSS feed with Basic HTTP Authentication.
#This DOES work for me.

import urllib2
import base64

myurl = 'http://www.my-restricted-site.com/'
username = 'username'
password = 'password'

req = urllib2.Request(myurl)

base64string = base64.encodestring( '%s:%s' % (username, password) )[:-1]
authheader = "Basic %s" % base64string
req.add_header("Authorization", authheader)

try:
handle = urllib2.urlopen(req)
print handle.read()
except IOError, e:
print "Wrong user/pass"


The Roku documentation for ifUrlTransfer contains the following passage, which has me a little worried:


"Boolean SetUserAndPassword(String user, String password)
- Enables HTTP authentication using the specified user name and password. Note that HTTP basic authentication is deliberately disabled due to it being inherently insecure. HTTP digest authentication is supported.

Any help would be greatly appreciated.
My Roku Channels:
Viddler - viddler.com
Tested Fan - tested.com | Jamie & Adam
This is my next - theverge.com
1080p Showcase - RIP
Whiskey Media - RIP
======================
http://www.binarymoustache.com
0 Kudos
5 REPLIES 5
TheEndless
Channel Surfer

Re: RSS feed with Basic HTTP Authentication using roUrlTrans

Not that it helps, but I use basic auth in MainSqueeze virtually identically to the SDK example you posted above, and it works great.
My Channels: http://roku.permanence.com - Twitter: @TheEndlessDev
Instant Watch Browser (NetflixIWB), Aquarium Screensaver (AQUARIUM), Clever Clocks Screensaver (CLEVERCLOCKS), iTunes Podcasts (ITPC), My Channels (MYCHANNELS)
0 Kudos
RokuKevin
Visitor

Re: RSS feed with Basic HTTP Authentication using roUrlTrans

Your code looks correct assuming your username is: "username" with a password of "password"

--Kevin
0 Kudos
evilmax17
Visitor

Re: RSS feed with Basic HTTP Authentication using roUrlTrans

Alright, if I make an HTTP HEAD request, I get back a -77 response code.

Failure message:
error setting certificate verify locations:
CAfile: /etc/pki/tls/certs/ca-bundle.crt
CApath: none

Does that tell you anything?
My Roku Channels:
Viddler - viddler.com
Tested Fan - tested.com | Jamie & Adam
This is my next - theverge.com
1080p Showcase - RIP
Whiskey Media - RIP
======================
http://www.binarymoustache.com
0 Kudos
RokuKevin
Visitor

Re: RSS feed with Basic HTTP Authentication using roUrlTrans

From the docs:

-77 CURLE_SSL_CACERT_BADFILE could not load CACERT file, missing or wrong format

So, you need to be using https and call the SetCertificatesFile(), passing a PEM file that includes the CA cert that signed your web server's certificate. It's the SSL giving you problems, not the Basic Auth.

--Kevin
0 Kudos
evilmax17
Visitor

Re: RSS feed with Basic HTTP Authentication using roUrlTrans

"RokuKevin" wrote:
From the docs:

-77 CURLE_SSL_CACERT_BADFILE could not load CACERT file, missing or wrong format

So, you need to be using https and call the SetCertificatesFile(), passing a PEM file that includes the CA cert that signed your web server's certificate. It's the SSL giving you problems, not the Basic Auth.

--Kevin

Yup, you were right! That fixed my problem.

Thanks!
My Roku Channels:
Viddler - viddler.com
Tested Fan - tested.com | Jamie & Adam
This is my next - theverge.com
1080p Showcase - RIP
Whiskey Media - RIP
======================
http://www.binarymoustache.com
0 Kudos
Need Assistance?
Welcome to the Roku Community! Feel free to search our Community for answers or post your question to get help.

Become a Roku Streaming Expert!

Share your expertise, help fellow streamers, and unlock exclusive rewards as part of the Roku Community. Learn more.