Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Basic HTTP Authentication Example? #3

Open
MCDELTAT opened this issue Sep 28, 2016 · 5 comments
Open

Basic HTTP Authentication Example? #3

MCDELTAT opened this issue Sep 28, 2016 · 5 comments

Comments

@MCDELTAT
Copy link

MCDELTAT commented Sep 28, 2016

I'm currently working on adding some cool Cablecast integrations features into our new website and I'm having trouble understanding how to send the Authentication header with my request. I'd appreciate it if I can just get a super quick example of sending that header and then carrying out an innocent action like perhaps "POST v1/digitalfiles/{id}/reindex" since any valid file will just get reindexed and be valid again.

Once that's out of the way, I'll be sure to merge my code here. We have some cool examples in the works. Thanks.

EDIT: I made a few new attempts using modified stuff from SO (let's not lie here) and reading the jQuery documentation. The code below (with username, pass, and IP obviously changed to correct values) gives me the following error:
"request header field is not allowed by access-control-allow-headers"

Ideas?

``var username = "plaintextUser";
var password = "plaintextPass";

function make_base_auth(user, password) {
var tok = user + ':' + password;
var hash = btoa(tok);
return "Basic " + hash;
}
$.ajax
({
method: "POST", //use for jquery above 1.9.0 else type: 'POST'
url: "http://xxx.xxx.xxx.xxx/cablecastapi/v1/digitalfiles/867/reindex",
dataType: 'json',
async: false,
beforeSend: function (xhr){
xhr.setRequestHeader('Authorization', make_base_auth(username, password));
},
success: function (){
alert('The file is being reindexed!');
}
});

console.log("Testing connection.");

@MCDELTAT
Copy link
Author

Cool this has been resolved. More cool stuff coming soon.

For anyone looking to get started with any of the authenticated API requests, here's some tips.

  1. Make sure to enable the desired CORS parameters as indicated in indicated in that section of the documentation. The web.config file is found in C:\TRMS\Web\CablecastAPI\web.config
    As of this writing, the lines you're looking for are around lines 100.

  2. Realize the {id} that is used in the API calls are different from the ShowID. In my case above, show 100 was id 867. I'm guessing the best way is figure this out is to call "Get v1/digitalFiles/" with a query specific enough to only return 1 value.

  3. Otherwise you can just try my code out above. All you have to do is create an html document with jquery in the header and then that code following. Of course changing 'username' and 'password' to your credentials and changing the url. I'll post more detailed example later.

@raytiley
Copy link
Member

raytiley commented Oct 5, 2016

@MCDELTAT hey... sorry, just saw this now. Glad you figured it out. Look forward to seeing your examples :)

@nwatv
Copy link

nwatv commented Apr 11, 2017

Super helpful, @MCDELTAT. What might a similar snippet look like that both authenticates and posts a new show record on a given channel?

@MCDELTAT
Copy link
Author

@nwatv I'll try and write one out for you tomorrow. Be aware though, this is obviously not an optimal or secure solution, as it would expose your Cablecast credentials to the public. I was just highlighting the code above so that if desired, people could play around with the API and make some cool stuff.

We are currently developing our website with a MERN stack so I can hide these credentials away on the server side. One of the cooler features I'm about to release is the ability for our Public Access members to remotely upload their shows, scan the file for viruses, and then transfer it to our server for playback, with a brand new show record to match it.

@nwatv
Copy link

nwatv commented Apr 17, 2017

@MCDELTAT That'd be incredible. Masking the credentials is easy enough, but the framework is hugely appreciated. The member uploads system sounds great--do you have a central space to follow your public access-related projects?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants